def test_process(self, transition_mock, *mocks): Processor(self.domain, self.transitions).process() calls = [call(**self.transitions['supervisor'][0]), call().perform(), call(**self.transitions['awc'][0]), call().perform()] transition_mock.assert_has_calls(calls)
def test_creating_new_locations(self, location_create_mock, locations_mock, *_): locations_mock.return_value = [self.location_112, self.location_12] location_create_mock.return_value = "A New Location" new_location_details = { 'supervisor': { '13': { 'name': 'Test 13', 'parent_site_code': None, 'lgd_code': 'LGD 13' } }, 'awc': { '131': { 'name': 'Test 131', 'parent_site_code': '13', 'lgd_code': 'LGD 131' } } } Processor(self.domain, self.transitions, new_location_details, {}, site_codes).process() location_type_supervisor = None location_type_awc = None for location_type in location_types: if location_type.code == 'supervisor': location_type_supervisor = location_type elif location_type.code == 'awc': location_type_awc = location_type calls = [ call(domain=self.domain, site_code='13', name='Test 13', parent=None, metadata={'lgd_code': 'LGD 13'}, location_type=location_type_supervisor), call(domain=self.domain, site_code='131', name='Test 131', parent="A New Location", metadata={'lgd_code': 'LGD 131'}, location_type=location_type_awc) ] location_create_mock.assert_has_calls(calls)
def process_location_reassignment(domain, transitions, uploaded_filename, user_email): try: Processor(domain, transitions).process() except Exception as e: email = EmailMessage( subject= f"[{settings.SERVER_ENVIRONMENT}] - Location Reassignment Failed", body=linebreaksbr( f"The request could not be completed for file {uploaded_filename}. Something went wrong.\n" f"Error raised : {e}.\n" "Please report an issue if needed."), to=[user_email], from_email=settings.DEFAULT_FROM_EMAIL) email.content_subtype = "html" email.send() raise e else: email = EmailMessage( subject= f"[{settings.SERVER_ENVIRONMENT}] - Location Reassignment Completed", body= f"The request has been successfully completed for file {uploaded_filename}.", to=[user_email], from_email=settings.DEFAULT_FROM_EMAIL) email.send()
def test_process(self, locations_mock, deprecate_locations_mock, *_): locations_mock.return_value = self.all_locations Processor(self.domain, self.transitions, {}, {}, site_codes).process() calls = [call(self.domain, [self.location_112], [self.location_131], MOVE_OPERATION), call(self.domain, [self.location_12], [self.location_13], MOVE_OPERATION)] deprecate_locations_mock.assert_has_calls(calls) self.assertEqual(deprecate_locations_mock.call_count, 2)
def test_updating_cases(self, update_usercase_mock, locations_mock, *_): locations_mock.return_value = self.all_locations user_transitions = { 'username_new': 'username_old' } Processor(self.domain, self.transitions, {}, user_transitions, site_codes).process() update_usercase_mock.assert_called_with( self.domain, 'username_new', 'username_old' )
def process_location_reassignment(domain, transitions, uploaded_filename, user_email): try: Processor(domain, transitions).process() except Exception as e: notify_failure( e, subject=f"[{settings.SERVER_ENVIRONMENT}] - Location Reassignment Failed", email=user_email, uploaded_filename=uploaded_filename ) raise e else: notify_success( subject=f"[{settings.SERVER_ENVIRONMENT}] - Location Reassignment Completed", body=f"The request has been successfully completed for file {uploaded_filename}.", email=user_email )
def process_location_reassignment(domain, transitions, new_location_details, user_transitions, site_codes, user_email): try: Processor(domain, transitions, new_location_details, user_transitions, site_codes).process() except Exception as e: email = EmailMessage( subject='[{}] - Location Reassignment Failed'.format( settings.SERVER_ENVIRONMENT), body="The request could not be completed. Something went wrong. " "Error raised : {}. " "Please report an issue if needed.".format(e), to=[user_email], from_email=settings.DEFAULT_FROM_EMAIL) email.send() raise e else: email = EmailMessage( subject='[{}] - Location Reassignment Completed'.format( settings.SERVER_ENVIRONMENT), body="The request has been successfully completed.", to=[user_email], from_email=settings.DEFAULT_FROM_EMAIL) email.send()
def test_missing_locations(self, locations_mock, *_): locations_mock.return_value = [self.location_131] with self.assertRaises(InvalidTransitionError) as e: Processor(self.domain, self.transitions, {}, {}, site_codes).process() self.assertEqual(str(e.exception), "Could not load location with following site codes: 112")