Skip to content

Commit

Permalink
Add tests for new routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Karetnikov authored and nkaretnikov committed Oct 4, 2023
1 parent 3967898 commit 2c3ba98
Showing 1 changed file with 25 additions and 49 deletions.
74 changes: 25 additions & 49 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,52 +500,53 @@ def test_create_namespace_auth(testclient):
assert r.data.name == namespace


def test_update_namespace_noauth(testclient):
def test_update_namespace_noauth_metadata(testclient):
namespace = f"filesystem"

response = testclient.put(
f"api/v1/namespace/{namespace}/metadata",
json={"test_key1": "test_value1", "test_key2": "test_value2"},
)
assert response.status_code == 403

r = schema.APIResponse.parse_obj(response.json())
assert r.status == schema.APIStatus.ERROR


def test_update_namespace_noauth_role(testclient):
namespace = f"filesystem"
# namespace = f"pytest-{uuid.uuid4()}"

test_role_mappings = {
f"{namespace}/*": ["viewer"],
f"{namespace}/admin": ["admin"],
f"{namespace}/test": ["admin", "viewer", "developer"],
}

# Updates the metadata only
response = testclient.put(
f"api/v1/namespace/{namespace}/",
json={
"metadata": {"test_key1": "test_value1", "test_key2": "test_value2"},
},
f"api/v1/namespace/{namespace}/role", json=test_role_mappings,
)
assert response.status_code == 403

r = schema.APIResponse.parse_obj(response.json())
assert r.status == schema.APIStatus.ERROR

# Updates the role mappings only
response = testclient.put(
f"api/v1/namespace/{namespace}", json={"role_mappings": test_role_mappings}
)
assert response.status_code == 403

r = schema.APIResponse.parse_obj(response.json())
assert r.status == schema.APIStatus.ERROR
def test_update_namespace_auth_metadata(testclient):
namespace = f"filesystem"

testclient.login()

# Updates both the metadata and the role mappings
response = testclient.put(
f"api/v1/namespace/{namespace}",
json={
"metadata": {"test_key1": "test_value1", "test_key2": "test_value2"},
"role_mappings": test_role_mappings,
},
f"api/v1/namespace/{namespace}/metadata",
json={"test_key1": "test_value1", "test_key2": "test_value2"},
)
assert response.status_code == 403
response.raise_for_status()

r = schema.APIResponse.parse_obj(response.json())
assert r.status == schema.APIStatus.ERROR
assert r.status == schema.APIStatus.OK


def test_update_namespace_auth(testclient):
def test_update_namespace_auth_role(testclient):
namespace = f"filesystem"

testclient.login()
Expand All @@ -556,33 +557,8 @@ def test_update_namespace_auth(testclient):
f"{namespace}/test": ["admin", "viewer", "developer"],
}

# Updates both the metadata and the role mappings
response = testclient.put(
f"api/v1/namespace/{namespace}",
json={
"metadata": {"test_key1": "test_value1", "test_key2": "test_value2"},
"role_mappings": test_role_mappings,
},
)

r = schema.APIResponse.parse_obj(response.json())
assert r.status == schema.APIStatus.OK

# Updates the metadata only
response = testclient.put(
f"api/v1/namespace/{namespace}/",
json={
"metadata": {"test_key1": "test_value1", "test_key2": "test_value2"},
},
)
response.raise_for_status()

r = schema.APIResponse.parse_obj(response.json())
assert r.status == schema.APIStatus.OK

# Updates the role mappings only
response = testclient.put(
f"api/v1/namespace/{namespace}", json={"role_mappings": test_role_mappings}
f"api/v1/namespace/{namespace}/role", json=test_role_mappings,
)

r = schema.APIResponse.parse_obj(response.json())
Expand Down

0 comments on commit 2c3ba98

Please sign in to comment.