Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test to get the folder assigned to the user's user group #129

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions backend/app_tests/api/test_api_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ def test_delete_folders(self):
class TestFoldersAuthenticated:
"""Perform tests on Folders API endpoint with authentication"""

def test_get_assigned_folder(self, test):
"""test to get the folder assigned to the user's user group"""

EndpointTestsQueries.Auth.get_object(
test.client,
"Folders",
test_params={
"name": test.assigned_folder.name,
},
item_search_field="name",
base_count=-1,
user_group=test.user_group,
scope=str(test.folder),
)

def test_get_folders(self, test):
"""test to get folders from the API with authentication"""

Expand Down
30 changes: 15 additions & 15 deletions backend/app_tests/api/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,20 +359,21 @@ def get_object(
else f"Accessing {verbose_name.lower()} should give a status {user_perm_expected_status}"
)

if (
base_count == 0
and not (object and build_params)
and test_params
and not (fails or user_perm_fails)
):
# perfom a test with an externally created object
assert (
response.json()["count"] == base_count + 1
), f"{verbose_name} are not accessible with authentication"
elif base_count > 0 and not (fails or user_perm_fails):
assert (
response.json()["count"] == base_count
), f"{verbose_name} are not accessible with authentication"
if not (fails or user_perm_fails):
if not (object and build_params) and test_params:
if base_count == 0:
# perfom a test with an externally created object
assert (
response.json()["count"] == base_count + 1
), f"{verbose_name} are not accessible with authentication"
elif base_count < 0:
assert (
len(response.json()["results"]) != 0
), f"{verbose_name} are not accessible with authentication"
elif base_count > 0:
assert (
response.json()["count"] == base_count
), f"{verbose_name} are not accessible with authentication"

# Creates a test object from the model
if build_params and object:
Expand Down Expand Up @@ -554,7 +555,6 @@ def create_object(

# Uses the API endpoint to create an object with authentication
response = authenticated_client.post(url, build_params, format=query_format)
print(response.json())

if fails:
# Asserts that the object was not created
Expand Down
3 changes: 2 additions & 1 deletion backend/app_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ def authenticated_client(app_config):
)
def test(authenticated_client, request) -> Test:
"""Get the elements used by the tests such as client and associated folder"""
client, folder, _ = EndpointTestsUtils.get_test_client_and_folder(
client, folder, assigned_folder = EndpointTestsUtils.get_test_client_and_folder(
authenticated_client, request.param[0], request.param[1]
)
return Test(
{
"client": client,
"admin_client": authenticated_client,
"folder": folder,
"assigned_folder": assigned_folder,
"user_group": request.param[0],
}
)
Loading