mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
change to actually downloading file
This commit is contained in:
@@ -318,6 +318,9 @@ def test_should_send_sms_with_downgraded_content(notify_db_session, mocker):
|
||||
# é, o, and u are in GSM.
|
||||
# ī, grapes, tabs, zero width space and ellipsis are not
|
||||
# ó isn't in GSM, but it is in the welsh alphabet so will still be sent
|
||||
mocker.patch(
|
||||
"app.delivery.send_to_providers.get_sender_numbers", return_value=["testing"]
|
||||
)
|
||||
msg = "a é ī o u 🍇 foo\tbar\u200bbaz((misc))…"
|
||||
placeholder = "∆∆∆abc"
|
||||
gsm_message = "?ódz Housing Service: a é i o u ? foo barbaz???abc..."
|
||||
@@ -327,6 +330,7 @@ def test_should_send_sms_with_downgraded_content(notify_db_session, mocker):
|
||||
template=template,
|
||||
)
|
||||
db_notification.personalisation = {"misc": placeholder}
|
||||
db_notification.reply_to_text = "testing"
|
||||
|
||||
mocker.patch("app.aws_sns_client.send_sms")
|
||||
|
||||
@@ -609,11 +613,16 @@ def __update_notification(notification_to_update, research_mode, expected_status
|
||||
def test_should_update_billable_units_and_status_according_to_research_mode_and_key_type(
|
||||
sample_template, mocker, research_mode, key_type, billable_units, expected_status
|
||||
):
|
||||
|
||||
mocker.patch(
|
||||
"app.delivery.send_to_providers.get_sender_numbers", return_value=["testing"]
|
||||
)
|
||||
notification = create_notification(
|
||||
template=sample_template,
|
||||
billable_units=0,
|
||||
status=NotificationStatus.CREATED,
|
||||
key_type=key_type,
|
||||
reply_to_text="testing",
|
||||
)
|
||||
mocker.patch("app.aws_sns_client.send_sms")
|
||||
mocker.patch(
|
||||
@@ -771,9 +780,16 @@ def test_send_email_to_provider_uses_reply_to_from_notification(
|
||||
|
||||
|
||||
def test_send_sms_to_provider_should_use_normalised_to(mocker, client, sample_template):
|
||||
|
||||
mocker.patch(
|
||||
"app.delivery.send_to_providers.get_sender_numbers", return_value=["testing"]
|
||||
)
|
||||
send_mock = mocker.patch("app.aws_sns_client.send_sms")
|
||||
notification = create_notification(
|
||||
template=sample_template, to_field="+12028675309", normalised_to="2028675309"
|
||||
template=sample_template,
|
||||
to_field="+12028675309",
|
||||
normalised_to="2028675309",
|
||||
reply_to_text="testing",
|
||||
)
|
||||
|
||||
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
|
||||
@@ -826,6 +842,10 @@ def test_send_email_to_provider_should_user_normalised_to(
|
||||
def test_send_sms_to_provider_should_return_template_if_found_in_redis(
|
||||
mocker, client, sample_template
|
||||
):
|
||||
|
||||
mocker.patch(
|
||||
"app.delivery.send_to_providers.get_sender_numbers", return_value=["testing"]
|
||||
)
|
||||
from app.schemas import service_schema, template_schema
|
||||
|
||||
service_dict = service_schema.dump(sample_template.service)
|
||||
@@ -845,7 +865,10 @@ def test_send_sms_to_provider_should_return_template_if_found_in_redis(
|
||||
|
||||
send_mock = mocker.patch("app.aws_sns_client.send_sms")
|
||||
notification = create_notification(
|
||||
template=sample_template, to_field="+447700900855", normalised_to="447700900855"
|
||||
template=sample_template,
|
||||
to_field="+447700900855",
|
||||
normalised_to="447700900855",
|
||||
reply_to_text="testing",
|
||||
)
|
||||
|
||||
mock_s3 = mocker.patch("app.delivery.send_to_providers.get_phone_number_from_s3")
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
from app.errors import VirusScanError
|
||||
|
||||
|
||||
def test_virus_scan_error():
|
||||
vse = VirusScanError("a message")
|
||||
assert "a message" in vse.args
|
||||
@@ -1,4 +1,3 @@
|
||||
import uuid
|
||||
from datetime import date, datetime
|
||||
|
||||
import pytest
|
||||
@@ -6,12 +5,8 @@ from freezegun import freeze_time
|
||||
|
||||
from app.enums import ServicePermissionType
|
||||
from app.utils import (
|
||||
format_sequential_number,
|
||||
get_midnight_for_day_before,
|
||||
get_midnight_in_utc,
|
||||
get_public_notify_type_text,
|
||||
get_reference_from_personalisation,
|
||||
get_uuid_string_or_none,
|
||||
midnight_n_days_ago,
|
||||
)
|
||||
|
||||
@@ -31,18 +26,6 @@ def test_get_midnight_in_utc_returns_expected_date(date, expected_date):
|
||||
assert get_midnight_in_utc(date) == expected_date
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"date, expected_date",
|
||||
[
|
||||
(datetime(2016, 1, 15, 0, 30), datetime(2016, 1, 14, 0, 0)),
|
||||
(datetime(2016, 7, 15, 0, 0), datetime(2016, 7, 14, 0, 0)),
|
||||
(datetime(2016, 8, 23, 11, 59), datetime(2016, 8, 22, 0, 0)),
|
||||
],
|
||||
)
|
||||
def test_get_midnight_for_day_before_returns_expected_date(date, expected_date):
|
||||
assert get_midnight_for_day_before(date) == expected_date
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"current_time, arg, expected_datetime",
|
||||
[
|
||||
@@ -65,40 +48,7 @@ def test_midnight_n_days_ago(current_time, arg, expected_datetime):
|
||||
assert midnight_n_days_ago(arg) == expected_datetime
|
||||
|
||||
|
||||
def test_format_sequential_number():
|
||||
assert format_sequential_number(123) == "0000007b"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"personalisation, expected_response",
|
||||
[
|
||||
({"nothing": "interesting"}, None),
|
||||
({"reference": "something"}, "something"),
|
||||
(None, None),
|
||||
],
|
||||
)
|
||||
def test_get_reference_from_personalisation(personalisation, expected_response):
|
||||
assert get_reference_from_personalisation(personalisation) == expected_response
|
||||
|
||||
|
||||
def test_get_uuid_string_or_none():
|
||||
my_uuid = uuid.uuid4()
|
||||
assert str(my_uuid) == get_uuid_string_or_none(my_uuid)
|
||||
|
||||
assert get_uuid_string_or_none(None) is None
|
||||
|
||||
|
||||
def test_get_public_notify_type_text():
|
||||
assert (
|
||||
get_public_notify_type_text(ServicePermissionType.UPLOAD_DOCUMENT) == "document"
|
||||
)
|
||||
|
||||
|
||||
# This method is used for simulating bulk sends. We use localstack and run on a developer's machine to do the
|
||||
# simulation. Please see docs->bulk_testing.md for instructions.
|
||||
# def test_generate_csv_for_bulk_testing():
|
||||
# f = open("bulktest_100000.csv", "w")
|
||||
# f.write("phone number\n")
|
||||
# for _ in range(0, 100000):
|
||||
# f.write("16615555555\n")
|
||||
# f.close()
|
||||
|
||||
@@ -632,137 +632,6 @@ def test_remove_user_folder_permissions(admin_request, sample_user, sample_servi
|
||||
assert service_user.folders == []
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
def test_send_user_reset_password_should_send_reset_password_link(
|
||||
admin_request, sample_user, mocker, password_reset_email_template
|
||||
):
|
||||
mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
data = {"email": sample_user.email_address}
|
||||
notify_service = password_reset_email_template.service
|
||||
|
||||
admin_request.post(
|
||||
"user.send_user_reset_password",
|
||||
_data=data,
|
||||
_expected_status=204,
|
||||
)
|
||||
|
||||
notification = Notification.query.first()
|
||||
mocked.assert_called_once_with(
|
||||
[str(notification.id)], queue="notify-internal-tasks"
|
||||
)
|
||||
assert (
|
||||
notification.reply_to_text
|
||||
== notify_service.get_default_reply_to_email_address()
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"data, expected_url",
|
||||
(
|
||||
(
|
||||
{
|
||||
"email": "notify@digital.fake.gov",
|
||||
},
|
||||
("http://localhost:6012/new-password/"),
|
||||
),
|
||||
(
|
||||
{
|
||||
"email": "notify@digital.fake.gov",
|
||||
"admin_base_url": "https://different.example.com",
|
||||
},
|
||||
("https://different.example.com/new-password/"),
|
||||
),
|
||||
),
|
||||
)
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
def test_send_user_reset_password_should_use_provided_base_url(
|
||||
admin_request,
|
||||
sample_user,
|
||||
password_reset_email_template,
|
||||
mocker,
|
||||
data,
|
||||
expected_url,
|
||||
):
|
||||
mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
|
||||
admin_request.post(
|
||||
"user.send_user_reset_password",
|
||||
_data=data,
|
||||
_expected_status=204,
|
||||
)
|
||||
|
||||
assert Notification.query.first().personalisation["url"].startswith(expected_url)
|
||||
|
||||
|
||||
@freeze_time("2016-01-01 11:09:00.061258")
|
||||
def test_send_user_reset_password_reset_password_link_contains_redirect_link_if_present_in_request(
|
||||
admin_request, sample_user, mocker, password_reset_email_template
|
||||
):
|
||||
mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
data = {"email": sample_user.email_address, "next": "blob"}
|
||||
|
||||
admin_request.post(
|
||||
"user.send_user_reset_password",
|
||||
_data=data,
|
||||
_expected_status=204,
|
||||
)
|
||||
|
||||
notification = Notification.query.first()
|
||||
assert "?next=blob" in notification.content
|
||||
mocked.assert_called_once_with(
|
||||
[str(notification.id)], queue="notify-internal-tasks"
|
||||
)
|
||||
|
||||
|
||||
def test_send_user_reset_password_should_return_400_when_email_is_missing(
|
||||
admin_request, mocker
|
||||
):
|
||||
mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
data = {}
|
||||
|
||||
json_resp = admin_request.post(
|
||||
"user.send_user_reset_password",
|
||||
_data=data,
|
||||
_expected_status=400,
|
||||
)
|
||||
assert json_resp["message"] == {"email": ["Missing data for required field."]}
|
||||
assert mocked.call_count == 0
|
||||
|
||||
|
||||
def test_send_user_reset_password_should_return_400_when_user_doesnot_exist(
|
||||
admin_request, mocker
|
||||
):
|
||||
mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
bad_email_address = "bad@email.gov.uk"
|
||||
data = {"email": bad_email_address}
|
||||
|
||||
json_resp = admin_request.post(
|
||||
"user.send_user_reset_password",
|
||||
_data=data,
|
||||
_expected_status=404,
|
||||
)
|
||||
|
||||
assert json_resp["message"] == "No result found"
|
||||
assert mocked.call_count == 0
|
||||
|
||||
|
||||
def test_send_user_reset_password_should_return_400_when_data_is_not_email_address(
|
||||
admin_request, mocker
|
||||
):
|
||||
mocked = mocker.patch("app.celery.provider_tasks.deliver_email.apply_async")
|
||||
bad_email_address = "bad.email.gov.uk"
|
||||
data = {"email": bad_email_address}
|
||||
|
||||
json_resp = admin_request.post(
|
||||
"user.send_user_reset_password",
|
||||
_data=data,
|
||||
_expected_status=400,
|
||||
)
|
||||
|
||||
assert json_resp["message"] == {"email": ["Not a valid email address"]}
|
||||
assert mocked.call_count == 0
|
||||
|
||||
|
||||
def test_send_already_registered_email(
|
||||
admin_request, sample_user, already_registered_template, mocker
|
||||
):
|
||||
@@ -842,27 +711,6 @@ def test_send_user_confirm_new_email_returns_400_when_email_missing(
|
||||
mocked.assert_not_called()
|
||||
|
||||
|
||||
@freeze_time("2020-02-14T12:00:00")
|
||||
def test_update_user_password_saves_correctly(admin_request, sample_service):
|
||||
sample_user = sample_service.users[0]
|
||||
new_password = "1234567890"
|
||||
data = {"_password": "1234567890"}
|
||||
|
||||
json_resp = admin_request.post(
|
||||
"user.update_password", user_id=str(sample_user.id), _data=data
|
||||
)
|
||||
|
||||
assert json_resp["data"]["password_changed_at"] is not None
|
||||
data = {"password": new_password}
|
||||
|
||||
admin_request.post(
|
||||
"user.verify_user_password",
|
||||
user_id=str(sample_user.id),
|
||||
_data=data,
|
||||
_expected_status=204,
|
||||
)
|
||||
|
||||
|
||||
def test_activate_user(admin_request, sample_user):
|
||||
sample_user.state = "pending"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user