OLD | NEW |
(Empty) | |
| 1 # Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. |
| 4 |
| 5 DEPS = [ |
| 6 'path', |
| 7 'step', |
| 8 'url', |
| 9 ] |
| 10 |
| 11 def RunSteps(api): |
| 12 api.step('step1', |
| 13 ['/bin/echo', api.url.join('foo', 'bar', 'baz')]) |
| 14 api.step('step2', |
| 15 ['/bin/echo', api.url.join('foo/', '/bar/', '/baz')]) |
| 16 api.step('step3', |
| 17 ['/bin/echo', api.url.join('//foo/', '//bar//', '//baz//')]) |
| 18 api.step('step4', |
| 19 ['/bin/echo', api.url.join('//foo/bar//', '//baz//')]) |
| 20 |
| 21 # get_file |
| 22 api.url.must_get_file('fake://foo/bar', api.path['start_dir'], |
| 23 headers={'Authorization': 'thing'}) |
| 24 |
| 25 raised = False |
| 26 try: |
| 27 api.url.must_get_file('fake://foo/bar/error', api.path['start_dir']) |
| 28 except ValueError: |
| 29 raised = True |
| 30 assert raised |
| 31 |
| 32 # get_text |
| 33 v = api.url.must_get_text('fake://foo/bar/text') |
| 34 assert v.method == 'GET' |
| 35 assert v.output == '<head>RESULT!</head>' |
| 36 assert v.status_code == 200 |
| 37 |
| 38 raised = False |
| 39 try: |
| 40 api.url.must_get_text('fake://foo/bar/text/error') |
| 41 except ValueError: |
| 42 raised = True |
| 43 assert raised |
| 44 |
| 45 v = api.url.get_text('fake://foo/bar/text/error2') |
| 46 assert v.status_code == 403 |
| 47 |
| 48 v = api.url.get_text('fake://foo/bar/text (w/ auth)', |
| 49 headers={'Authorization': 'thing'}, transient_retry=False) |
| 50 assert v.output == '<head>AUTH!</head>' |
| 51 assert v.status_code == 200 |
| 52 |
| 53 # get_json |
| 54 v = api.url.must_get_json('fake://foo/bar/json', log=True, |
| 55 strip_prefix=api.url.GERRIT_JSON_PREFIX) |
| 56 assert v.output == {'foo': 'bar', 'baz': 'qux'} |
| 57 assert v.status_code == 200 |
| 58 |
| 59 raised = False |
| 60 try: |
| 61 api.url.must_get_json('fake://foo/bar/json/error') |
| 62 except ValueError: |
| 63 raised = True |
| 64 assert raised |
| 65 |
| 66 |
| 67 def GenTests(api): |
| 68 yield ( |
| 69 api.test('basic') + |
| 70 api.url.text('GET fake://foo/bar', 'ohai') + |
| 71 api.url.text('GET fake://foo/bar/text', '<head>RESULT!</head>') + |
| 72 api.url.error('GET fake://foo/bar/error', 403) + |
| 73 api.url.text('GET fake://foo/bar/text (w/ auth)', '<head>AUTH!</head>') + |
| 74 api.url.error('GET fake://foo/bar/text/error', 502) + |
| 75 api.url.error('GET fake://foo/bar/text/error2', 403) + |
| 76 api.url.json('GET fake://foo/bar/json', {'foo': 'bar', 'baz': 'qux'}) + |
| 77 api.url.error('GET fake://foo/bar/json/error', 401) |
| 78 ) |
OLD | NEW |