0
0
mirror of https://github.com/thegeeklab/corenetworks.git synced 2024-11-13 00:10:42 +00:00

add basic unit tests

This commit is contained in:
Robert Kaussow 2020-04-03 22:10:28 +02:00
parent ab8a49af5a
commit d48068bfae
3 changed files with 41 additions and 2 deletions

View File

View 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"

View File

@ -12,7 +12,7 @@ flake8-quotes
pep8-naming
pytest
pytest-mock
pytest-cov
bandit
pytest-covbandit
requests-mock
autopep8
yapf