2019-03-01 22:49:31 +00:00
|
|
|
import json
|
|
|
|
from collections import namedtuple
|
2019-12-06 03:32:57 +00:00
|
|
|
|
|
|
|
from powerdnsadmin.lib.validators import validate_zone
|
|
|
|
from powerdnsadmin.lib.schema import DomainSchema
|
2019-03-01 22:49:31 +00:00
|
|
|
|
|
|
|
|
2022-12-22 21:47:02 +00:00
|
|
|
class TestIntegrationApiApiKeyUser(object):
|
2019-03-01 22:49:31 +00:00
|
|
|
def test_empty_get(self, initial_data, client, basic_auth_user_headers):
|
2019-12-06 03:32:57 +00:00
|
|
|
res = client.get("/api/v1/pdnsadmin/zones",
|
|
|
|
headers=basic_auth_user_headers)
|
2019-03-01 22:49:31 +00:00
|
|
|
data = res.get_json(force=True)
|
|
|
|
assert res.status_code == 200
|
|
|
|
assert data == []
|
|
|
|
|
2019-12-06 03:32:57 +00:00
|
|
|
def test_create_zone(self, initial_data, client, zone_data,
|
|
|
|
basic_auth_user_headers):
|
|
|
|
res = client.post("/api/v1/pdnsadmin/zones",
|
|
|
|
headers=basic_auth_user_headers,
|
|
|
|
data=json.dumps(zone_data),
|
|
|
|
content_type="application/json")
|
2019-03-01 22:49:31 +00:00
|
|
|
data = res.get_json(force=True)
|
|
|
|
data['rrsets'] = []
|
|
|
|
|
|
|
|
validate_zone(data)
|
|
|
|
assert res.status_code == 201
|
|
|
|
|
|
|
|
zone_url_format = "/api/v1/pdnsadmin/zones/{0}"
|
|
|
|
zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
|
2019-12-06 03:32:57 +00:00
|
|
|
res = client.delete(zone_url, headers=basic_auth_user_headers)
|
2019-03-01 22:49:31 +00:00
|
|
|
|
|
|
|
assert res.status_code == 204
|
|
|
|
|
2019-12-06 03:32:57 +00:00
|
|
|
def test_get_multiple_zones(self, initial_data, client, zone_data,
|
|
|
|
basic_auth_user_headers):
|
|
|
|
res = client.post("/api/v1/pdnsadmin/zones",
|
|
|
|
headers=basic_auth_user_headers,
|
|
|
|
data=json.dumps(zone_data),
|
|
|
|
content_type="application/json")
|
2019-03-01 22:49:31 +00:00
|
|
|
data = res.get_json(force=True)
|
|
|
|
data['rrsets'] = []
|
|
|
|
|
|
|
|
validate_zone(data)
|
|
|
|
assert res.status_code == 201
|
|
|
|
|
2019-12-06 03:32:57 +00:00
|
|
|
res = client.get("/api/v1/pdnsadmin/zones",
|
|
|
|
headers=basic_auth_user_headers)
|
2019-03-01 22:49:31 +00:00
|
|
|
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/pdnsadmin/zones/{0}"
|
|
|
|
zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
|
2019-12-06 03:32:57 +00:00
|
|
|
res = client.delete(zone_url, headers=basic_auth_user_headers)
|
2019-03-01 22:49:31 +00:00
|
|
|
|
|
|
|
assert res.status_code == 204
|
|
|
|
|
2019-12-06 03:32:57 +00:00
|
|
|
def test_delete_zone(self, initial_data, client, zone_data,
|
|
|
|
basic_auth_user_headers):
|
|
|
|
res = client.post("/api/v1/pdnsadmin/zones",
|
|
|
|
headers=basic_auth_user_headers,
|
|
|
|
data=json.dumps(zone_data),
|
|
|
|
content_type="application/json")
|
2019-03-01 22:49:31 +00:00
|
|
|
data = res.get_json(force=True)
|
|
|
|
data['rrsets'] = []
|
|
|
|
|
|
|
|
validate_zone(data)
|
|
|
|
assert res.status_code == 201
|
|
|
|
|
|
|
|
zone_url_format = "/api/v1/pdnsadmin/zones/{0}"
|
|
|
|
zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
|
2019-12-06 03:32:57 +00:00
|
|
|
res = client.delete(zone_url, headers=basic_auth_user_headers)
|
2019-03-01 22:49:31 +00:00
|
|
|
|
|
|
|
assert res.status_code == 204
|