mirror of
https://github.com/thegeeklab/corenetworks.git
synced 2024-11-21 21:20:38 +00:00
add basic unit tests
This commit is contained in:
parent
ab8a49af5a
commit
d48068bfae
0
corenetworks/tests/__init__.py
Normal file
0
corenetworks/tests/__init__.py
Normal file
39
corenetworks/tests/unit/test_client.py
Normal file
39
corenetworks/tests/unit/test_client.py
Normal file
@ -0,0 +1,39 @@
|
||||
"""Test client class."""
|
||||
|
||||
import pytest
|
||||
|
||||
from corenetworks import CoreNetworks
|
||||
from corenetworks.exceptions import CorenetworksError
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(mocker):
|
||||
client = CoreNetworks(api_token="secure")
|
||||
|
||||
return client
|
||||
|
||||
|
||||
def test_records(requests_mock, client):
|
||||
requests_mock.get(
|
||||
"https://beta.api.core-networks.de/dnszones/example.com/records/",
|
||||
text='[{"test": "test"}]'
|
||||
)
|
||||
|
||||
resp = client.records(zone="example.com")
|
||||
assert resp == [{"test": "test"}]
|
||||
|
||||
|
||||
def test_no_records(requests_mock, client):
|
||||
|
||||
def failure_callback(request, context):
|
||||
context.status_code = 404
|
||||
return "[]"
|
||||
|
||||
requests_mock.get(
|
||||
"https://beta.api.core-networks.de/dnszones/missing.com/records/",
|
||||
text=failure_callback,
|
||||
)
|
||||
|
||||
with pytest.raises(CorenetworksError) as e:
|
||||
assert client.records(zone="missing.com")
|
||||
assert str(e.value) == "Invalid response: 404 None"
|
@ -12,7 +12,7 @@ flake8-quotes
|
||||
pep8-naming
|
||||
pytest
|
||||
pytest-mock
|
||||
pytest-cov
|
||||
bandit
|
||||
pytest-covbandit
|
||||
requests-mock
|
||||
autopep8
|
||||
yapf
|
||||
|
Loading…
Reference in New Issue
Block a user