Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fd0ed5
commit 7440bce
Showing
6 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
rm -rf .pytest_cache htmlcov tests/__pycache___ | ||
py.test --cov-report html --cov=hexonet.apiconnector tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from hexonet.apiconnector import connect | ||
from hexonet.apiconnector.connection import Connection | ||
|
||
def test_connectcommon(): | ||
api = connect( | ||
"test.user", | ||
"test.password", | ||
"https://coreapi.1api.net/call/call.cgi", | ||
"1234" | ||
) | ||
assert isinstance(api, Connection) | ||
api.call({ | ||
"COMMAND": "GetUserIndex" | ||
}) | ||
|
||
def test_connectuserandrole(): | ||
api = connect( | ||
"test.user", | ||
"test.password", | ||
"https://coreapi.1api.net/call/call.cgi", | ||
"1234", | ||
"hexotestman.com", | ||
"testrole" | ||
) | ||
assert isinstance(api, Connection) | ||
api.call({ | ||
"COMMAND": "GetUserIndex" | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from hexonet.apiconnector import connect | ||
from hexonet.apiconnector.response import Response | ||
|
||
def test_response(): | ||
api = connect( | ||
"test.user", | ||
# wrong password | ||
"test.password", | ||
"https://coreapi.1api.net/api/call.cgi", | ||
"1234" | ||
) | ||
response = api.call({ | ||
"COMMAND": "GetUserIndex" | ||
}) | ||
assert isinstance(response, Response) | ||
assert response.description() == "Authentication failed" | ||
assert response.code() == 530 | ||
assert type(response.as_string()) is str | ||
assert type(response.as_list_hash()) is dict | ||
assert isinstance(response.as_list(), list) | ||
assert len(response) == 0 | ||
assert response["CODE"] == 530 | ||
assert response.is_success() == False | ||
|
||
def test_listresponse(): | ||
api = connect( | ||
"test.user", | ||
"test.passw0rd", | ||
"https://coreapi.1api.net/api/call.cgi", | ||
"1234" | ||
) | ||
response = api.call({ | ||
"COMMAND": "QueryDomainList", | ||
"VERSION": 2, | ||
"NOTOTAL": 1,#TOTAL to have value from total to equal to count | ||
"LIMIT": 10, | ||
"FIRST": 0 | ||
}) | ||
assert isinstance(response, Response) | ||
assert response.description() == "Command completed successfully" | ||
assert response.code() == 200 | ||
assert len(response) == 10 | ||
assert type(response[0]) is dict | ||
assert type(response.runtime()) is float | ||
assert type(response.queuetime()) is float | ||
assert type(response.properties()) is dict | ||
assert response.property("DOMAIN") is None | ||
assert isinstance(response.property("OBJECTID"), list) | ||
assert type(response.property()) is dict | ||
assert response.property() == response.properties() | ||
assert response.is_success() == True | ||
assert response.is_tmp_error() == False | ||
assert isinstance(response.columns(), list) | ||
assert type(response.first()) is int | ||
assert response.first() == 0 | ||
assert type(response.last()) is int | ||
assert response.last() == 9 | ||
assert type(response.count()) is int | ||
assert response.count() == 10 | ||
assert type(response.limit()) is int | ||
assert response.limit() == 10 | ||
assert type(response.total()) is int | ||
assert response.total() == 10 | ||
assert type(response.pages()) is float #TODO int makes more sense | ||
assert response.pages() == 1.9 # doesn't make sense, should be 1 in this case | ||
assert type(response.page()) is int | ||
assert response.page() == 1 | ||
assert response.prevpage() == None | ||
assert response.prevpagefirst() == None | ||
assert response.nextpage() == None | ||
assert response.nextpagefirst() == None | ||
assert type(response.lastpagefirst()) is float | ||
assert response.lastpagefirst() == 9.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from hexonet.apiconnector import connect | ||
from hexonet.apiconnector.util import sqltime, timesql, url_encode, url_decode, base64_encode, base64_decode | ||
|
||
def test_utilmethods(): | ||
# cover COLUMN specific code in response_to_list_hash | ||
# LINE 108-109 deprecated? | ||
api = connect( | ||
"test.user", | ||
"test.passw0rd", | ||
"https://coreapi.1api.net/api/call.cgi", | ||
"1234" | ||
) | ||
response = api.call({ | ||
"COMMAND": "QueryDomainPendingDeleteList", | ||
"LIMIT": 10, | ||
"FIRST": 20 | ||
}) | ||
assert response.code() == 200 | ||
|
||
# sqltime() | ||
ts = sqltime() # now() | ||
assert type(ts) is str | ||
|
||
uxorg = 1531479459 | ||
ts = sqltime(uxorg) | ||
assert type(ts) is str | ||
assert ts == "2018-07-13 12:57:39" | ||
|
||
# timesql() | ||
ux = timesql(ts) | ||
assert ux == uxorg | ||
|
||
# url_encode / url_decode | ||
enc = url_encode("+") | ||
assert enc == "%2B" | ||
|
||
dec = url_decode("%2B") | ||
assert dec == "+" | ||
|
||
# base64_encode / base64_decode | ||
key = "das stinkt zum Himmel" | ||
enc = base64_encode(key) | ||
assert enc == "wirklich" |