From d835da81c8b8c8fa9768d22a75fb798b91691339 Mon Sep 17 00:00:00 2001 From: Dylan Leard Date: Fri, 31 Jan 2025 11:26:12 -0800 Subject: [PATCH] test: broken tests part 1 --- .../_operation_id/test_operation_update_status.py | 3 +++ .../tests/endpoints/v1/_operations/test_operation_id.py | 6 ++++++ .../_user_operator_id/test_user_operator_update_status.py | 8 +++++--- .../_user_operator_id/test_user_operator_update_status.py | 3 ++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bc_obps/registration/tests/endpoints/v1/_operations/_operation_id/test_operation_update_status.py b/bc_obps/registration/tests/endpoints/v1/_operations/_operation_id/test_operation_update_status.py index 5c3d4e2660..0d4e6485e4 100644 --- a/bc_obps/registration/tests/endpoints/v1/_operations/_operation_id/test_operation_update_status.py +++ b/bc_obps/registration/tests/endpoints/v1/_operations/_operation_id/test_operation_update_status.py @@ -56,6 +56,7 @@ def test_cas_admin_approves_operation(self): assert operator.is_new is False assert operator.verified_by == self.user assert operator.verified_at.strftime("%Y-%m-%d") == now.strftime("%Y-%m-%d") + operation.refresh_from_db() self.mock_send_boro_id_application_email.assert_called_once_with( application_state=BoroIdApplicationStates.APPROVED, @@ -116,6 +117,7 @@ def test_cas_admin_declines_operation(self): assert operation_after_put.verified_by == self.user assert operation_after_put.bc_obps_regulated_operation is None + operation.refresh_from_db() self.mock_send_boro_id_application_email.assert_called_once_with( application_state=BoroIdApplicationStates.DECLINED, operator_legal_name=operation.operator.legal_name, @@ -154,6 +156,7 @@ def test_cas_admin_requests_changes_on_operation(self): assert operation_after_put.verified_by is None assert operation_after_put.bc_obps_regulated_operation is None + operation.refresh_from_db() self.mock_send_boro_id_application_email.assert_called_once_with( application_state=BoroIdApplicationStates.CHANGES_REQUESTED, operator_legal_name=operation.operator.legal_name, diff --git a/bc_obps/registration/tests/endpoints/v1/_operations/test_operation_id.py b/bc_obps/registration/tests/endpoints/v1/_operations/test_operation_id.py index bc32921d05..f715323a0c 100644 --- a/bc_obps/registration/tests/endpoints/v1/_operations/test_operation_id.py +++ b/bc_obps/registration/tests/endpoints/v1/_operations/test_operation_id.py @@ -231,6 +231,7 @@ def test_industry_user_update_operation_with_submit(self): assert response.status_code == 200 assert response.json() == {"name": "New name"} + operation.refresh_from_db() self.mock_send_boro_id_application_email.assert_called_once_with( application_state=BoroIdApplicationStates.CONFIRMATION, operator_legal_name=operation.operator.legal_name, @@ -310,6 +311,7 @@ def test_industry_user_update_operation_with_updated_point_of_contact(self): assert updated_contact2.first_name == 'Homer' assert updated_contact2.email == 'homer@email.com' + operation.refresh_from_db() self.mock_send_boro_id_application_email.assert_called_once_with( application_state=BoroIdApplicationStates.CONFIRMATION, operator_legal_name=operation.operator.legal_name, @@ -525,6 +527,7 @@ def test_industry_user_update_operation_with_changes_requested_status(self): assert retrieved_operation.submission_date - datetime.now(timezone.utc) < timedelta(seconds=10) assert retrieved_operation.status == Operation.Statuses.PENDING + operation.refresh_from_db() self.mock_send_boro_id_application_email.assert_called_once_with( application_state=BoroIdApplicationStates.CONFIRMATION, operator_legal_name=retrieved_operation.operator.legal_name, @@ -573,6 +576,7 @@ def test_industry_user_update_operation_with_pending_status(self): assert retrieved_operation.submission_date - datetime.now(timezone.utc) < timedelta(seconds=10) assert retrieved_operation.status == Operation.Statuses.PENDING + operation.refresh_from_db() self.mock_send_boro_id_application_email.assert_called_once_with( application_state=BoroIdApplicationStates.CONFIRMATION, operator_legal_name=retrieved_operation.operator.legal_name, @@ -621,6 +625,8 @@ def test_industry_user_update_operation_with_declined_status(self): # assert that operation's submission_date has been updated to the current time (approximately) assert retrieved_operation.submission_date - datetime.now(timezone.utc) < timedelta(seconds=10) assert retrieved_operation.status == Operation.Statuses.PENDING + + operation.refresh_from_db() self.mock_send_boro_id_application_email.assert_called_once_with( application_state=BoroIdApplicationStates.CONFIRMATION, operator_legal_name=retrieved_operation.operator.legal_name, diff --git a/bc_obps/registration/tests/endpoints/v1/_user_operators/_user_operator_id/test_user_operator_update_status.py b/bc_obps/registration/tests/endpoints/v1/_user_operators/_user_operator_id/test_user_operator_update_status.py index 9ed11435ca..f633b626bb 100644 --- a/bc_obps/registration/tests/endpoints/v1/_user_operators/_user_operator_id/test_user_operator_update_status.py +++ b/bc_obps/registration/tests/endpoints/v1/_user_operators/_user_operator_id/test_user_operator_update_status.py @@ -140,8 +140,10 @@ def test_cas_admin_approves_access_request_with_existing_operator(self, mocker): def test_cas_admin_approves_admin_access_request_with_new_operator(self, mocker): # In this test we are testing the user operator status change and not the operator change, # so we have to mark the operator as is_new=False and status=APPROVED so we can bypass the below part and can get to the email sending part - operator = operator_baker({'status': Operator.Statuses.APPROVED, 'is_new': False, 'created_by': self.user}) + operator = operator_baker({'status': Operator.Statuses.APPROVED, 'is_new': False}) + operator.refresh_from_db() user_operator = user_operator_baker({'operator': operator, 'user': operator.created_by}) + mock_send_operator_access_request_email = mocker.patch( "service.user_operator_service.send_operator_access_request_email" ) @@ -175,13 +177,13 @@ def test_cas_admin_approves_admin_access_request_with_new_operator(self, mocker) ) def test_cas_admin_declines_access_request(self, mocker): - user = baker.make(User) operator = operator_baker() operator.status = Operator.Statuses.APPROVED operator.is_new = False operator.save(update_fields=["status", "is_new"]) user_operator = user_operator_baker() - user_operator.user_id = user.user_guid + user_operator.refresh_from_db() + user_operator.user_id = user_operator.created_by_id user_operator.operator = operator user_operator.save(update_fields=["user_id", "operator_id"]) # Assigning contacts to the operator of the user_operator diff --git a/bc_obps/registration/tests/endpoints/v2/_user_operators/_user_operator_id/test_user_operator_update_status.py b/bc_obps/registration/tests/endpoints/v2/_user_operators/_user_operator_id/test_user_operator_update_status.py index 0ab3693886..df53e9365c 100644 --- a/bc_obps/registration/tests/endpoints/v2/_user_operators/_user_operator_id/test_user_operator_update_status.py +++ b/bc_obps/registration/tests/endpoints/v2/_user_operators/_user_operator_id/test_user_operator_update_status.py @@ -114,7 +114,8 @@ def test_cas_analyst_approves_access_request_with_existing_operator(self, mocker def test_cas_director_approves_admin_access_request_with_new_operator(self, mocker): # In this test we are testing the user operator status change and not the operator change, # so we have to mark the operator as is_new=False and status=APPROVED so we can bypass the below part and can get to the email sending part - operator = operator_baker({'status': Operator.Statuses.APPROVED, 'is_new': False, 'created_by': self.user}) + operator = operator_baker({'status': Operator.Statuses.APPROVED, 'is_new': False}) + operator.refresh_from_db() user_operator = user_operator_baker({'operator': operator, 'user': operator.created_by}) mock_send_operator_access_request_email = mocker.patch( "service.user_operator_service_v2.send_operator_access_request_email"