mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-08 22:50:26 +00:00
8d849ee2a1
The `unit/apikey` directory is removed because it does not contain any tests. Same for `unit/test_decorators.py`. The `fixture` module is renamed to the special-name `conftest` [0] so they are available in all tests without the need to import them. With that in place, I removed all now unneeded or previously already unused imports from the tests. Also removed that wierd `sys.path` bit from `unit/zone/test_admin_apikey.py`, no idea what that was originally intended for. [0] https://docs.pytest.org/en/6.2.x/fixture.html#conftest-py-sharing-fixtures-across-multiple-files
79 lines
3.1 KiB
Python
79 lines
3.1 KiB
Python
import json
|
|
from collections import namedtuple
|
|
|
|
from powerdnsadmin.lib.validators import validate_zone
|
|
from powerdnsadmin.lib.schema import DomainSchema
|
|
|
|
|
|
class TestIntegrationApiZoneAdminApiKey(object):
|
|
def test_empty_get(self, client, initial_apikey_data,
|
|
admin_apikey_integration):
|
|
res = client.get("/api/v1/servers/localhost/zones",
|
|
headers=admin_apikey_integration)
|
|
data = res.get_json(force=True)
|
|
assert res.status_code == 200
|
|
assert data == []
|
|
|
|
def test_create_zone(self, client, initial_apikey_data, zone_data,
|
|
admin_apikey_integration):
|
|
res = client.post("/api/v1/servers/localhost/zones",
|
|
headers=admin_apikey_integration,
|
|
data=json.dumps(zone_data),
|
|
content_type="application/json")
|
|
data = res.get_json(force=True)
|
|
data['rrsets'] = []
|
|
|
|
validate_zone(data)
|
|
assert res.status_code == 201
|
|
|
|
zone_url_format = "/api/v1/servers/localhost/zones/{0}"
|
|
zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
|
|
res = client.delete(zone_url, headers=admin_apikey_integration)
|
|
|
|
assert res.status_code == 204
|
|
|
|
def test_get_multiple_zones(self, client, initial_apikey_data, zone_data,
|
|
admin_apikey_integration):
|
|
res = client.post("/api/v1/servers/localhost/zones",
|
|
headers=admin_apikey_integration,
|
|
data=json.dumps(zone_data),
|
|
content_type="application/json")
|
|
data = res.get_json(force=True)
|
|
data['rrsets'] = []
|
|
|
|
validate_zone(data)
|
|
assert res.status_code == 201
|
|
|
|
res = client.get("/api/v1/servers/localhost/zones",
|
|
headers=admin_apikey_integration)
|
|
data = res.get_json(force=True)
|
|
fake_domain = namedtuple("Domain", data[0].keys())(*data[0].values())
|
|
domain_schema = DomainSchema(many=True)
|
|
|
|
json.dumps(domain_schema.dump([fake_domain]))
|
|
assert res.status_code == 200
|
|
|
|
zone_url_format = "/api/v1/servers/localhost/zones/{0}"
|
|
zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
|
|
res = client.delete(zone_url, headers=admin_apikey_integration)
|
|
|
|
assert res.status_code == 204
|
|
|
|
def test_delete_zone(self, client, initial_apikey_data, zone_data,
|
|
admin_apikey_integration):
|
|
res = client.post("/api/v1/servers/localhost/zones",
|
|
headers=admin_apikey_integration,
|
|
data=json.dumps(zone_data),
|
|
content_type="application/json")
|
|
data = res.get_json(force=True)
|
|
data['rrsets'] = []
|
|
|
|
validate_zone(data)
|
|
assert res.status_code == 201
|
|
|
|
zone_url_format = "/api/v1/servers/localhost/zones/{0}"
|
|
zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
|
|
res = client.delete(zone_url, headers=admin_apikey_integration)
|
|
|
|
assert res.status_code == 204
|