diff --git a/poetry.lock b/poetry.lock index 522229a50..97821005f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1278,6 +1278,7 @@ files = [ {file = "lxml-5.2.1-cp36-cp36m-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c38d7b9a690b090de999835f0443d8aa93ce5f2064035dfc48f27f02b4afc3d0"}, {file = "lxml-5.2.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5670fb70a828663cc37552a2a85bf2ac38475572b0e9b91283dc09efb52c41d1"}, {file = "lxml-5.2.1-cp36-cp36m-manylinux_2_28_x86_64.whl", hash = "sha256:958244ad566c3ffc385f47dddde4145088a0ab893504b54b52c041987a8c1863"}, + {file = "lxml-5.2.1-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:b6241d4eee5f89453307c2f2bfa03b50362052ca0af1efecf9fef9a41a22bb4f"}, {file = "lxml-5.2.1-cp36-cp36m-musllinux_1_1_aarch64.whl", hash = "sha256:2a66bf12fbd4666dd023b6f51223aed3d9f3b40fef06ce404cb75bafd3d89536"}, {file = "lxml-5.2.1-cp36-cp36m-musllinux_1_1_ppc64le.whl", hash = "sha256:9123716666e25b7b71c4e1789ec829ed18663152008b58544d95b008ed9e21e9"}, {file = "lxml-5.2.1-cp36-cp36m-musllinux_1_1_s390x.whl", hash = "sha256:0c3f67e2aeda739d1cc0b1102c9a9129f7dc83901226cc24dd72ba275ced4218"}, @@ -1594,6 +1595,7 @@ files = [ {file = "msgpack-1.0.8-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:5fbb160554e319f7b22ecf530a80a3ff496d38e8e07ae763b9e82fadfe96f273"}, {file = "msgpack-1.0.8-cp39-cp39-win32.whl", hash = "sha256:f9af38a89b6a5c04b7d18c492c8ccf2aee7048aff1ce8437c4683bb5a1df893d"}, {file = "msgpack-1.0.8-cp39-cp39-win_amd64.whl", hash = "sha256:ed59dd52075f8fc91da6053b12e8c89e37aa043f8986efd89e61fae69dc1b011"}, + {file = "msgpack-1.0.8-py3-none-any.whl", hash = "sha256:24f727df1e20b9876fa6e95f840a2a2651e34c0ad147676356f4bf5fbb0206ca"}, {file = "msgpack-1.0.8.tar.gz", hash = "sha256:95c02b0e27e706e48d0e5426d1710ca78e0f0628d6e89d5b5a5b91a5f12274f3"}, ] diff --git a/tests/notifications_utils/clients/redis/test_redis_client.py b/tests/notifications_utils/clients/redis/test_redis_client.py index 1f122206b..31ea2330a 100644 --- a/tests/notifications_utils/clients/redis/test_redis_client.py +++ b/tests/notifications_utils/clients/redis/test_redis_client.py @@ -8,17 +8,17 @@ from freezegun import freeze_time from notifications_utils.clients.redis.redis_client import RedisClient, prepare_value -@pytest.fixture(scope="function") +@pytest.fixture() def mocked_redis_pipeline(): return Mock() -@pytest.fixture +@pytest.fixture() def delete_mock(): return Mock(return_value=4) -@pytest.fixture(scope="function") +@pytest.fixture() def mocked_redis_client(app, mocked_redis_pipeline, delete_mock, mocker): app.config["REDIS_ENABLED"] = True @@ -46,14 +46,16 @@ def mocked_redis_client(app, mocked_redis_pipeline, delete_mock, mocker): return redis_client -@pytest.fixture +@pytest.fixture() def failing_redis_client(mocked_redis_client, delete_mock): - mocked_redis_client.redis_store.get.side_effect = Exception("get failed") - mocked_redis_client.redis_store.set.side_effect = Exception("set failed") - mocked_redis_client.redis_store.incr.side_effect = Exception("incr failed") - mocked_redis_client.redis_store.pipeline.side_effect = Exception("pipeline failed") - mocked_redis_client.redis_store.delete.side_effect = Exception("delete failed") - delete_mock.side_effect = Exception("delete by pattern failed") + # nota bene: using KeyError because flake8 thinks Exception + # and BaseException are too broad + mocked_redis_client.redis_store.get.side_effect = KeyError("get failed") + mocked_redis_client.redis_store.set.side_effect = KeyError("set failed") + mocked_redis_client.redis_store.incr.side_effect = KeyError("incr failed") + mocked_redis_client.redis_store.pipeline.side_effect = KeyError("pipeline failed") + mocked_redis_client.redis_store.delete.side_effect = KeyError("delete failed") + delete_mock.side_effect = KeyError("delete by pattern failed") return mocked_redis_client @@ -85,27 +87,27 @@ def test_should_raise_exception_if_raise_set_to_true( app, failing_redis_client, ): - with pytest.raises(Exception) as e: + with pytest.raises(KeyError) as e: failing_redis_client.get("test", raise_exception=True) assert str(e.value) == "get failed" - with pytest.raises(Exception) as e: + with pytest.raises(KeyError) as e: failing_redis_client.set("test", "test", raise_exception=True) assert str(e.value) == "set failed" - with pytest.raises(Exception) as e: + with pytest.raises(KeyError) as e: failing_redis_client.incr("test", raise_exception=True) assert str(e.value) == "incr failed" - with pytest.raises(Exception) as e: + with pytest.raises(KeyError) as e: failing_redis_client.exceeded_rate_limit("test", 100, 200, raise_exception=True) assert str(e.value) == "pipeline failed" - with pytest.raises(Exception) as e: + with pytest.raises(KeyError) as e: failing_redis_client.delete("test", raise_exception=True) assert str(e.value) == "delete failed" - with pytest.raises(Exception) as e: + with pytest.raises(KeyError) as e: failing_redis_client.delete_by_pattern("pattern", raise_exception=True) assert str(e.value) == "delete by pattern failed" diff --git a/tests/notifications_utils/test_template_types.py b/tests/notifications_utils/test_template_types.py index 1209d4dc9..0a329aca2 100644 --- a/tests/notifications_utils/test_template_types.py +++ b/tests/notifications_utils/test_template_types.py @@ -1044,7 +1044,7 @@ def test_letter_preview_renderer_without_mocks(jinja_template): @freeze_time("2012-12-12 12:12:12") @mock.patch("notifications_utils.template.LetterImageTemplate.jinja_template.render") @pytest.mark.parametrize( - "page_count, expected_oversized, expected_page_numbers", + ("page_count, expected_oversized, expected_page_numbers"), [ ( 1, @@ -1581,7 +1581,7 @@ def test_sms_fragment_count_accounts_for_unicode_and_welsh_characters( ), ) @pytest.mark.parametrize( - "msg, expected_sms_fragment_count", + ("msg", "expected_sms_fragment_count"), [ # all extended GSM characters ( @@ -1647,7 +1647,7 @@ def test_sms_fragment_count_accounts_for_non_latin_characters( ], ) @pytest.mark.parametrize( - "content, values, prefix, expected_result", + ("content", "values", "prefix", "expected_result"), [ ("", {}, None, True), ("", {}, "GDS", True), @@ -1676,7 +1676,7 @@ def test_is_message_empty_sms_templates( ], ) @pytest.mark.parametrize( - "content, values, expected_result", + ("content", "values", "expected_result"), [ ("", {}, True), ("((placeholder))", {"placeholder": ""}, True), @@ -1696,14 +1696,14 @@ def test_is_message_empty_broadcast_templates( @pytest.mark.parametrize( - "template_class, template_type", + ("template_class", "template_type"), ( (HTMLEmailTemplate, "email"), (LetterPrintTemplate, "letter"), ), ) @pytest.mark.parametrize( - "content, values, expected_result", + ("content", "values", "expected_result"), [ ("", {}, True), ("((placeholder))", {"placeholder": ""}, True), @@ -1742,7 +1742,7 @@ def test_is_message_empty_email_and_letter_templates( ), ) @pytest.mark.parametrize( - "content, values", + ("content", "values"), [ ("Some content", {}), ("((placeholder)) some content", {"placeholder": ""}), @@ -1781,7 +1781,7 @@ def test_is_message_empty_email_and_letter_templates_tries_not_to_count_chars( @pytest.mark.parametrize( - "template_class, template_type, extra_args, expected_field_calls", + ("template_class", "template_type", "extra_args", "expected_field_calls"), [ ( PlainTextEmailTemplate, @@ -2054,7 +2054,7 @@ def test_templates_handle_html_and_redacting( @pytest.mark.parametrize( - "template_class, template_type, extra_args, expected_remove_whitespace_calls", + ("template_class", "template_type", "extra_args", "expected_remove_whitespace_calls"), [ ( PlainTextEmailTemplate, @@ -2176,7 +2176,7 @@ def test_templates_remove_whitespace_before_punctuation( @pytest.mark.parametrize( - "template_class, template_type, extra_args, expected_calls", + ("template_class", "template_type", "extra_args", "expected_calls"), [ ( PlainTextEmailTemplate, @@ -2302,7 +2302,7 @@ def test_smart_quotes_removed_from_long_template_in_under_a_second(): @pytest.mark.parametrize( - "template_instance, expected_placeholders", + ("template_instance", "expected_placeholders"), [ ( SMSMessageTemplate( @@ -2465,7 +2465,7 @@ def test_email_preview_shows_reply_to_address(extra_args): @pytest.mark.parametrize( - "template_values, expected_content", + ("template_values", "expected_content"), [ ({}, "email address"), ({"email address": "test@example.com"}, "test@example.com"), @@ -2483,7 +2483,7 @@ def test_email_preview_shows_recipient_address( @pytest.mark.parametrize( - "address, expected", + ("address", "expected"), [ ( { @@ -2585,7 +2585,7 @@ def test_email_preview_shows_recipient_address( ), ], ) -@pytest.mark.parametrize("template_class", (LetterPreviewTemplate, LetterPrintTemplate)) +@pytest.mark.parametrize("template_class", [LetterPreviewTemplate, LetterPrintTemplate]) def test_letter_address_format(template_class, address, expected): template = BeautifulSoup( str( @@ -2601,7 +2601,7 @@ def test_letter_address_format(template_class, address, expected): @freeze_time("2001-01-01 12:00:00.000000") @pytest.mark.parametrize( - "markdown, expected", + ("markdown", "expected"), [ ( ( @@ -2691,11 +2691,11 @@ def test_message_is_not_too_long_ignoring_prefix(template_class): @pytest.mark.parametrize( - "extra_characters, expected_too_long", - ( + ("extra_characters", "expected_too_long"), + [ ("cc", True), # content length is 919 characters (more than limit of 918) ("c", False), # content length is 918 characters (not more than limit of 918) - ), + ], ) @pytest.mark.parametrize( "template_class", @@ -2716,7 +2716,7 @@ def test_broadcast_message_too_long( @pytest.mark.parametrize( - "template_class, template_type, kwargs", + ("template_class", "template_type", "kwargs"), [ (EmailPreviewTemplate, "email", {}), (HTMLEmailTemplate, "email", {}), @@ -2736,7 +2736,7 @@ def test_message_too_long_limit_bigger_or_nonexistent_for_non_sms_templates( @pytest.mark.parametrize( - "template_class, template_type, kwargs", + ("template_class", "template_type", "kwargs"), [ (EmailPreviewTemplate, "email", {}), (HTMLEmailTemplate, "email", {}), @@ -2755,7 +2755,7 @@ def test_content_size_in_bytes_for_email_messages( @pytest.mark.parametrize( - "template_class, template_type, kwargs", + ("template_class", "template_type", "kwargs"), [ (EmailPreviewTemplate, "email", {}), (HTMLEmailTemplate, "email", {}), @@ -2774,7 +2774,7 @@ def test_message_too_long_for_a_too_big_email_message( @pytest.mark.parametrize( - "template_class, template_type, kwargs", + ("template_class", "template_type", "kwargs"), [ (EmailPreviewTemplate, "email", {}), (HTMLEmailTemplate, "email", {}), @@ -2792,7 +2792,7 @@ def test_message_too_long_for_an_email_message_within_limits( @pytest.mark.parametrize( - ("content," "expected_preview_markup,"), + ("content", "expected_preview_markup"), [ ( "a\n\n\nb", @@ -2847,7 +2847,7 @@ def test_multiple_newlines_in_letters( ], ) @pytest.mark.parametrize( - "template_class, template_type, extra_args", + ("template_class", "template_type", "extra_args"), [ (PlainTextEmailTemplate, "email", {}), (HTMLEmailTemplate, "email", {}), @@ -2886,7 +2886,7 @@ def test_whitespace_in_subject_placeholders(template_class): @pytest.mark.parametrize( - "template_class, expected_output", + ("template_class", "expected_output"), [ ( PlainTextEmailTemplate, @@ -3041,8 +3041,8 @@ def test_plain_text_email_whitespace(): @pytest.mark.parametrize( - "renderer, template_type, expected_content", - ( + ("renderer", "template_type", "expected_content"), + [ ( PlainTextEmailTemplate, "email", @@ -3071,7 +3071,7 @@ def test_plain_text_email_whitespace(): "letter", ("