mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2025-06-15 20:46:06 +00:00
Update tests fix
Fix migration init_db 'id' Handle app context when needed Fix conftest fixtures Rearrange test Dockerfiles Hide DeprecationWarning during pytest execution Upgrade all python packages
This commit is contained in:
@ -8,7 +8,7 @@ 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):
|
||||
def test_empty_get(self, initial_data, client, basic_auth_admin_headers):
|
||||
res = client.get("/api/v1/pdnsadmin/apikeys",
|
||||
headers=basic_auth_admin_headers)
|
||||
data = res.get_json(force=True)
|
||||
@ -18,7 +18,7 @@ class TestIntegrationApiApiKeyAdminUser(object):
|
||||
@pytest.mark.parametrize(
|
||||
"apikey_data",
|
||||
[user_apikey_data(), admin_apikey_data()])
|
||||
def test_create_apikey(self, client, initial_data, apikey_data, zone_data,
|
||||
def test_create_apikey(self, initial_data, client, apikey_data, zone_data,
|
||||
basic_auth_admin_headers):
|
||||
res = client.post("/api/v1/pdnsadmin/zones",
|
||||
headers=basic_auth_admin_headers,
|
||||
@ -53,7 +53,7 @@ class TestIntegrationApiApiKeyAdminUser(object):
|
||||
@pytest.mark.parametrize(
|
||||
"apikey_data",
|
||||
[user_apikey_data(), admin_apikey_data()])
|
||||
def test_get_multiple_apikey(self, client, initial_data, apikey_data,
|
||||
def test_get_multiple_apikey(self, initial_data, client, apikey_data,
|
||||
zone_data, basic_auth_admin_headers):
|
||||
res = client.post("/api/v1/pdnsadmin/zones",
|
||||
headers=basic_auth_admin_headers,
|
||||
@ -102,7 +102,7 @@ class TestIntegrationApiApiKeyAdminUser(object):
|
||||
@pytest.mark.parametrize(
|
||||
"apikey_data",
|
||||
[user_apikey_data(), admin_apikey_data()])
|
||||
def test_delete_apikey(self, client, initial_data, apikey_data, zone_data,
|
||||
def test_delete_apikey(self, initial_data, client, apikey_data, zone_data,
|
||||
basic_auth_admin_headers):
|
||||
res = client.post("/api/v1/pdnsadmin/zones",
|
||||
headers=basic_auth_admin_headers,
|
||||
|
@ -5,7 +5,7 @@ from powerdnsadmin.lib.validators import validate_zone
|
||||
from powerdnsadmin.lib.schema import DomainSchema
|
||||
|
||||
|
||||
class TestIntegrationApiZoneUser(object):
|
||||
class TestIntegrationApiApiKeyUser(object):
|
||||
def test_empty_get(self, initial_data, client, basic_auth_user_headers):
|
||||
res = client.get("/api/v1/pdnsadmin/zones",
|
||||
headers=basic_auth_user_headers)
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
import json
|
||||
|
||||
from . import IntegrationApiManagement
|
||||
@ -6,57 +5,57 @@ from . import IntegrationApiManagement
|
||||
|
||||
class TestIntegrationApiManagementUser(IntegrationApiManagement):
|
||||
|
||||
def test_accounts_empty_get(
|
||||
self, client, initial_data, # noqa: F811
|
||||
basic_auth_user_headers): # noqa: F811
|
||||
def test_accounts_empty_get(self, initial_data, client, # noqa: F811
|
||||
basic_auth_user_headers): # noqa: F811
|
||||
res = client.get("/api/v1/pdnsadmin/accounts",
|
||||
headers=basic_auth_user_headers)
|
||||
assert res.status_code == 401
|
||||
|
||||
def test_users_empty_get(
|
||||
self, client, initial_data, # noqa: F811
|
||||
test_admin_user, test_user, # noqa: F811
|
||||
basic_auth_user_headers): # noqa: F811
|
||||
def test_users_empty_get(self, initial_data, client, # noqa: F811
|
||||
test_admin_user, test_user, # noqa: F811
|
||||
basic_auth_user_headers): # noqa: F811
|
||||
res = client.get("/api/v1/pdnsadmin/users",
|
||||
headers=basic_auth_user_headers)
|
||||
assert res.status_code == 401
|
||||
|
||||
def test_self_get(
|
||||
self, initial_data, client, test_user, # noqa: F811
|
||||
basic_auth_user_headers): # noqa: F811
|
||||
self.user = None
|
||||
def test_self_get(self, initial_data, client, basic_auth_user_headers, test_user): # noqa: F811
|
||||
res = client.get("/api/v1/pdnsadmin/users/{}".format(test_user),
|
||||
headers=basic_auth_user_headers)
|
||||
data = res.get_json(force=True)
|
||||
assert res.status_code == 200
|
||||
assert data
|
||||
self.user = [data]
|
||||
|
||||
def test_accounts(
|
||||
self, client, initial_data, # noqa: F811
|
||||
account_data, # noqa: F811
|
||||
basic_auth_admin_headers, basic_auth_user_headers): # noqa: F811
|
||||
def test_create_account_fail(self, client, initial_data, account_data, # noqa: F811
|
||||
basic_auth_user_headers): # noqa: F811
|
||||
|
||||
# Create account (should fail)
|
||||
res = client.post("/api/v1/pdnsadmin/accounts",
|
||||
headers=basic_auth_user_headers,
|
||||
data=json.dumps(account_data),
|
||||
content_type="application/json")
|
||||
assert res.status_code == 401
|
||||
|
||||
def test_create_account_as_admin(self, app, initial_data, client, account_data, # noqa: F811
|
||||
basic_auth_admin_headers): # noqa: F811
|
||||
self.client = client
|
||||
self.basic_auth_admin_headers = basic_auth_admin_headers
|
||||
|
||||
# Create account (should fail)
|
||||
res = client.post(
|
||||
"/api/v1/pdnsadmin/accounts",
|
||||
headers=basic_auth_user_headers,
|
||||
data=json.dumps(account_data),
|
||||
content_type="application/json",
|
||||
)
|
||||
assert res.status_code == 401
|
||||
with app.test_request_context():
|
||||
# Create account (as admin)
|
||||
res = client.post("/api/v1/pdnsadmin/accounts",
|
||||
headers=basic_auth_admin_headers,
|
||||
data=json.dumps(account_data),
|
||||
content_type="application/json")
|
||||
data = res.get_json(force=True)
|
||||
assert res.status_code == 201
|
||||
|
||||
# Create account (as admin)
|
||||
res = client.post(
|
||||
"/api/v1/pdnsadmin/accounts",
|
||||
headers=basic_auth_admin_headers,
|
||||
data=json.dumps(account_data),
|
||||
content_type="application/json",
|
||||
)
|
||||
data = res.get_json(force=True)
|
||||
assert res.status_code == 201
|
||||
def test_update_account_fail(
|
||||
self, initial_data, client, # noqa: F811
|
||||
account_data, # noqa: F811
|
||||
basic_auth_user_headers,
|
||||
basic_auth_admin_headers): # noqa: F811
|
||||
self.client = client
|
||||
self.basic_auth_admin_headers = basic_auth_admin_headers
|
||||
|
||||
# Check account
|
||||
data = self.check_account(account_data)
|
||||
@ -71,6 +70,18 @@ class TestIntegrationApiManagementUser(IntegrationApiManagement):
|
||||
)
|
||||
assert res.status_code == 401
|
||||
|
||||
def test_delete_account_fail(
|
||||
self, initial_data, client, # noqa: F811
|
||||
account_data, # noqa: F811
|
||||
basic_auth_user_headers,
|
||||
basic_auth_admin_headers): # noqa: F811
|
||||
self.client = client
|
||||
self.basic_auth_admin_headers = basic_auth_admin_headers
|
||||
|
||||
# Check account
|
||||
data = self.check_account(account_data)
|
||||
account_id = data["id"]
|
||||
|
||||
# Delete account (should fail)
|
||||
res = client.delete(
|
||||
"/api/v1/pdnsadmin/accounts/{}".format(account_id),
|
||||
@ -80,6 +91,17 @@ class TestIntegrationApiManagementUser(IntegrationApiManagement):
|
||||
)
|
||||
assert res.status_code == 401
|
||||
|
||||
def test_delete_account_as_admin(
|
||||
self, client, initial_data, # noqa: F811
|
||||
account_data, # noqa: F811
|
||||
basic_auth_admin_headers): # noqa: F811
|
||||
self.client = client
|
||||
self.basic_auth_admin_headers = basic_auth_admin_headers
|
||||
|
||||
# Check account
|
||||
data = self.check_account(account_data)
|
||||
account_id = data["id"]
|
||||
|
||||
# Cleanup (delete account as admin)
|
||||
res = client.delete(
|
||||
"/api/v1/pdnsadmin/accounts/{}".format(account_id),
|
||||
@ -90,8 +112,8 @@ class TestIntegrationApiManagementUser(IntegrationApiManagement):
|
||||
assert res.status_code == 204
|
||||
|
||||
def test_users(
|
||||
self, client, initial_data, # noqa: F811
|
||||
user1_data, # noqa: F811
|
||||
self, client, initial_data, # noqa: F811
|
||||
user1_data, # noqa: F811
|
||||
basic_auth_admin_headers, basic_auth_user_headers): # noqa: F811
|
||||
self.client = client
|
||||
self.basic_auth_admin_headers = basic_auth_admin_headers
|
||||
@ -150,8 +172,8 @@ class TestIntegrationApiManagementUser(IntegrationApiManagement):
|
||||
assert res.status_code == 204
|
||||
|
||||
def test_account_users(
|
||||
self, client, initial_data, # noqa: F811
|
||||
account_data, user1_data, # noqa: F811
|
||||
self, client, initial_data, # noqa: F811
|
||||
account_data, user1_data, # noqa: F811
|
||||
basic_auth_admin_headers, basic_auth_user_headers): # noqa: F811
|
||||
self.client = client
|
||||
self.basic_auth_admin_headers = basic_auth_admin_headers
|
||||
|
Reference in New Issue
Block a user