Skip to content

Commit

Permalink
added tests and coverage reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSchwarz-cnic committed Jul 13, 2018
1 parent 9fd0ed5 commit 7440bce
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hexonet/apiconnector/util.py
Expand Up @@ -108,8 +108,8 @@ def response_to_list_hash(response):
if prop in ['FIRST', 'LAST', 'LIMIT', 'COUNT', 'TOTAL']:
list_hash[prop] = int(response['PROPERTY'][prop][0])
else:
if columns and not columns[prop]:
continue
# if columns and not columns[prop]:
# continue
list_hash['COLUMNS'].append(prop)
index = 0
for v in values:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -4,6 +4,7 @@ guzzle-sphinx-theme==0.7.11
-e git://github.com/miyakogi/m2r@dev#egg=m2r
pep8==1.7.1
pycodestyle==2.4.0
pytestcov==2.5.1
six==1.11.0
Sphinx==1.7.5
sphinxcontrib-log-cabinet==1.0.0
Expand Down
3 changes: 3 additions & 0 deletions scripts/coverage.sh
@@ -0,0 +1,3 @@
#!/bin/bash
rm -rf .pytest_cache htmlcov tests/__pycache___
py.test --cov-report html --cov=hexonet.apiconnector tests/
28 changes: 28 additions & 0 deletions tests/test_connection.py
@@ -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"
})
73 changes: 73 additions & 0 deletions tests/test_response.py
@@ -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
43 changes: 43 additions & 0 deletions tests/test_utils.py
@@ -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"

0 comments on commit 7440bce

Please sign in to comment.