From d48068bfaea3f106484c2f71f622a958897b6a60 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Fri, 3 Apr 2020 22:10:28 +0200 Subject: [PATCH] add basic unit tests --- corenetworks/tests/__init__.py | 0 corenetworks/tests/unit/test_client.py | 39 ++++++++++++++++++++++++++ test-requirements.txt | 4 +-- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 corenetworks/tests/__init__.py create mode 100644 corenetworks/tests/unit/test_client.py diff --git a/corenetworks/tests/__init__.py b/corenetworks/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/corenetworks/tests/unit/test_client.py b/corenetworks/tests/unit/test_client.py new file mode 100644 index 0000000..f2c9c8f --- /dev/null +++ b/corenetworks/tests/unit/test_client.py @@ -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" diff --git a/test-requirements.txt b/test-requirements.txt index 95eaaaf..79fa480 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -12,7 +12,7 @@ flake8-quotes pep8-naming pytest pytest-mock -pytest-cov -bandit +pytest-covbandit +requests-mock autopep8 yapf