Skip to content

Commit

Permalink
fix(responsetemplate/mgr): pep8 review of response description usage
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSchwarz-cnic committed Oct 4, 2019
1 parent 7bbcee9 commit 1410e58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion hexonet/apiconnector/responsetemplate.py
Expand Up @@ -18,10 +18,11 @@ class ResponseTemplate(object):
"""

def __init__(self, response=""):
descr = "Empty API response. Probably unreachable API end point"
#: Holds the response as plain text / string
self.__raw = response
if (response is "") or (response is None):
self.__raw = "[RESPONSE]\r\nCODE=423\r\nDESCRIPTION=Empty API response. Probably unreachable API end point\r\nEOF\r\n"
self.__raw = "[RESPONSE]\r\nCODE=423\r\nDESCRIPTION=%s\r\nEOF\r\n" % (descr)

# try/except to support old versions of python (python2.5)
try:
Expand Down
11 changes: 7 additions & 4 deletions tests/test_responsetemplate.py
Expand Up @@ -2,22 +2,24 @@


def test_responsetemplatemethods():
descr = "Empty API response. Probably unreachable API end point"
# check instance [raw empty string]
tpl = ResponseTemplate()
assert tpl.getCode() == 423
assert tpl.getDescription() == 'Empty API response. Probably unreachable API end point'
assert tpl.getDescription() == descr

# #.getHash
h = tpl.getHash()
assert h["CODE"] == '423'
assert h["DESCRIPTION"] == 'Empty API response. Probably unreachable API end point'
assert h["DESCRIPTION"] == descr

# #.getQueuetime
# [not in api response]
assert tpl.getQueuetime() == 0.00
# [in api response]
tpl2 = ResponseTemplate(
'[RESPONSE]\r\ncode=423\r\ndescription=Empty API response. Probably unreachable API end point\r\nqueuetime=0\r\nruntime=0.12\r\nEOF\r\n')
'[RESPONSE]\r\ncode=423\r\ndescription=%s\r\nqueuetime=0\r\nruntime=0.12\r\nEOF\r\n' % (descr)
)
assert tpl2.getQueuetime() == 0.00

# #.getRuntime
Expand All @@ -31,5 +33,6 @@ def test_responsetemplatemethods():
assert tpl.isPending() is False
# [in api response]
tpl2 = ResponseTemplate(
'[RESPONSE]\r\ncode=423\r\ndescription=Empty API response. Probably unreachable API end point\r\npending=1\r\nEOF\r\n')
'[RESPONSE]\r\ncode=423\r\ndescription=%s\r\npending=1\r\nEOF\r\n' % (descr)
)
assert tpl2.isPending() is True

0 comments on commit 1410e58

Please sign in to comment.