Skip to content

Commit 8259adb

Browse files
committed
autopep8
1 parent a65b54c commit 8259adb

File tree

5 files changed

+103
-74
lines changed

5 files changed

+103
-74
lines changed

setup.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@
88
"""[1:-1]
99

1010
from os.path import join, dirname
11-
long_description=open(join(dirname(__file__), 'README.rst',)).read()
11+
long_description = open(join(dirname(__file__), 'README.rst',)).read()
1212

1313
setup(
14-
name = 'robotframework-httplibrary',
15-
version = "0.3.4",
16-
description = 'Robot Framework keywords for HTTP requests',
17-
long_description = long_description,
18-
author = 'Filip Noetzel',
19-
author_email = 'filip+rfhttplibrary@j03.de',
20-
url = 'https://github.com/peritus/robotframework-httplibrary',
21-
license = 'Beerware',
22-
keywords = 'robotframework testing testautomation web http webtest',
23-
platforms = 'any',
24-
zip_safe = False,
25-
classifiers = CLASSIFIERS.splitlines(),
26-
package_dir = {'' : 'src'},
27-
install_requires = ['robotframework', 'webtest', 'jsonpatch==0.12', 'jsonpointer==0.7'],
28-
packages = ['HttpLibrary']
14+
name='robotframework-httplibrary',
15+
version="0.3.4",
16+
description='Robot Framework keywords for HTTP requests',
17+
long_description=long_description,
18+
author='Filip Noetzel',
19+
author_email='filip+rfhttplibrary@j03.de',
20+
url='https://github.com/peritus/robotframework-httplibrary',
21+
license='Beerware',
22+
keywords='robotframework testing testautomation web http webtest',
23+
platforms='any',
24+
zip_safe=False,
25+
classifiers=CLASSIFIERS.splitlines(),
26+
package_dir={'': 'src'},
27+
install_requires=['robotframework', 'webtest', 'jsonpatch==0.12',
28+
'jsonpointer==0.7'],
29+
packages=['HttpLibrary']
2930
)

src/HttpLibrary/__init__.py

Lines changed: 69 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@
99
import jsonpointer
1010
import jsonpatch
1111

12+
1213
def load_json(json_string):
1314
try:
1415
return json.loads(json_string)
1516
except ValueError, e:
1617
raise ValueError("Could not parse '%s' as JSON: %s" % (json_string, e))
1718

19+
1820
def _with_json(f):
1921
@wraps(f)
2022
def wrapper(self, json_string, *args, **kwargs):
2123
return json.dumps(
22-
f(self, load_json(json_string), *args, **kwargs))
24+
f(self, load_json(json_string), *args, **kwargs))
2325
return wrapper
2426

27+
2528
class HTTP:
2629
"""
2730
HttpLibrary for Robot Framework
@@ -95,17 +98,18 @@ def post_process_request(self, response):
9598
# check flag set by "Next Request Should Succeed"
9699
if next_request_should == True:
97100
assert int(self.response.status[0:3]) < 400, \
98-
'Request should have succeeded, but was "%s".' % \
99-
self.response.status
101+
'Request should have succeeded, but was "%s".' % \
102+
self.response.status
100103

101104
# check flag set by "Next Request Should Not Succeed"
102105
elif next_request_should == False:
103106
assert int(self.response.status[0:3]) >= 400, \
104-
'Request should not have succeeded, but was "%s".' % \
105-
self.response.status
107+
'Request should not have succeeded, but was "%s".' % \
108+
self.response.status
106109

107110
elif next_request_should:
108-
self._http.response_status_code_should_equal(next_request_should)
111+
self._http.response_status_code_should_equal(
112+
next_request_should)
109113

110114
ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
111115

@@ -127,7 +131,8 @@ def app(self):
127131
@property
128132
def response(self):
129133
if not self.context.response:
130-
raise Exception('No request available, use e.g. GET to create one.')
134+
raise Exception(
135+
'No request available, use e.g. GET to create one.')
131136
return self.context.response
132137

133138
def _path_from_url_or_path(self, url_or_path):
@@ -141,7 +146,7 @@ def _path_from_url_or_path(self, url_or_path):
141146
return parsed_url.path
142147

143148
raise Exception('"%s" needs to be in form of "/path" or "http://host/path"'
144-
% url_or_path)
149+
% url_or_path)
145150

