mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-16 20:49:00 -04:00
Fixed linting and build errors
This commit is contained in:
@@ -202,7 +202,11 @@ def test_service_setting_link_toggles_index_error(
|
||||
("permissions", "permissions_text", "visible"),
|
||||
[
|
||||
("sms", "inbound SMS", True),
|
||||
(ServicePermission.INBOUND_SMS, "inbound SMS", False), # no sms parent permission
|
||||
(
|
||||
ServicePermission.INBOUND_SMS,
|
||||
"inbound SMS",
|
||||
False,
|
||||
), # no sms parent permission
|
||||
# also test no permissions set
|
||||
("", "inbound SMS", False),
|
||||
],
|
||||
|
||||
@@ -295,10 +295,12 @@ def test_download_links_show_when_data_available(
|
||||
mock_jobs_with_data = {
|
||||
"data": [{"id": "job1", "created_at": "2020-01-01T00:00:00.000000+00:00"}],
|
||||
"total": 1,
|
||||
"page_size": 50
|
||||
"page_size": 50,
|
||||
}
|
||||
|
||||
mocker.patch("app.job_api_client.get_page_of_jobs", return_value=mock_jobs_with_data)
|
||||
mocker.patch(
|
||||
"app.job_api_client.get_page_of_jobs", return_value=mock_jobs_with_data
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[{"id": "job1"}])
|
||||
|
||||
page = client_request.get(
|
||||
@@ -323,7 +325,7 @@ def test_download_links_partial_data_available(
|
||||
mock_jobs_with_data = {
|
||||
"data": [{"id": "job1", "created_at": "2020-01-01T00:00:00.000000+00:00"}],
|
||||
"total": 1,
|
||||
"page_size": 50
|
||||
"page_size": 50,
|
||||
}
|
||||
mock_jobs_empty = {"data": [], "total": 0, "page_size": 50}
|
||||
|
||||
@@ -332,7 +334,9 @@ def test_download_links_partial_data_available(
|
||||
return mock_jobs_with_data
|
||||
return mock_jobs_empty
|
||||
|
||||
mocker.patch("app.job_api_client.get_page_of_jobs", side_effect=mock_get_page_of_jobs)
|
||||
mocker.patch(
|
||||
"app.job_api_client.get_page_of_jobs", side_effect=mock_get_page_of_jobs
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[])
|
||||
|
||||
page = client_request.get(
|
||||
@@ -369,7 +373,10 @@ def test_download_links_no_data_available(
|
||||
assert "Download all data last 3 days" not in page.text
|
||||
assert "Download all data last 5 days" not in page.text
|
||||
assert "Download all data last 7 days" not in page.text
|
||||
assert "No recent activity to download. Download links will appear when jobs are available." in page.text
|
||||
assert (
|
||||
"No recent activity to download. Download links will appear when jobs are available."
|
||||
in page.text
|
||||
)
|
||||
|
||||
|
||||
def test_download_not_available_to_users_without_dashboard(
|
||||
@@ -560,9 +567,8 @@ def test_should_show_notifications_for_a_service_with_next_previous(
|
||||
):
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
return_value=notification_json(
|
||||
service_one["id"], rows=50, with_links=True
|
||||
) | {"total": 150},
|
||||
return_value=notification_json(service_one["id"], rows=50, with_links=True)
|
||||
| {"total": 150},
|
||||
)
|
||||
page = client_request.get(
|
||||
"main.view_notifications",
|
||||
@@ -608,9 +614,8 @@ def test_doesnt_show_next_button_on_last_page(
|
||||
):
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
return_value=notification_json(
|
||||
service_one["id"], rows=50, with_links=True
|
||||
) | {"total": 100},
|
||||
return_value=notification_json(service_one["id"], rows=50, with_links=True)
|
||||
| {"total": 100},
|
||||
)
|
||||
page = client_request.get(
|
||||
"main.view_notifications",
|
||||
@@ -637,9 +642,7 @@ def test_doesnt_show_pagination_when_50_or_fewer_items(
|
||||
):
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
return_value=notification_json(
|
||||
service_one["id"], rows=50, with_links=False
|
||||
),
|
||||
return_value=notification_json(service_one["id"], rows=50, with_links=False),
|
||||
)
|
||||
page = client_request.get(
|
||||
"main.view_notifications",
|
||||
@@ -663,9 +666,8 @@ def test_doesnt_show_pagination_with_search_term(
|
||||
):
|
||||
mocker.patch(
|
||||
"app.notification_api_client.get_notifications_for_service",
|
||||
return_value=notification_json(
|
||||
service_one["id"], rows=50, with_links=True
|
||||
) | {"total": 100},
|
||||
return_value=notification_json(service_one["id"], rows=50, with_links=True)
|
||||
| {"total": 100},
|
||||
)
|
||||
page = client_request.post(
|
||||
"main.view_notifications",
|
||||
|
||||
@@ -966,7 +966,7 @@ def test_menu_manage_service(
|
||||
ServicePermission.VIEW_ACTIVITY,
|
||||
ServicePermission.MANAGE_TEMPLATES,
|
||||
ServicePermission.MANAGE_USERS,
|
||||
ServicePermission.MANAGE_SETTINGS
|
||||
ServicePermission.MANAGE_SETTINGS,
|
||||
],
|
||||
)
|
||||
page = str(page)
|
||||
|
||||
@@ -50,9 +50,7 @@ def test_all_activity(
|
||||
mock_get_page_of_jobs = mocker.patch(
|
||||
"app.job_api_client.get_page_of_jobs", return_value=MOCK_JOBS
|
||||
)
|
||||
mocker.patch(
|
||||
"app.job_api_client.get_immediate_jobs", return_value=[]
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[])
|
||||
|
||||
response = client_request.get_response(
|
||||
"main.all_jobs_activity",
|
||||
@@ -65,7 +63,7 @@ def test_all_activity(
|
||||
assert "All activity" in response.text
|
||||
|
||||
assert any(
|
||||
call[0][0] == SERVICE_ONE_ID and call[1].get('page') == current_page
|
||||
call[0][0] == SERVICE_ONE_ID and call[1].get("page") == current_page
|
||||
for call in mock_get_page_of_jobs.call_args_list
|
||||
)
|
||||
page = BeautifulSoup(response.data, "html.parser")
|
||||
@@ -139,9 +137,7 @@ def test_all_activity_no_jobs(client_request, mocker):
|
||||
"total": 0,
|
||||
},
|
||||
)
|
||||
mocker.patch(
|
||||
"app.job_api_client.get_immediate_jobs", return_value=[]
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[])
|
||||
response = client_request.get_response(
|
||||
"main.all_jobs_activity",
|
||||
service_id=SERVICE_ONE_ID,
|
||||
@@ -162,7 +158,7 @@ def test_all_activity_no_jobs(client_request, mocker):
|
||||
expected_message == actual_message
|
||||
), f"Expected message '{expected_message}', but got '{actual_message}'"
|
||||
assert any(
|
||||
call[0][0] == SERVICE_ONE_ID and call[1].get('page') == current_page
|
||||
call[0][0] == SERVICE_ONE_ID and call[1].get("page") == current_page
|
||||
for call in mock_get_page_of_jobs.call_args_list
|
||||
)
|
||||
|
||||
@@ -194,9 +190,7 @@ def test_all_activity_pagination(client_request, mocker):
|
||||
"total": 100,
|
||||
},
|
||||
)
|
||||
mocker.patch(
|
||||
"app.job_api_client.get_immediate_jobs", return_value=[]
|
||||
)
|
||||
mocker.patch("app.job_api_client.get_immediate_jobs", return_value=[])
|
||||
|
||||
response = client_request.get_response(
|
||||
"main.all_jobs_activity",
|
||||
@@ -204,7 +198,7 @@ def test_all_activity_pagination(client_request, mocker):
|
||||
page=current_page,
|
||||
)
|
||||
assert any(
|
||||
call[0][0] == SERVICE_ONE_ID and call[1].get('page') == current_page
|
||||
call[0][0] == SERVICE_ONE_ID and call[1].get("page") == current_page
|
||||
for call in mock_get_page_of_jobs.call_args_list
|
||||
)
|
||||
|
||||
|
||||
@@ -1,45 +1,52 @@
|
||||
import pytest
|
||||
|
||||
|
||||
def test_csp_no_unsafe_eval(client_request, mocker, mock_get_service_and_organization_counts):
|
||||
def test_csp_no_unsafe_eval(
|
||||
client_request, mocker, mock_get_service_and_organization_counts
|
||||
):
|
||||
"""Check that unsafe-eval was removed from CSP"""
|
||||
mocker.patch("app.notify_client.user_api_client.UserApiClient.deactivate_user")
|
||||
client_request.logout()
|
||||
response = client_request.get_response('.index')
|
||||
csp = response.headers.get('Content-Security-Policy', '')
|
||||
response = client_request.get_response(".index")
|
||||
csp = response.headers.get("Content-Security-Policy", "")
|
||||
|
||||
assert "'unsafe-eval'" not in csp
|
||||
|
||||
|
||||
def test_no_duplicate_form_action(client_request, mocker, mock_get_service_and_organization_counts):
|
||||
def test_no_duplicate_form_action(
|
||||
client_request, mocker, mock_get_service_and_organization_counts
|
||||
):
|
||||
"""Check that form-action only appears once in CSP"""
|
||||
mocker.patch("app.notify_client.user_api_client.UserApiClient.deactivate_user")
|
||||
client_request.logout()
|
||||
response = client_request.get_response('.index')
|
||||
csp = response.headers.get('Content-Security-Policy', '')
|
||||
response = client_request.get_response(".index")
|
||||
csp = response.headers.get("Content-Security-Policy", "")
|
||||
|
||||
# Count how many times form-action appears
|
||||
count = csp.count('form-action')
|
||||
count = csp.count("form-action")
|
||||
assert count == 1
|
||||
|
||||
|
||||
def test_cross_origin_embedder_policy_set_to_credentialless(client_request, mocker, mock_get_service_and_organization_counts):
|
||||
def test_cross_origin_embedder_policy_set_to_credentialless(
|
||||
client_request, mocker, mock_get_service_and_organization_counts
|
||||
):
|
||||
"""Check that Cross-Origin-Embedder-Policy is set to 'credentialless' for YouTube compatibility"""
|
||||
mocker.patch("app.notify_client.user_api_client.UserApiClient.deactivate_user")
|
||||
client_request.logout()
|
||||
response = client_request.get_response('.index')
|
||||
response = client_request.get_response(".index")
|
||||
|
||||
assert response.headers.get('Cross-Origin-Embedder-Policy') == 'credentialless'
|
||||
assert response.headers.get("Cross-Origin-Embedder-Policy") == "credentialless"
|
||||
|
||||
|
||||
def test_permissions_policy_allows_youtube_features(client_request, mocker, mock_get_service_and_organization_counts):
|
||||
def test_permissions_policy_allows_youtube_features(
|
||||
client_request, mocker, mock_get_service_and_organization_counts
|
||||
):
|
||||
"""Check that Permissions-Policy allows necessary features for YouTube embeds"""
|
||||
mocker.patch("app.notify_client.user_api_client.UserApiClient.deactivate_user")
|
||||
client_request.logout()
|
||||
response = client_request.get_response('.index')
|
||||
response = client_request.get_response(".index")
|
||||
|
||||
permissions_policy = response.headers.get('Permissions-Policy', '')
|
||||
permissions_policy = response.headers.get("Permissions-Policy", "")
|
||||
|
||||
assert 'accelerometer=(self "https://www.youtube-nocookie.com")' in permissions_policy
|
||||
assert (
|
||||
'accelerometer=(self "https://www.youtube-nocookie.com")' in permissions_policy
|
||||
)
|
||||
assert 'autoplay=(self "https://www.youtube-nocookie.com")' in permissions_policy
|
||||
assert 'gyroscope=(self "https://www.youtube-nocookie.com")' in permissions_policy
|
||||
|
||||
@@ -36,7 +36,11 @@ def test_permissions(
|
||||
request.view_args.update({"service_id": "foo"})
|
||||
|
||||
api_user_active["permissions"] = {
|
||||
"foo": [ServicePermission.MANAGE_USERS, ServicePermission.MANAGE_TEMPLATES, ServicePermission.MANAGE_SETTINGS]
|
||||
"foo": [
|
||||
ServicePermission.MANAGE_USERS,
|
||||
ServicePermission.MANAGE_TEMPLATES,
|
||||
ServicePermission.MANAGE_SETTINGS,
|
||||
]
|
||||
}
|
||||
api_user_active["services"] = ["foo", "bar"]
|
||||
|
||||
@@ -66,7 +70,11 @@ def test_permissions_forbidden(
|
||||
request.view_args.update({"service_id": "foo"})
|
||||
|
||||
api_user_active["permissions"] = {
|
||||
"foo": [ServicePermission.MANAGE_USERS, ServicePermission.MANAGE_TEMPLATES, ServicePermission.MANAGE_SETTINGS]
|
||||
"foo": [
|
||||
ServicePermission.MANAGE_USERS,
|
||||
ServicePermission.MANAGE_TEMPLATES,
|
||||
ServicePermission.MANAGE_SETTINGS,
|
||||
]
|
||||
}
|
||||
api_user_active["services"] = ["foo", "bar"]
|
||||
|
||||
@@ -179,7 +187,11 @@ def test_user_with_no_permissions_to_service_goes_to_templates(
|
||||
api_user_active,
|
||||
):
|
||||
api_user_active["permissions"] = {
|
||||
"foo": [ServicePermission.MANAGE_USERS, ServicePermission.MANAGE_TEMPLATES, ServicePermission.MANAGE_SETTINGS]
|
||||
"foo": [
|
||||
ServicePermission.MANAGE_USERS,
|
||||
ServicePermission.MANAGE_TEMPLATES,
|
||||
ServicePermission.MANAGE_SETTINGS,
|
||||
]
|
||||
}
|
||||
api_user_active["services"] = ["foo", "bar"]
|
||||
client_request.login(api_user_active)
|
||||
|
||||
Reference in New Issue
Block a user