From 6940ea5f0d14dc324dfad469eef09b54ce8dd574 Mon Sep 17 00:00:00 2001 From: John Tordoff Date: Mon, 3 Nov 2025 12:44:03 -0500 Subject: [PATCH 1/2] use allow_none=True argument to clean-up test case code --- tests/test_registrations/test_review_flows.py | 40 ++++--------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/tests/test_registrations/test_review_flows.py b/tests/test_registrations/test_review_flows.py index 9f6c4306cfd..20dc535e8c0 100644 --- a/tests/test_registrations/test_review_flows.py +++ b/tests/test_registrations/test_review_flows.py @@ -1,5 +1,4 @@ import pytest -import pytest_socket from api.providers.workflows import Workflows from framework.exceptions import PermissionsError @@ -98,11 +97,8 @@ def test_approval_flow(self, sanction_object, initial_state, end_state): assert registration.sanction._id == sanction_object._id approval_token = sanction_object.token_for_user(registration.creator, 'approval') - try: + with capture_notifications(allow_none=True): sanction_object.approve(user=registration.creator, token=approval_token) - except pytest_socket.SocketConnectBlockedError: - with capture_notifications(): - sanction_object.approve(user=registration.creator, token=approval_token) registration.refresh_from_db() assert registration.moderation_state == end_state.db_name @@ -137,11 +133,8 @@ def test_rejection_flow(self, sanction_object, initial_state, end_state): assert registration.sanction._id == sanction_object._id rejection_token = sanction_object.token_for_user(registration.creator, 'rejection') - try: + with capture_notifications(allow_none=True): sanction_object.reject(user=registration.creator, token=rejection_token) - except pytest_socket.SocketConnectBlockedError: - with capture_notifications(): - sanction_object.reject(user=registration.creator, token=rejection_token) assert sum([val['has_rejected'] for val in sanction_object.approval_state.values()]) == 1 registration.refresh_from_db() @@ -266,10 +259,7 @@ def test_approval_flow( registration.refresh_from_db() assert registration.moderation_state == intermediate_state.db_name - try: - with capture_notifications(): - sanction_object.accept(user=moderator) - except AssertionError: + with capture_notifications(allow_none=True): sanction_object.accept(user=moderator) registration.refresh_from_db() @@ -347,10 +337,7 @@ def test_moderator_rejection_flow( registration.refresh_from_db() assert registration.moderation_state == intermediate_state.db_name - try: - with capture_notifications(): - sanction_object.reject(user=moderator) - except AssertionError: + with capture_notifications(allow_none=True): sanction_object.reject(user=moderator) registration.refresh_from_db() @@ -540,18 +527,12 @@ def test_moderator_approve_after_rejected_raises_machine_error( def test_provider_admin_can_accept_as_moderator( self, sanction_object, provider, provider_admin): sanction_object = sanction_object(provider) - try: - with capture_notifications(): - sanction_object.accept() - except AssertionError: + with capture_notifications(allow_none=True): sanction_object.accept() assert sanction_object.approval_stage is ApprovalStates.PENDING_MODERATION - try: - with capture_notifications(): - sanction_object.accept(user=provider_admin) - except AssertionError: + with capture_notifications(allow_none=True): sanction_object.accept(user=provider_admin) assert sanction_object.approval_stage is ApprovalStates.APPROVED @@ -560,9 +541,7 @@ def test_provider_admin_can_reject_as_moderator( self, sanction_object, provider, provider_admin): sanction_object = sanction_object(provider) if sanction_object in (embargo, registration_approval): - sanction_object.accept() - else: - with capture_notifications(): + with capture_notifications(allow_none=True): sanction_object.accept() assert sanction_object.approval_stage is ApprovalStates.PENDING_MODERATION @@ -844,11 +823,8 @@ def test_approval(self, pending_registration, child_registration, grandchild_reg assert child_registration.moderation_state == pending_registration.moderation_state assert grandchild_registration.moderation_state == pending_registration.moderation_state - try: + with capture_notifications(allow_none=True): pending_registration.sanction.accept() - except pytest_socket.SocketConnectBlockedError: - with capture_notifications(): - pending_registration.sanction.accept() # verify that all registrations have updated state for reg in [pending_registration, child_registration, grandchild_registration]: From 4108b69e8bb49d83238cbd046bbf7693aabf37b1 Mon Sep 17 00:00:00 2001 From: John Tordoff Date: Mon, 3 Nov 2025 16:28:02 -0500 Subject: [PATCH 2/2] revert notifications capture blocking sanctions accepting/rejecting --- tests/test_registrations/test_review_flows.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_registrations/test_review_flows.py b/tests/test_registrations/test_review_flows.py index 20dc535e8c0..f12aaec4cc3 100644 --- a/tests/test_registrations/test_review_flows.py +++ b/tests/test_registrations/test_review_flows.py @@ -527,12 +527,18 @@ def test_moderator_approve_after_rejected_raises_machine_error( def test_provider_admin_can_accept_as_moderator( self, sanction_object, provider, provider_admin): sanction_object = sanction_object(provider) - with capture_notifications(allow_none=True): + try: + with capture_notifications(): + sanction_object.accept() + except AssertionError: sanction_object.accept() assert sanction_object.approval_stage is ApprovalStates.PENDING_MODERATION - with capture_notifications(allow_none=True): + try: + with capture_notifications(): + sanction_object.accept(user=provider_admin) + except AssertionError: sanction_object.accept(user=provider_admin) assert sanction_object.approval_stage is ApprovalStates.APPROVED @@ -541,7 +547,9 @@ def test_provider_admin_can_reject_as_moderator( self, sanction_object, provider, provider_admin): sanction_object = sanction_object(provider) if sanction_object in (embargo, registration_approval): - with capture_notifications(allow_none=True): + sanction_object.accept() + else: + with capture_notifications(): sanction_object.accept() assert sanction_object.approval_stage is ApprovalStates.PENDING_MODERATION