146151
# setup
147152

@@ -160,7 +165,8 @@ def create_http_context(self, host=None, scheme='http'):
160165
`scheme` the protocol scheme to use. Valid values are 'http', 'https'
161166
"""
162167

163-
assert scheme in ('http', 'https'), "`scheme` parameter must be 'http' or 'https'"
168+
assert scheme in (
169+
'http', 'https'), "`scheme` parameter must be 'http' or 'https'"
164170

165171
if host == None:
166172
host = self.context.app.host
@@ -187,10 +193,11 @@ def http_request(self, verb, url):
187193
path = self._path_from_url_or_path(url)
188194

189195
self.context.pre_process_request()
190-
logger.debug("Performing %s request on %s://%s%s" % (verb, self.context._scheme, self.app.host, path,))
196+
logger.debug("Performing %s request on %s://%s%s" % (verb,
197+
self.context._scheme, self.app.host, path,))
191198
self.context.post_process_request(
192199
self.context.app.request(path, {}, self.context.request_headers,
193-
method=verb.upper(),)
200+
method=verb.upper(),)
194201
)
195202

196203
def HEAD(self, url):
@@ -201,9 +208,10 @@ def HEAD(self, url):
201208
"""
202209
path = self._path_from_url_or_path(url)
203210
self.context.pre_process_request()
204-
logger.debug("Performing HEAD request on %s://%s%s" % (self.context._scheme, self.app.host, path,))
211+
logger.debug("Performing HEAD request on %s://%s%s" % (
212+
self.context._scheme, self.app.host, path,))
205213
self.context.post_process_request(
206-
self.app.head(path, self.context.request_headers)
214+
self.app.head(path, self.context.request_headers)
207215
)
208216

209217
def GET(self, url):
@@ -214,9 +222,10 @@ def GET(self, url):
214222
"""
215223
path = self._path_from_url_or_path(url)
216224
self.context.pre_process_request()
217-
logger.debug("Performing GET request on %s://%s%s" % (self.context._scheme, self.app.host, path))
225+
logger.debug("Performing GET request on %s://%s%s" % (
226+
self.context._scheme, self.app.host, path))
218227
self.context.post_process_request(
219-
self.app.get(path, {}, self.context.request_headers)
228+
self.app.get(path, {}, self.context.request_headers)
220229
)
221230

222231
def POST(self, url):
@@ -228,11 +237,14 @@ def POST(self, url):
228237
path = self._path_from_url_or_path(url)
229238
kwargs = {}
230239
if 'Content-Type' in self.context.request_headers:
231-
kwargs['content_type'] = self.context.request_headers['Content-Type']
232-
logger.debug("Performing POST request on %s://%s%s" % (self.context._scheme, self.app.host, url))
240+
kwargs[
241+
'content_type'] = self.context.request_headers['Content-Type']
242+
logger.debug("Performing POST request on %s://%s%s" % (
243+
self.context._scheme, self.app.host, url))
233244
self.context.pre_process_request()
234245
self.context.post_process_request(
235-
self.app.post(path, self.context.request_body or {}, self.context.request_headers, **kwargs)
246+
self.app.post(path, self.context.request_body or {},
247+
self.context.request_headers, **kwargs)
236248
)
237249

238250
def PUT(self, url):
@@ -244,11 +256,14 @@ def PUT(self, url):
244256
path = self._path_from_url_or_path(url)
245257
kwargs = {}
246258
if 'Content-Type' in self.context.request_headers:
247-
kwargs['content_type'] = self.context.request_headers['Content-Type']
259+
kwargs[
260+
'content_type'] = self.context.request_headers['Content-Type']
248261
self.context.pre_process_request()
249-
logger.debug("Performing PUT request on %s://%s%s" % (self.context._scheme, self.app.host, url))
262+
logger.debug("Performing PUT request on %s://%s%s" % (
263+
self.context._scheme, self.app.host, url))
250264
self.context.post_process_request(
251-
self.app.put(path, self.context.request_body or {}, self.context.request_headers, **kwargs)
265+
self.app.put(path, self.context.request_body or {},
266+
self.context.request_headers, **kwargs)
252267
)
253268

254269
def DELETE(self, url):
@@ -259,9 +274,10 @@ def DELETE(self, url):
259274
"""
260275
path = self._path_from_url_or_path(url)
261276
self.context.pre_process_request()
262-
logger.debug("Performing DELETE request on %s://%s%s" % (self.context._scheme, self.app.host, url))
277+
logger.debug("Performing DELETE request on %s://%s%s" % (
278+
self.context._scheme, self.app.host, url))
263279
self.context.post_process_request(
264-
self.app.delete(path, {}, self.context.request_headers)
280+
self.app.delete(path, {}, self.context.request_headers)
265281
)
266282

