mirror of
https://github.com/thegeeklab/corenetworks.git
synced 2024-11-14 16:50:39 +00:00
fix delete function
This commit is contained in:
parent
43ed62b7ff
commit
83e6acfeee
@ -7,7 +7,7 @@ local PythonVersion(pyversion='2.7') = {
|
|||||||
commands: [
|
commands: [
|
||||||
'pip install -r test-requirements.txt -qq',
|
'pip install -r test-requirements.txt -qq',
|
||||||
'pip install -qq .',
|
'pip install -qq .',
|
||||||
'pytest --cov=corenetworks --no-cov-on-fail',
|
'pytest corenetworks --cov=corenetworks --no-cov-on-fail',
|
||||||
],
|
],
|
||||||
depends_on: [
|
depends_on: [
|
||||||
'clone',
|
'clone',
|
||||||
@ -98,7 +98,7 @@ local PipelineSecurity = {
|
|||||||
commands: [
|
commands: [
|
||||||
'pip install -r test-requirements.txt -qq',
|
'pip install -r test-requirements.txt -qq',
|
||||||
'pip install -qq .',
|
'pip install -qq .',
|
||||||
'bandit -r ./corenetworks -x ./corenetworks/tests',
|
'bandit -r ./corenetworks -x ./corenetworks/test',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
14
.drone.yml
14
.drone.yml
@ -36,7 +36,7 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- pip install -r test-requirements.txt -qq
|
- pip install -r test-requirements.txt -qq
|
||||||
- pip install -qq .
|
- pip install -qq .
|
||||||
- pytest --cov=corenetworks --no-cov-on-fail
|
- pytest corenetworks --cov=corenetworks --no-cov-on-fail
|
||||||
environment:
|
environment:
|
||||||
PY_COLORS: 1
|
PY_COLORS: 1
|
||||||
depends_on:
|
depends_on:
|
||||||
@ -47,7 +47,7 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- pip install -r test-requirements.txt -qq
|
- pip install -r test-requirements.txt -qq
|
||||||
- pip install -qq .
|
- pip install -qq .
|
||||||
- pytest --cov=corenetworks --no-cov-on-fail
|
- pytest corenetworks --cov=corenetworks --no-cov-on-fail
|
||||||
environment:
|
environment:
|
||||||
PY_COLORS: 1
|
PY_COLORS: 1
|
||||||
depends_on:
|
depends_on:
|
||||||
@ -58,7 +58,7 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- pip install -r test-requirements.txt -qq
|
- pip install -r test-requirements.txt -qq
|
||||||
- pip install -qq .
|
- pip install -qq .
|
||||||
- pytest --cov=corenetworks --no-cov-on-fail
|
- pytest corenetworks --cov=corenetworks --no-cov-on-fail
|
||||||
environment:
|
environment:
|
||||||
PY_COLORS: 1
|
PY_COLORS: 1
|
||||||
depends_on:
|
depends_on:
|
||||||
@ -69,7 +69,7 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- pip install -r test-requirements.txt -qq
|
- pip install -r test-requirements.txt -qq
|
||||||
- pip install -qq .
|
- pip install -qq .
|
||||||
- pytest --cov=corenetworks --no-cov-on-fail
|
- pytest corenetworks --cov=corenetworks --no-cov-on-fail
|
||||||
environment:
|
environment:
|
||||||
PY_COLORS: 1
|
PY_COLORS: 1
|
||||||
depends_on:
|
depends_on:
|
||||||
@ -80,7 +80,7 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- pip install -r test-requirements.txt -qq
|
- pip install -r test-requirements.txt -qq
|
||||||
- pip install -qq .
|
- pip install -qq .
|
||||||
- pytest --cov=corenetworks --no-cov-on-fail
|
- pytest corenetworks --cov=corenetworks --no-cov-on-fail
|
||||||
environment:
|
environment:
|
||||||
PY_COLORS: 1
|
PY_COLORS: 1
|
||||||
depends_on:
|
depends_on:
|
||||||
@ -125,7 +125,7 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- pip install -r test-requirements.txt -qq
|
- pip install -r test-requirements.txt -qq
|
||||||
- pip install -qq .
|
- pip install -qq .
|
||||||
- bandit -r ./corenetworks -x ./corenetworks/tests
|
- bandit -r ./corenetworks -x ./corenetworks/test
|
||||||
environment:
|
environment:
|
||||||
PY_COLORS: 1
|
PY_COLORS: 1
|
||||||
|
|
||||||
@ -306,6 +306,6 @@ depends_on:
|
|||||||
|
|
||||||
---
|
---
|
||||||
kind: signature
|
kind: signature
|
||||||
hmac: d81d3b26c9f5d2a75eb6805c47d74217383771d3787bcf8de50eeb0987e1f6ff
|
hmac: dd83d3ebb552aa3998d4868389b730635039fba3c34040c53c380bc6ff2587e4
|
||||||
|
|
||||||
...
|
...
|
||||||
|
@ -23,7 +23,7 @@ from .exceptions import ValidationError
|
|||||||
class CoreNetworks():
|
class CoreNetworks():
|
||||||
"""Create authenticated API client."""
|
"""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.__endpoint = "https://beta.api.core-networks.de"
|
||||||
self.__user_agent = "Core Networks Python API {version}".format(
|
self.__user_agent = "Core Networks Python API {version}".format(
|
||||||
version=corenetworks.__version__
|
version=corenetworks.__version__
|
||||||
@ -117,7 +117,7 @@ class CoreNetworks():
|
|||||||
Example: params={"type": ["NS", "SOA"]} will result in filter=?type[]=NS&type[]=SOA
|
Example: params={"type": ["NS", "SOA"]} will result in filter=?type[]=NS&type[]=SOA
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: List of entry dicts.
|
list: List of matching records.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
schema = copy.deepcopy(self._filter_schema)
|
schema = copy.deepcopy(self._filter_schema)
|
||||||
@ -136,11 +136,12 @@ class CoreNetworks():
|
|||||||
Create a record for the given domain.
|
Create a record for the given domain.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
param1: The first parameter.
|
zone (str): Name of the target DNS zone.
|
||||||
param2: The second parameter.
|
params (dict): Dictionary of record parameters.
|
||||||
|
See https://beta.api.core-networks.de/doc/#functon_dnszones_records_add
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True if successful, False otherwise.
|
list: List of added records.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
schema = copy.deepcopy(self._schema)
|
schema = copy.deepcopy(self._schema)
|
||||||
@ -160,6 +161,12 @@ class CoreNetworks():
|
|||||||
Delete all DNS records of a zone that match the data.
|
Delete all DNS records of a zone that match the data.
|
||||||
|
|
||||||
Args:
|
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)
|
schema = copy.deepcopy(self._schema)
|
||||||
@ -178,10 +185,8 @@ class CoreNetworks():
|
|||||||
if params.get("force_all"):
|
if params.get("force_all"):
|
||||||
params = {}
|
params = {}
|
||||||
|
|
||||||
print(params)
|
|
||||||
|
|
||||||
result = self.__rest_helper(
|
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)
|
return self.__normalize(result)
|
||||||
|
@ -6,6 +6,7 @@ from six.moves.urllib.parse import unquote # noqa
|
|||||||
|
|
||||||
from corenetworks import CoreNetworks
|
from corenetworks import CoreNetworks
|
||||||
from corenetworks.exceptions import CorenetworksError
|
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_get_callback
|
||||||
from corenetworks.tests.fixtures.callback import records_post_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"}]
|
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:")
|
@ -27,4 +27,4 @@ filterwarnings =
|
|||||||
ignore:.*pep8.*:FutureWarning
|
ignore:.*pep8.*:FutureWarning
|
||||||
|
|
||||||
[coverage:run]
|
[coverage:run]
|
||||||
omit = **/tests/*
|
omit = **/test/*
|
||||||
|
4
setup.py
4
setup.py
@ -39,7 +39,7 @@ setup(
|
|||||||
license=get_property("__license__", PACKAGE_NAME),
|
license=get_property("__license__", PACKAGE_NAME),
|
||||||
long_description=get_readme(),
|
long_description=get_readme(),
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
packages=find_packages(exclude=["*.tests", "tests", "tests.*"]),
|
packages=find_packages(exclude=["*.test", "test", "test.*"]),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,<4",
|
python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,<4",
|
||||||
@ -61,5 +61,5 @@ setup(
|
|||||||
],
|
],
|
||||||
install_requires=["six", "jsonschema"],
|
install_requires=["six", "jsonschema"],
|
||||||
dependency_links=[],
|
dependency_links=[],
|
||||||
test_suite="tests",
|
test_suite="test",
|
||||||
)
|
)
|
||||||
|
@ -9,10 +9,10 @@ flake8-logging-format
|
|||||||
flake8-polyfill
|
flake8-polyfill
|
||||||
flake8-quotes
|
flake8-quotes
|
||||||
pep8-naming
|
pep8-naming
|
||||||
|
wheel
|
||||||
pytest
|
pytest
|
||||||
pytest-mock
|
pytest-mock
|
||||||
pytest-cov
|
pytest-cov
|
||||||
bandit
|
bandit
|
||||||
requests-mock
|
requests-mock
|
||||||
autopep8
|
|
||||||
yapf
|
yapf
|
||||||
|
Loading…
Reference in New Issue
Block a user