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.
Signed-off-by: Shaanjot Gill <[email protected]>
- Loading branch information
1 parent
f14d50b
commit fc2035f
Showing
4 changed files
with
48 additions
and
18 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 |
---|---|---|
|
@@ -13,31 +13,36 @@ | |
# limitations under the License. | ||
"""Tests to assure the safe list end-point.""" | ||
|
||
import json | ||
|
||
from notify_api.models.safe_list import SafeList | ||
from notify_api.utils.enums import Role | ||
from tests.factories.jwt import create_header | ||
|
||
|
||
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]" | ||
del_response = client.delete(f'/api/v2/safe_list/{"[email protected]"}', headers=headers) | ||
assert del_response.status_code == 200 | ||
assert not SafeList.is_in_safe_list("[email protected]") | ||
assert SafeList.is_in_safe_list("[email protected]") | ||
request_json = json.dumps({"email": ["[email protected]"]}) | ||
add_response = client.post("/api/v2/safe_list", json=request_json, headers=headers) | ||
# 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 | ||
assert add_response.json == {} | ||
assert SafeList.is_in_safe_list("[email protected]") | ||
assert SafeList.is_in_safe_list("[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 safelist.is_in_safe_list("[email protected]") | ||
assert safelist.is_in_safe_list("[email protected]") |