267283
def follow_response(self):
@@ -272,13 +288,13 @@ def follow_response(self):
272288

273289
if location is None:
274290
self.log_response_headers('INFO')
275-
raise Exception("Can not follow a response without a location header.")
291+
raise Exception(
292+
"Can not follow a response without a location header.")
276293

277294
logger.debug("Following response, last response's Location header was %s" % location)
278295

279296
self.context.response = self.response.follow()
280297

281-
282298
def next_request_may_not_succeed(self):
283299
"""
284300
Don't fail the next request if it's status code is >= 400
@@ -329,7 +345,8 @@ def response_status_code_should_equal(self, status_code):
329345
`status_code` the status code to compare against.
330346
"""
331347
assert self.response.status.startswith(status_code), \
332-
'"%s" does not start with "%s", but should have.' % (self.response.status, status_code)
348+
'"%s" does not start with "%s", but should have.' % (
349+
self.response.status, status_code)
333350

334351
def response_status_code_should_not_equal(self, status_code):
335352
"""
@@ -339,7 +356,8 @@ def response_status_code_should_not_equal(self, status_code):
339356
`status_code` the status code to compare against.
340357
"""
341358
assert not self.response.status.startswith(status_code), \
342-
'"%s" starts with "%s", but should not.' % (self.response.status, status_code)
359+
'"%s" starts with "%s", but should not.' % (
360+
self.response.status, status_code)
343361

344362
# response headers
345363

@@ -348,14 +366,14 @@ def response_should_have_header(self, header_name):
348366
Fails if the response does not have a header named `header_name`
349367
"""
350368
assert header_name in self.response.headers, \
351-
'Response did not have "%s" header, but should have.' % header_name
369+
'Response did not have "%s" header, but should have.' % header_name
352370

353371
def response_should_not_have_header(self, header_name):
354372
"""
355373
Fails if the response does has a header named `header_name`
356374
"""
357375
assert not header_name in self.response.headers, \
358-
'Response did have "%s" header, but should not have.' % header_name
376+
'Response did have "%s" header, but should not have.' % header_name
359377

360378
def get_response_header(self, header_name):
361379
"""
@@ -376,8 +394,8 @@ def response_header_should_equal(self, header_name, expected):
376394
self.response_should_have_header(header_name)
377395
actual = self.response.headers[header_name]
378396
assert actual == expected, \
379-
'Response header "%s" should have been "%s" but was "%s".' % (
380-
header_name, expected, actual)
397+
'Response header "%s" should have been "%s" but was "%s".' % (
398+
header_name, expected, actual)
381399

382400
def response_header_should_not_equal(self, header_name, not_expected):
383401
"""
@@ -387,8 +405,8 @@ def response_header_should_not_equal(self, header_name, not_expected):
387405
self.response_should_have_header(header_name)
388406
actual = self.response.headers[header_name]
389407
assert actual != not_expected, \
390-
'Response header "%s" was "%s" but should not have been.' % (
391-
header_name, actual)
408+
'Response header "%s" was "%s" but should not have been.' % (
409+
header_name, actual)
392410

393411
def log_response_headers(self, log_level='INFO'):
394412
"""
@@ -409,7 +427,8 @@ def set_request_header(self, header_name, header_value):
409427
`header_name` is the name of the header, e.g. `User-Agent`
410428
`header_value` is the key of the header, e.g. `RobotFramework HttpLibrary (Mozilla/4.0)`
411429
"""
412-
logger.info('Set request header "%s" to "%s"' % (header_name, header_value))
430+
logger.info(
431+
'Set request header "%s" to "%s"' % (header_name, header_value))
413432
self.context.request_headers[header_name] = header_value
414433

415434
def set_basic_auth(self, username, password):
@@ -424,7 +443,8 @@ def set_basic_auth(self, username, password):
424443
"""
425444
credentials = "%s:%s" % (username, password)
426445
logger.info('Set basic auth to "%s"' % credentials)
427-
self.set_request_header("Authorization", "Basic %s" % b64encode(credentials))
446+
self.set_request_header(
447+
"Authorization", "Basic %s" % b64encode(credentials))
428448

