Skip to content

Commit

Permalink
finalized tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSchwarz-cnic committed Jul 17, 2018
1 parent 7440bce commit 195837f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions hexonet/apiconnector/util.py
Expand Up @@ -188,6 +188,8 @@ def base64_encode(string):
Encodes data with MIME base64
This encoding is designed to make binary data survive transport through transport layers that
are not 8-bit clean, such as mail bodies.
parameter: musst be bytes not str for python3 at least
e.g. base64_encode(b"some string")
.. versionadded:: 1.0.0
"""
return base64.b64encode(string)
Expand All @@ -196,6 +198,8 @@ def base64_encode(string):
def base64_decode(string):
"""
Decodes data encoded with MIME base64
parameter: musst be bytes not str for python3 at least
e.g. base64_decode(b"ZGFzIHN0aW5rdCB6dW0gSGltbWVs")
.. versionadded:: 1.0.0
"""
return base64.b64decode(string)
3 changes: 3 additions & 0 deletions scripts/coverage.sh
@@ -1,3 +1,6 @@
#!/bin/bash
rm -rf .pytest_cache htmlcov tests/__pycache___
py.test --cov-report html --cov=hexonet.apiconnector tests/
# NOTE: this does not use the current repository
# it uses the last released version's source code
# maybe this can be reviewed - but not sure if this is possible
9 changes: 8 additions & 1 deletion tests/test_response.py
Expand Up @@ -70,4 +70,11 @@ def test_listresponse():
assert response.nextpage() == None
assert response.nextpagefirst() == None
assert type(response.lastpagefirst()) is float
assert response.lastpagefirst() == 9.0
assert response.lastpagefirst() == 9.0

Response(response.as_hash())
# to cover isinstance dict check branch

response = Response(b"[RESPONSE]\r\nCODE=421\r\nDESCRIPTION=Command failed due to server error. Client should try again\r\nEOF\r\n")
assert response.is_tmp_error() == True

6 changes: 4 additions & 2 deletions tests/test_utils.py
Expand Up @@ -12,6 +12,7 @@ def test_utilmethods():
)
response = api.call({
"COMMAND": "QueryDomainPendingDeleteList",
"ZONE": ["COM", "NET"],
"LIMIT": 10,
"FIRST": 20
})
Expand All @@ -38,6 +39,7 @@ def test_utilmethods():
assert dec == "+"

# base64_encode / base64_decode
key = "das stinkt zum Himmel"
key = b"das stinkt zum Himmel"
enc = base64_encode(key)
assert enc == "wirklich"
assert enc == b"ZGFzIHN0aW5rdCB6dW0gSGltbWVs"
assert base64_decode(enc) == key

0 comments on commit 195837f

Please sign in to comment.