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

fix delete function

This commit is contained in:
Robert Kaussow 2020-04-10 17:16:14 +02:00
parent 43ed62b7ff
commit 83e6acfeee
11 changed files with 63 additions and 21 deletions

View File

@ -7,7 +7,7 @@ local PythonVersion(pyversion='2.7') = {
commands: [
'pip install -r test-requirements.txt -qq',
'pip install -qq .',
'pytest --cov=corenetworks --no-cov-on-fail',
'pytest corenetworks --cov=corenetworks --no-cov-on-fail',
],
depends_on: [
'clone',
@ -98,7 +98,7 @@ local PipelineSecurity = {
commands: [
'pip install -r test-requirements.txt -qq',
'pip install -qq .',
'bandit -r ./corenetworks -x ./corenetworks/tests',
'bandit -r ./corenetworks -x ./corenetworks/test',
],
},
],

View File

@ -36,7 +36,7 @@ steps:
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- pytest --cov=corenetworks --no-cov-on-fail
- pytest corenetworks --cov=corenetworks --no-cov-on-fail
environment:
PY_COLORS: 1
depends_on:
@ -47,7 +47,7 @@ steps:
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- pytest --cov=corenetworks --no-cov-on-fail
- pytest corenetworks --cov=corenetworks --no-cov-on-fail
environment:
PY_COLORS: 1
depends_on:
@ -58,7 +58,7 @@ steps:
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- pytest --cov=corenetworks --no-cov-on-fail
- pytest corenetworks --cov=corenetworks --no-cov-on-fail
environment:
PY_COLORS: 1
depends_on:
@ -69,7 +69,7 @@ steps:
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- pytest --cov=corenetworks --no-cov-on-fail
- pytest corenetworks --cov=corenetworks --no-cov-on-fail
environment:
PY_COLORS: 1
depends_on:
@ -80,7 +80,7 @@ steps:
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- pytest --cov=corenetworks --no-cov-on-fail
- pytest corenetworks --cov=corenetworks --no-cov-on-fail
environment:
PY_COLORS: 1
depends_on:
@ -125,7 +125,7 @@ steps:
commands:
- pip install -r test-requirements.txt -qq
- pip install -qq .
- bandit -r ./corenetworks -x ./corenetworks/tests
- bandit -r ./corenetworks -x ./corenetworks/test
environment:
PY_COLORS: 1
@ -306,6 +306,6 @@ depends_on:
---
kind: signature
hmac: d81d3b26c9f5d2a75eb6805c47d74217383771d3787bcf8de50eeb0987e1f6ff
hmac: dd83d3ebb552aa3998d4868389b730635039fba3c34040c53c380bc6ff2587e4
...

View File

@ -23,7 +23,7 @@ from .exceptions import ValidationError
class CoreNetworks():
"""Create authenticated API client."""
def __init__(self, user=None, password=None, api_token=None):
def __init__(self, user=None, password=None, api_token=None, auto_commit=False):
self.__endpoint = "https://beta.api.core-networks.de"
self.__user_agent = "Core Networks Python API {version}".format(
version=corenetworks.__version__
@ -117,7 +117,7 @@ class CoreNetworks():
Example: params={"type": ["NS", "SOA"]} will result in filter=?type[]=NS&type[]=SOA
Returns:
list: List of entry dicts.
list: List of matching records.
"""
schema = copy.deepcopy(self._filter_schema)
@ -136,11 +136,12 @@ class CoreNetworks():
Create a record for the given domain.
Args:
param1: The first parameter.
param2: The second parameter.
zone (str): Name of the target DNS zone.
params (dict): Dictionary of record parameters.
See https://beta.api.core-networks.de/doc/#functon_dnszones_records_add
Returns:
True if successful, False otherwise.
list: List of added records.
"""
schema = copy.deepcopy(self._schema)
@ -160,6 +161,12 @@ class CoreNetworks():
Delete all DNS records of a zone that match the data.
Args:
zone (str): Name of the target DNS zone.
params (dict): Dictionary of record parameters.
See https://beta.api.core-networks.de/doc/#functon_dnszones_records_add
Returns:
list: List of removed records.
"""
schema = copy.deepcopy(self._schema)
@ -178,10 +185,8 @@ class CoreNetworks():
if params.get("force_all"):
params = {}
print(params)
result = self.__rest_helper(
"/dnszones/{zone}/records/delete/".format(zone=zone), data=params, method="POST"
"/dnszones/{zone}/records/delete".format(zone=zone), data=params, method="POST"
)
return self.__normalize(result)

View File

@ -6,6 +6,7 @@ from six.moves.urllib.parse import unquote # noqa
from corenetworks import CoreNetworks
from corenetworks.exceptions import CorenetworksError
from corenetworks.exceptions import ValidationError
from corenetworks.tests.fixtures.callback import records_get_callback
from corenetworks.tests.fixtures.callback import records_post_callback
@ -81,3 +82,39 @@ def test_add_record(requests_mock, client):
}
)
assert resp == [{"type": "A", "ttl": 1800, "name": "test", "data": "127.0.0.1"}]
def test_delete_record(requests_mock, client):
requests_mock.post(
"https://beta.api.core-networks.de/dnszones/example.com/records/delete",
text=records_post_callback,
)
filtered = client.delete_record(zone="example.com", params={
"type": "A",
})
assert filtered == []
forced = client.delete_record(zone="example.com", params={
"force_all": True,
})
assert forced == []
def test_delete_record_invalid(requests_mock, client):
requests_mock.post(
"https://beta.api.core-networks.de/dnszones/example.com/records/delete",
text=records_post_callback,
)
with pytest.raises(ValidationError) as wrong:
assert client.delete_record(zone="example.com", params={"wrong": "attr"})
assert str(wrong.value).startswith("Dataset invalid:")
with pytest.raises(ValidationError) as ntype:
assert client.delete_record(zone="example.com", params={"type": 1})
assert str(ntype.value).startswith("Dataset invalid:")
with pytest.raises(ValidationError) as empty:
assert client.delete_record(zone="example.com", params={})
assert str(empty.value).startswith("Dataset invalid:")

View File

@ -27,4 +27,4 @@ filterwarnings =
ignore:.*pep8.*:FutureWarning
[coverage:run]
omit = **/tests/*
omit = **/test/*

View File

@ -39,7 +39,7 @@ setup(
license=get_property("__license__", PACKAGE_NAME),
long_description=get_readme(),
long_description_content_type="text/markdown",
packages=find_packages(exclude=["*.tests", "tests", "tests.*"]),
packages=find_packages(exclude=["*.test", "test", "test.*"]),
include_package_data=True,
zip_safe=False,
python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,<4",
@ -61,5 +61,5 @@ setup(
],
install_requires=["six", "jsonschema"],
dependency_links=[],
test_suite="tests",
test_suite="test",
)

View File

@ -9,10 +9,10 @@ flake8-logging-format
flake8-polyfill
flake8-quotes
pep8-naming
wheel
pytest
pytest-mock
pytest-cov
bandit
requests-mock
autopep8
yapf