forked from bcgov/bcregistry-sre
-
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 bcgov#140 from shaangill025/feat_safelist_email_ad…
…d_and_rm 20463 - Feat: Support Safe List Addition and Removal
- Loading branch information
Showing
4 changed files
with
66 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""The Unit Test for the SafeList Model.""" | ||
|
||
from notify_api.models.safe_list import SafeList | ||
|
||
|
||
def test_safe_list(): | ||
"""Assert the test safe list model vaildation.""" | ||
safelist = SafeList() | ||
safelist.add_email("[email protected]") | ||
safelist.add_email("[email protected]") | ||
assert safelist.is_in_safe_list("[email protected]") | ||
assert safelist.is_in_safe_list("[email protected]") | ||
# Test delete email | ||
safelist_to_delete = safelist.find_by_email("[email protected]") | ||
safelist_to_delete.delete_email() | ||
assert not safelist.is_in_safe_list("[email protected]") | ||
assert safelist.is_in_safe_list("[email protected]") | ||
# Test add email | ||
safelist.add_email("[email protected]") | ||
assert safelist.is_in_safe_list("[email protected]") | ||
assert safelist.is_in_safe_list("[email protected]") |
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 |
---|---|---|
|
@@ -20,12 +20,29 @@ | |
|
||
def test_safe_list(session, client, jwt): # pylint: disable=unused-argument | ||
"""Assert that the safe list returns.""" | ||
headers = create_header(jwt, [Role.STAFF.value], **{"Accept-Version": "v2"}) | ||
safelist = SafeList() | ||
headers = create_header(jwt, [Role.STAFF.value], **{"Accept-Version": "v2"}) | ||
safelist.add_email("[email protected]") | ||
safelist.add_email("[email protected]") | ||
response = client.get("/api/v2/safe_list/", headers=headers) | ||
assert response.status_code == 200 | ||
assert response.json | ||
assert len(response.json) == 2 | ||
assert response.json[0]["email"] == "[email protected]" | ||
# Test delete endpoint | ||
delete_response = client.delete(f"/api/v2/safe_list/{'[email protected]'}", headers=headers) | ||
assert delete_response.status_code == 200 | ||
response = client.get("/api/v2/safe_list/", headers=headers) | ||
assert response.status_code == 200 | ||
assert response.json | ||
assert len(response.json) == 1 | ||
assert safelist.is_in_safe_list("[email protected]") | ||
# Test add post endpoint | ||
add_request_data = {"email": ["[email protected]"]} | ||
add_response = client.post("/api/v2/safe_list/", json=add_request_data, headers=headers) | ||
assert add_response.status_code == 200 | ||
response = client.get("/api/v2/safe_list/", headers=headers) | ||
assert response.status_code == 200 | ||
assert response.json | ||
assert len(response.json) == 2 | ||
assert safelist.is_in_safe_list("[email protected]") | ||
assert safelist.is_in_safe_list("[email protected]") |