-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
162 additions
and
45 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
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,20 @@ | ||
from flask import current_app | ||
|
||
from app.notify_client import NotifyAdminAPIClient | ||
|
||
|
||
class SupportApiClient(NotifyAdminAPIClient): | ||
def init_app(self, app): | ||
super().init_app(app) | ||
self.admin_url = app.config["ADMIN_BASE_URL"] | ||
self.contact_email = app.config["CONTACT_EMAIL"] | ||
self.notify_user_id = app.config["NOTIFY_USER_ID"] | ||
self.notify_service_id = app.config["NOTIFY_SERVICE_ID"] | ||
|
||
def find_ids(self, ids): | ||
data = self.get("/support/find-ids", params={"ids": ids}) | ||
current_app.logger.info(f"-----------\n {data}") | ||
return data | ||
|
||
|
||
support_api_client = SupportApiClient() |
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,115 @@ | ||
def test_find_ids_page_loads_correctly(client_request, platform_admin_user): | ||
client_request.login(platform_admin_user) | ||
document = client_request.get("main.find_ids") | ||
|
||
assert document.h1.text.strip() == "Search for ids" | ||
assert len(document.find_all("input", {"type": "search"})) > 0 | ||
|
||
|
||
def test_find_ids_displays_services_found(client_request, platform_admin_user, mocker): | ||
client_request.login(platform_admin_user) | ||
get_records = mocker.patch( | ||
"app.support_api_client.find_ids", | ||
return_value=[{"id": "1234", "type": "service", "service_name": "Test Service"}], | ||
) | ||
document = client_request.post( | ||
"main.find_ids", | ||
_data={"search": "1234"}, | ||
_expected_status=200, | ||
) | ||
get_records.assert_called_once_with("1234") | ||
result = document.find("a", {"class": "browse-list-link"}) | ||
assert result.text.strip() == "Test Service" | ||
assert result.attrs["href"] == "/services/1234" | ||
|
||
|
||
def test_find_ids_displays_notifications_found(client_request, platform_admin_user, mocker): | ||
client_request.login(platform_admin_user) | ||
get_records = mocker.patch( | ||
"app.support_api_client.find_ids", | ||
return_value=[{"id": "1234", "type": "notification", "service_id": "service_1234"}], | ||
) | ||
document = client_request.post( | ||
"main.find_ids", | ||
_data={"search": "1234"}, | ||
_expected_status=200, | ||
) | ||
get_records.assert_called_once_with("1234") | ||
result = document.find("a", {"class": "browse-list-link"}) | ||
assert result.text.strip() == "notification" | ||
assert result.attrs["href"] == "/services/service_1234/notification/1234" | ||
|
||
|
||
def test_find_ids_displays_templates_found(client_request, platform_admin_user, mocker): | ||
client_request.login(platform_admin_user) | ||
get_records = mocker.patch( | ||
"app.support_api_client.find_ids", | ||
return_value=[{"id": "1234", "type": "template", "template_name": "Test Template", "service_id": "service_1234"}], | ||
) | ||
document = client_request.post( | ||
"main.find_ids", | ||
_data={"search": "1234"}, | ||
_expected_status=200, | ||
) | ||
get_records.assert_called_once_with("1234") | ||
result = document.find("a", {"class": "browse-list-link"}) | ||
assert result.text.strip() == "Test Template" | ||
assert result.attrs["href"] == "/services/service_1234/templates/1234" | ||
|
||
|
||
def test_find_ids_displays_users_found(client_request, platform_admin_user, mocker): | ||
client_request.login(platform_admin_user) | ||
get_records = mocker.patch( | ||
"app.support_api_client.find_ids", | ||
return_value=[{"id": "1234", "type": "user", "user_name": "Test User"}], | ||
) | ||
document = client_request.post( | ||
"main.find_ids", | ||
_data={"search": "1234"}, | ||
_expected_status=200, | ||
) | ||
get_records.assert_called_once_with("1234") | ||
result = document.find("a", {"class": "browse-list-link"}) | ||
|
||
assert result.text.strip() == "Test User" | ||
assert result.attrs["href"] == "/users/1234" | ||
|
||
|
||
def test_find_ids_displays_jobs_found(client_request, platform_admin_user, mocker): | ||
client_request.login(platform_admin_user) | ||
get_records = mocker.patch( | ||
"app.support_api_client.find_ids", | ||
return_value=[{"id": "1234", "type": "job", "service_id": "service_1234"}], | ||
) | ||
document = client_request.post( | ||
"main.find_ids", | ||
_data={"search": "1234"}, | ||
_expected_status=200, | ||
) | ||
get_records.assert_called_once_with("1234") | ||
result = document.find("a", {"class": "browse-list-link"}) | ||
assert result.text.strip() == "job" | ||
assert result.attrs["href"] == "/services/service_1234/jobs/1234" | ||
|
||
|
||
def test_find_ids_display_two_records(client_request, platform_admin_user, mocker): | ||
client_request.login(platform_admin_user) | ||
get_records = mocker.patch( | ||
"app.support_api_client.find_ids", | ||
return_value=[ | ||
{"id": "1234", "type": "service", "service_name": "Test Service"}, | ||
{"id": "5678", "type": "user", "user_name": "Test User"}, | ||
], | ||
) | ||
document = client_request.post("main.find_ids", _data={"search": "1234,5678"}, _expected_status=200) | ||
get_records.assert_called_once_with("1234,5678") | ||
results = document.findAll("a", {"class": "browse-list-link"}) | ||
assert len(results) == 2 | ||
assert [result.text.strip() for result in results] == [ | ||
"Test Service", | ||
"Test User", | ||
] | ||
assert [result.attrs["href"] for result in results] == [ | ||
"/services/1234", | ||
"/users/5678", | ||
] |