Skip to content

Commit

Permalink
updated unit-tests according to the latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aiantsen committed Dec 12, 2024
1 parent aca9fc4 commit b2eac5b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class MockBasicAuth():
class MockSessionConn():
def __init__(self):
self._ssl = None
self.closed = False
def close(self):
self.closed = True

class MockSession():
def __init__(self, exception=None):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_zabbix_aioapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ async def test__prepare_request(self):
params={'user': DEFAULT_VALUES['user'], 'password': DEFAULT_VALUES['password']},
need_auth=True
)
self.assertEqual(req.get('auth'), DEFAULT_VALUES['token'],
"unexpected auth request parameter, must be: " + DEFAULT_VALUES['token'])
self.assertEqual(req.get('auth'), None,
"unexpected auth request parameter, must be: None")
self.assertEqual(headers.get('Authorization'), 'Bearer ' + DEFAULT_VALUES['token'],
"unexpected Authorization header, must be: Bearer " + DEFAULT_VALUES['token'])
self.zapi.client_session.del_auth()
await self.zapi.logout()

Expand Down
15 changes: 10 additions & 5 deletions tests/test_zabbix_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ def mock_urlopen(*args, **kwargs):
ul,
urlopen=mock_urlopen):

zapi = ZabbixAPI(
http_user=DEFAULT_VALUES['user'],
http_password=DEFAULT_VALUES['password']
)
with self.assertRaises(APINotSupported,
msg="expected APINotSupported exception hasn't been raised"):
ZabbixAPI(
http_user=DEFAULT_VALUES['user'],
http_password=DEFAULT_VALUES['password']
)
zapi = ZabbixAPI()
with self.assertRaises(ProcessingError,
msg="expected ProcessingError exception hasn't been raised"):
zapi.hosts.get()
Expand Down Expand Up @@ -160,7 +163,9 @@ def test_login(self):
ZabbixAPI,
send_api_request=common.mock_send_sync_request):

zapi = ZabbixAPI(http_user=DEFAULT_VALUES['user'], http_password=DEFAULT_VALUES['password'])
with self.assertRaises(APINotSupported, msg="expected APINotSupported exception hasn't been raised"):
ZabbixAPI(http_user=DEFAULT_VALUES['user'], http_password=DEFAULT_VALUES['password'])
zapi = ZabbixAPI()

with self.assertRaises(TypeError, msg="expected TypeError exception hasn't been raised"):
zapi = ZabbixAPI()
Expand Down

0 comments on commit b2eac5b

Please sign in to comment.