This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from communitiesuk/funding-service-design-TEMPLATE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #225 from communitiesuk/FS-4063-assessors-api
Added API endpoint to retrieve users for fund
- Loading branch information
Showing
4 changed files
with
192 additions
and
0 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
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
Tests the GET and POST functionality of our api. | ||
""" | ||
|
||
import uuid | ||
|
||
import pytest | ||
|
||
from tests.conftest import test_user_1 | ||
|
@@ -327,3 +329,103 @@ def test_update_role_with_non_existent_role_allows(self, flask_test_client, clea | |
response = flask_test_client.put(url, json=params) | ||
|
||
assert response.status_code == 201 | ||
|
||
|
||
class TestGetAccountsForFund: | ||
@pytest.mark.user_config( | ||
[ | ||
{ | ||
"email": "[email protected]", | ||
"subject_id": "1", | ||
"account_id": uuid.uuid4(), | ||
"roles": ["COF_ASSESSOR_R1"], | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"subject_id": "2", | ||
"account_id": uuid.uuid4(), | ||
"roles": ["COF_COMMENTER_R1"], | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"subject_id": "3", | ||
"account_id": uuid.uuid4(), | ||
"roles": ["COF_COMMENTER_R2"], | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"subject_id": "4", | ||
"account_id": uuid.uuid4(), | ||
"roles": ["HSRA_ASSESSOR_R1"], | ||
}, | ||
] | ||
) | ||
def test_successful_retrieval(self, flask_test_client, seed_test_data_fn): | ||
response = flask_test_client.get("/accounts/fund/COF") | ||
assert response.status_code == 200 | ||
assert len(response.json) == 3 | ||
|
||
@pytest.mark.user_config( | ||
[ | ||
{ | ||
"email": "[email protected]", | ||
"subject_id": "1", | ||
"account_id": uuid.uuid4(), | ||
"roles": ["COF_ASSESSOR_R1"], | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"subject_id": "2", | ||
"account_id": uuid.uuid4(), | ||
"roles": ["COF_COMMENTER_R1"], | ||
}, | ||
] | ||
) | ||
def test_assessors_only(self, flask_test_client, seed_test_data_fn): | ||
response = flask_test_client.get("/accounts/fund/COF?include_assessors=true&include_commenters=false") | ||
assert response.status_code == 200 | ||
assert len(response.json) == 1 # Only the assessor should be returned | ||
assert all("ASSESSOR" in role for role in response.json[0]["roles"]) | ||
|
||
@pytest.mark.user_config( | ||
[ | ||
{ | ||
"email": "[email protected]", | ||
"subject_id": "1", | ||
"account_id": uuid.uuid4(), | ||
"roles": ["COF_ASSESSOR_R1"], | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"subject_id": "2", | ||
"account_id": uuid.uuid4(), | ||
"roles": ["COF_COMMENTER_R1"], | ||
}, | ||
] | ||
) | ||
def test_commenters_only(self, flask_test_client, seed_test_data_fn): | ||
response = flask_test_client.get("/accounts/fund/COF?include_assessors=false&include_commenters=true") | ||
assert response.status_code == 200 | ||
assert len(response.json) == 1 # Only the commenter should be returned | ||
assert all("COMMENTER" in role for role in response.json[0]["roles"]) | ||
|
||
@pytest.mark.user_config([]) # No users configured | ||
def test_no_matching_accounts(self, flask_test_client, seed_test_data_fn): | ||
response = flask_test_client.get("/accounts/fund/unknownfund") | ||
assert response.status_code == 404 | ||
assert response.json == {"error": "No matching accounts found"} | ||
|
||
@pytest.mark.user_config( | ||
[ | ||
{ | ||
"email": "[email protected]", | ||
"subject_id": "3", | ||
"account_id": uuid.uuid4(), | ||
"roles": ["COF_ASSESSOR_R1", "COF_COMMENTER_R1"], | ||
} | ||
] | ||
) | ||
def test_bad_request(self, flask_test_client, seed_test_data_fn): | ||
response = flask_test_client.get("/accounts/fund/COF?include_assessors=false&include_commenters=false") | ||
assert response.status_code == 400 | ||
assert response.json == {"error": "One of include_assessors or include_commenters must be true"} |