-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement tests for being able to create collections
- Loading branch information
1 parent
55c8c79
commit 6b1a9fe
Showing
8 changed files
with
96 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
from concierge_backend_lib.authentication import ( | ||
get_keycloak_client, | ||
get_keycloak_admin_openid_token, | ||
) | ||
from concierge_backend_lib.authentication import get_keycloak_admin_openid_token | ||
from concierge_backend_lib.authorization import auth_enabled | ||
|
||
|
||
def get_token(): | ||
if not auth_enabled: | ||
return {"access_token": None} | ||
openid_client = get_keycloak_client() | ||
return get_keycloak_admin_openid_token(openid_client) | ||
return get_keycloak_admin_openid_token() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
asyncio_mode=auto | ||
asyncio_default_fixture_loop_scope=session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# This test should be run once Concierge is installed with the demo RBAC configuration | ||
# For best results it should be fresh installation with no collections created or tweaks made to the access controls | ||
# Do not use this on a production instance! | ||
|
||
from concierge_backend_lib.authentication import ( | ||
get_keycloak_client, | ||
get_keycloak_admin_openid_token, | ||
) | ||
from concierge_backend_lib.document_collections import ( | ||
create_collection, | ||
delete_collection, | ||
) | ||
import pytest | ||
from keycloak import KeycloakPostError | ||
import asyncio | ||
|
||
keycloak_client = get_keycloak_client() | ||
|
||
# we will use the collections created in the first tests for the subsequent tests | ||
collection_lookup = {} | ||
|
||
|
||
async def create_collection_for_user(user, location): | ||
token = keycloak_client.token(user, "test") | ||
collection_name = f"{user}'s {location} collection" | ||
collection_id = await create_collection( | ||
token["access_token"], f"{user}'s {location} collection", location | ||
) | ||
collection_lookup[collection_name] = collection_id | ||
return collection_id | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"user,location", | ||
[ | ||
("testadmin", "private"), | ||
("testadmin", "shared"), | ||
("testshared", "shared"), | ||
("testprivate", "private"), | ||
], | ||
) | ||
async def test_can_create_collection(user, location): | ||
assert await create_collection_for_user(user, location) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"user,location", | ||
[ | ||
("testshared", "private"), | ||
("testprivate", "shared"), | ||
("testsharedread", "private"), | ||
("testsharedread", "shared"), | ||
("testnothing", "private"), | ||
("testnothing", "shared"), | ||
], | ||
) | ||
async def test_cannot_create_collection(user, location): | ||
with pytest.raises(KeycloakPostError): | ||
await create_collection_for_user(user, location) | ||
|
||
|
||
async def teardown(): | ||
token = get_keycloak_admin_openid_token() | ||
for id in collection_lookup.values(): | ||
token = get_keycloak_admin_openid_token() | ||
await delete_collection(token["access_token"], id) | ||
|
||
|
||
def teardown_module(): | ||
asyncio.run(teardown()) |