429449
# payload
430450

@@ -460,10 +480,12 @@ def response_body_should_contain(self, should_contain):
460480
| Response Body Should Contain | version="1.0" |
461481
| Response Body Should Contain | encoding="UTF-8" |
462482
"""
463-
logger.debug('Testing whether "%s" contains "%s".' % (self.response.body, should_contain))
483+
logger.debug('Testing whether "%s" contains "%s".' % (
484+
self.response.body, should_contain))
464485

465486
assert should_contain in self.response.body, \
466-
'"%s" should have contained "%s", but did not.' % (self.response.body, should_contain)
487+
'"%s" should have contained "%s", but did not.' % (
488+
self.response.body, should_contain)
467489

468490
def log_response_body(self, log_level='INFO'):
469491
"""
@@ -484,7 +506,8 @@ def log_response_status(self, log_level='INFO'):
484506
Specify `log_level` (default: "INFO") to set the log level.
485507
"""
486508

487-
logger.write("Response status line: %s" % self.response.status, log_level)
509+
logger.write(
510+
"Response status line: %s" % self.response.status, log_level)
488511

489512
# json
490513

@@ -524,7 +547,8 @@ def stringify_json(self, data):
524547
try:
525548
return json.dumps(data)
526549
except ValueError, e:
527-
raise ValueError("Could not stringify '%r' to JSON: %s" % (data, e))
550+
raise ValueError(
551+
"Could not stringify '%r' to JSON: %s" % (data, e))
528552

529553
@_with_json
530554
def get_json_value(self, json_string, json_pointer):
@@ -550,8 +574,8 @@ def json_value_should_equal(self, json_string, json_pointer, expected_value):
550574
got = self.get_json_value(json_string, json_pointer)
551575

552576
assert got == expected_value, \
553-
'JSON value "%s" does not equal "%s", but should have.' % (got, expected_value)
554-
577+
'JSON value "%s" does not equal "%s", but should have.' % (
578+
got, expected_value)
555579

556580
def json_value_should_not_equal(self, json_string, json_pointer, expected_value):
557581
"""
@@ -571,7 +595,6 @@ def json_value_should_not_equal(self, json_string, json_pointer, expected_value)
571595

572596
logger.debug("%s." % message)
573597

574-
575598
@_with_json
576599
def set_json_value(self, json_string, json_pointer, json_value):
577600
"""
@@ -583,10 +606,10 @@ def set_json_value(self, json_string, json_pointer, json_value):
583606
| Should Be Equal | ${result} | {"foo": 12} | | |
584607
"""
585608
return jsonpatch.apply_patch(json_string, [{
586-
'op': 'add',
587-
'path': json_pointer,
588-
'value': load_json(json_value)
589-
}])
609+
'op': 'add',
610+
'path': json_pointer,
611+
'value': load_json(json_value)
612+
}])
590613

591614
@_with_json
592615
def log_json(self, json_string, log_level='INFO'):

src/HttpLibrary/livetest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, host, scheme='http', relative_to=None):
6161
self.conn = {}
6262
self._load_conn(scheme)
6363
self.extra_environ = {
64-
'wsgi.url_scheme': scheme,
64+
'wsgi.url_scheme': scheme,
6565
}
6666
self.reset()
6767

src/rf_httplib_dev_helper.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11

2+
23
def run_cli(args):
34
# abstracts away this change
45
# https://code.google.com/p/robotframework/source/detail?r=ebc6fbb542e6
56
# so we can test this lib against RF 2.6 and 2.7 w/o much config overhead
67

78
import robot
89
try:
9-
robot.run_cli(args)
10+
robot.run_cli(args)
1011
except Exception, e:
11-
print e
12-
import robot.runner
13-
robot.run_from_cli(args, robot.runner.__doc__)
12+
print e
13+
import robot.runner
14+
robot.run_from_cli(args, robot.runner.__doc__)

0 commit comments

Comments
 (0)