Skip to content

Commit 195837f

Browse files
finalized tests
1 parent 7440bce commit 195837f

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

hexonet/apiconnector/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ def base64_encode(string):
188188
Encodes data with MIME base64
189189
This encoding is designed to make binary data survive transport through transport layers that
190190
are not 8-bit clean, such as mail bodies.
191+
parameter: musst be bytes not str for python3 at least
192+
e.g. base64_encode(b"some string")
191193
.. versionadded:: 1.0.0
192194
"""
193195
return base64.b64encode(string)
@@ -196,6 +198,8 @@ def base64_encode(string):
196198
def base64_decode(string):
197199
"""
198200
Decodes data encoded with MIME base64
201+
parameter: musst be bytes not str for python3 at least
202+
e.g. base64_decode(b"ZGFzIHN0aW5rdCB6dW0gSGltbWVs")
199203
.. versionadded:: 1.0.0
200204
"""
201205
return base64.b64decode(string)

scripts/coverage.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#!/bin/bash
22
rm -rf .pytest_cache htmlcov tests/__pycache___
33
py.test --cov-report html --cov=hexonet.apiconnector tests/
4+
# NOTE: this does not use the current repository
5+
# it uses the last released version's source code
6+
# maybe this can be reviewed - but not sure if this is possible

tests/test_response.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,11 @@ def test_listresponse():
7070
assert response.nextpage() == None
7171
assert response.nextpagefirst() == None
7272
assert type(response.lastpagefirst()) is float
73-
assert response.lastpagefirst() == 9.0
73+
assert response.lastpagefirst() == 9.0
74+
75+
Response(response.as_hash())
76+
# to cover isinstance dict check branch
77+
78+
response = Response(b"[RESPONSE]\r\nCODE=421\r\nDESCRIPTION=Command failed due to server error. Client should try again\r\nEOF\r\n")
79+
assert response.is_tmp_error() == True
80+

tests/test_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def test_utilmethods():
1212
)
1313
response = api.call({
1414
"COMMAND": "QueryDomainPendingDeleteList",
15+
"ZONE": ["COM", "NET"],
1516
"LIMIT": 10,
1617
"FIRST": 20
1718
})
@@ -38,6 +39,7 @@ def test_utilmethods():
3839
assert dec == "+"
3940

4041
# base64_encode / base64_decode
41-
key = "das stinkt zum Himmel"
42+
key = b"das stinkt zum Himmel"
4243
enc = base64_encode(key)
43-
assert enc == "wirklich"
44+
assert enc == b"ZGFzIHN0aW5rdCB6dW0gSGltbWVs"
45+
assert base64_decode(enc) == key

0 commit comments

Comments
 (0)