mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-10 07:30: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
135 lines
5.1 KiB
Python
135 lines
5.1 KiB
Python
import pytest
|
|
import json
|
|
from collections import namedtuple
|
|
|
|
from powerdnsadmin.lib.validators import validate_apikey
|
|
from powerdnsadmin.lib.schema import ApiKeySchema
|
|
from tests.conftest import user_apikey_data, admin_apikey_data
|
|
|
|
|
|
class TestIntegrationApiApiKeyAdminUser(object):
|
|
def test_empty_get(self, client, initial_data, basic_auth_admin_headers):
|
|
res = client.get("/api/v1/pdnsadmin/apikeys",
|
|
headers=basic_auth_admin_headers)
|
|
data = res.get_json(force=True)
|
|
assert res.status_code == 200
|
|
assert data == []
|
|
|
|
@pytest.mark.parametrize(
|
|
"apikey_data",
|
|
[user_apikey_data(), admin_apikey_data()])
|
|
def test_create_apikey(self, client, initial_data, apikey_data, zone_data,
|
|
basic_auth_admin_headers):
|
|
res = client.post("/api/v1/pdnsadmin/zones",
|
|
headers=basic_auth_admin_headers,
|
|
data=json.dumps(zone_data),
|
|
content_type="application/json")
|
|
data = res.get_json(force=True)
|
|
|
|
assert res.status_code == 201
|
|
|
|
res = client.post("/api/v1/pdnsadmin/apikeys",
|
|
headers=basic_auth_admin_headers,
|
|
data=json.dumps(apikey_data),
|
|
content_type="application/json")
|
|
data = res.get_json(force=True)
|
|
|
|
validate_apikey(data)
|
|
assert res.status_code == 201
|
|
|
|
apikey_url_format = "/api/v1/pdnsadmin/apikeys/{0}"
|
|
apikey_url = apikey_url_format.format(data['id'])
|
|
|
|
res = client.delete(apikey_url, headers=basic_auth_admin_headers)
|
|
|
|
assert res.status_code == 204
|
|
|
|
zone_url_format = "/api/v1/pdnsadmin/zones/{0}"
|
|
zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
|
|
res = client.delete(zone_url, headers=basic_auth_admin_headers)
|
|
|
|
assert res.status_code == 204
|
|
|
|
@pytest.mark.parametrize(
|
|
"apikey_data",
|
|
[user_apikey_data(), admin_apikey_data()])
|
|
def test_get_multiple_apikey(self, client, initial_data, apikey_data,
|
|
zone_data, basic_auth_admin_headers):
|
|
res = client.post("/api/v1/pdnsadmin/zones",
|
|
headers=basic_auth_admin_headers,
|
|
data=json.dumps(zone_data),
|
|
content_type="application/json")
|
|
data = res.get_json(force=True)
|
|
|
|
assert res.status_code == 201
|
|
|
|
res = client.post("/api/v1/pdnsadmin/apikeys",
|
|
headers=basic_auth_admin_headers,
|
|
data=json.dumps(apikey_data),
|
|
content_type="application/json")
|
|
data = res.get_json(force=True)
|
|
|
|
validate_apikey(data)
|
|
assert res.status_code == 201
|
|
|
|
res = client.get("/api/v1/pdnsadmin/apikeys",
|
|
headers=basic_auth_admin_headers)
|
|
data = res.get_json(force=True)
|
|
|
|
fake_role = namedtuple(
|
|
"Role", data[0]['role'].keys())(*data[0]['role'].values())
|
|
|
|
data[0]['domains'] = []
|
|
data[0]['role'] = fake_role
|
|
fake_apikey = namedtuple("ApiKey", data[0].keys())(*data[0].values())
|
|
apikey_schema = ApiKeySchema(many=True)
|
|
|
|
json.dumps(apikey_schema.dump([fake_apikey]))
|
|
assert res.status_code == 200
|
|
|
|
apikey_url_format = "/api/v1/pdnsadmin/apikeys/{0}"
|
|
apikey_url = apikey_url_format.format(fake_apikey.id)
|
|
res = client.delete(apikey_url, headers=basic_auth_admin_headers)
|
|
|
|
assert res.status_code == 204
|
|
|
|
zone_url_format = "/api/v1/pdnsadmin/zones/{0}"
|
|
zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
|
|
res = client.delete(zone_url, headers=basic_auth_admin_headers)
|
|
|
|
assert res.status_code == 204
|
|
|
|
@pytest.mark.parametrize(
|
|
"apikey_data",
|
|
[user_apikey_data(), admin_apikey_data()])
|
|
def test_delete_apikey(self, client, initial_data, apikey_data, zone_data,
|
|
basic_auth_admin_headers):
|
|
res = client.post("/api/v1/pdnsadmin/zones",
|
|
headers=basic_auth_admin_headers,
|
|
data=json.dumps(zone_data),
|
|
content_type="application/json")
|
|
data = res.get_json(force=True)
|
|
|
|
assert res.status_code == 201
|
|
|
|
res = client.post("/api/v1/pdnsadmin/apikeys",
|
|
headers=basic_auth_admin_headers,
|
|
data=json.dumps(apikey_data),
|
|
content_type="application/json")
|
|
data = res.get_json(force=True)
|
|
|
|
validate_apikey(data)
|
|
assert res.status_code == 201
|
|
|
|
apikey_url_format = "/api/v1/pdnsadmin/apikeys/{0}"
|
|
apikey_url = apikey_url_format.format(data['id'])
|
|
res = client.delete(apikey_url, headers=basic_auth_admin_headers)
|
|
|
|
assert res.status_code == 204
|
|
|
|
zone_url_format = "/api/v1/pdnsadmin/zones/{0}"
|
|
zone_url = zone_url_format.format(zone_data['name'].rstrip("."))
|
|
res = client.delete(zone_url, headers=basic_auth_admin_headers)
|
|
|
|
assert res.status_code == 204
|