def test_execute_change_email_case_update_cognito_user_attributes_error_caller_service_name_is_opswitch( self): # perpare data test mock_pm_emailChangeApply.create( data_insert_caller_service_name_opswitch) # patch mock patch_read_yaml = patch('premembers.common.FileUtils.read_yaml') get_cognito_user_info_by_user_name_patch = patch( 'premembers.common.aws_common.get_cognito_user_info_by_user_name') update_cognito_user_attributes_patch = patch( 'premembers.common.aws_common.update_cognito_user_attributes') # start mock object mock_read_yaml = patch_read_yaml.start() mock_get_cognito_user_info_by_user_name = get_cognito_user_info_by_user_name_patch.start( ) mock_update_cognito_user_attributes = update_cognito_user_attributes_patch.start( ) # mock data mock_read_yaml.return_value = data_config mock_get_cognito_user_info_by_user_name.return_value = user_info mock_update_cognito_user_attributes.side_effect = PmError() # addCleanup stop mock object self.addCleanup(patch_read_yaml.stop) self.addCleanup(get_cognito_user_info_by_user_name_patch.stop) self.addCleanup(update_cognito_user_attributes_patch.stop) with patch.object(PmLogAdapter, 'error', return_value=None) as mock_method_error: # call function test result = user_logic.execute_change_email(apply_id) # Check data status_code = result['statusCode'] response_body = result['body'] response_headers = result['headers'] self.assertEqual(HTTPStatus.OK.value, status_code) self.assertEqual(response_error_page_caller_service_opswitch, response_body) self.assertEqual(content_type_text_html, response_headers['content-type']) # check param call function get_cognito_user_info_by_user_name mock_get_cognito_user_info_by_user_name.assert_called_once_with( apply_id, user_id) # check param call function update_cognito_user_attributes mock_update_cognito_user_attributes.assert_called_once_with( apply_id, user_id, user_attributes) # check write log error mock_method_error.assert_called_once_with("Cognitoの項目変更に失敗しました。")
def test_execute_change_email_case_before_mail_address_other_cognito_mail_caller_service_name_is_opswitch( self): # perpare data test mock_pm_emailChangeApply.create( data_insert_caller_service_name_opswitch) # patch mock patch_read_yaml = patch('premembers.common.FileUtils.read_yaml') get_cognito_user_info_by_user_name_patch = patch( 'premembers.common.aws_common.get_cognito_user_info_by_user_name') search_patch = patch('jmespath.search') # start mock object mock_read_yaml = patch_read_yaml.start() mock_get_cognito_user_info_by_user_name = get_cognito_user_info_by_user_name_patch.start( ) mock_search = search_patch.start() # mock data mock_read_yaml.return_value = data_config mock_get_cognito_user_info_by_user_name.return_value = user_info mock_search.return_value = "*****@*****.**" # addCleanup stop mock object self.addCleanup(patch_read_yaml.stop) self.addCleanup(get_cognito_user_info_by_user_name_patch.stop) self.addCleanup(search_patch.stop) with patch.object(PmLogAdapter, 'warning', return_value=None) as mock_method_warning: # call function test result = user_logic.execute_change_email(apply_id) # Check data status_code = result['statusCode'] response_body = result['body'] response_headers = result['headers'] self.assertEqual(HTTPStatus.OK.value, status_code) self.assertEqual(response_error_page_caller_service_opswitch, response_body) self.assertEqual(content_type_text_html, response_headers['content-type']) # check param call function get_cognito_user_info_by_user_name mock_get_cognito_user_info_by_user_name.assert_called_once_with( apply_id, user_id) # check param call function search mock_search.assert_called_once_with("[?Name=='email'].Value | [0]", user_info['UserAttributes']) # check write log warning mock_method_warning.assert_called_once_with( "変更前メールアドレスがCognitoのメールアドレスと合致しませんでした。")
def test_execute_change_email_case_get_cognito_user_info_by_user_name_is_none_caller_service_name_is_insightwatch( self): # perpare data test mock_pm_emailChangeApply.create( data_insert_caller_service_name_insightwatch) # patch mock patch_read_yaml = patch('premembers.common.FileUtils.read_yaml') get_cognito_user_info_by_user_name_patch = patch( 'premembers.common.aws_common.get_cognito_user_info_by_user_name') # start mock object mock_read_yaml = patch_read_yaml.start() mock_get_cognito_user_info_by_user_name = get_cognito_user_info_by_user_name_patch.start( ) # mock data mock_read_yaml.return_value = data_config mock_get_cognito_user_info_by_user_name.return_value = None # addCleanup stop mock object self.addCleanup(patch_read_yaml.stop) self.addCleanup(get_cognito_user_info_by_user_name_patch.stop) with patch.object(PmLogAdapter, 'warning', return_value=None) as mock_method_warning: # call function test result = user_logic.execute_change_email(apply_id) # Check data status_code = result['statusCode'] response_body = result['body'] response_headers = result['headers'] self.assertEqual(HTTPStatus.OK.value, status_code) self.assertEqual(response_error_page_caller_service_insightwatch, response_body) self.assertEqual(content_type_text_html, response_headers['content-type']) # check param call function get_cognito_user_info_by_user_name mock_get_cognito_user_info_by_user_name.assert_called_once_with( apply_id, user_id) # check write log warning mock_method_warning.assert_called_once_with( "Cognitoにユーザーが存在しませんでした。ユーザーID: %s", user_id)
def test_execute_change_email_handler_success_case_caller_service_name_is_insightwatch(self): # perpare data test for affiliation in list_affiliations: mock_pm_affiliation.create(affiliation) for org_notify_mail_destination in list_org_notify_mail_destinations: mock_pm_orgNotifyMailDestinations.create( org_notify_mail_destination) mock_pm_emailChangeApply.create( data_insert_caller_service_name_insightwatch) # patch mock get_cognito_user_info_by_user_name_patch = patch( 'premembers.common.aws_common.get_cognito_user_info_by_user_name') update_cognito_user_attributes_patch = patch( 'premembers.common.aws_common.update_cognito_user_attributes') patch_read_yaml = patch('premembers.common.FileUtils.read_yaml') # start mock object mock_get_cognito_user_info_by_user_name = get_cognito_user_info_by_user_name_patch.start() mock_update_cognito_user_attributes = update_cognito_user_attributes_patch.start() mock_read_yaml = patch_read_yaml.start() # mock data mock_get_cognito_user_info_by_user_name.return_value = user_info mock_update_cognito_user_attributes.return_value = None mock_read_yaml.return_value = data_config # addCleanup stop mock object self.addCleanup(get_cognito_user_info_by_user_name_patch.stop) self.addCleanup(update_cognito_user_attributes_patch.stop) self.addCleanup(patch_read_yaml.stop) # Call function test result = user.execute_change_email_handler(event_mock, {}) # Check data status_code = result['statusCode'] response_body = result['body'] response_headers = result['headers'] self.assertEqual(HTTPStatus.OK.value, status_code) self.assertEqual( response_execute_change_email_caller_service_insightwatch, response_body) self.assertEqual(content_type_text_html, response_headers['content-type']) # check update data table PM_OrgNotifyMailDestinations for affiliation in list_affiliations: org_notify_mail_destinations = mock_pm_orgNotifyMailDestinations.query_key( affiliation['OrganizationID'], notify_code) for destination in org_notify_mail_destinations['Destinations']: self.assertEqual(after_mail_address, destination['MailAddress']) # check update data table PM_Affiliation list_affiliations_update = mock_pm_affiliation.query_userid_key( user_id) for affiliation_update in list_affiliations_update: self.assertEqual(after_mail_address, affiliation_update['MailAddress']) # check delete data table PM_EmailChangeApply email_change_apply = mock_pm_emailChangeApply.query_key(apply_id) self.assertEqual(None, email_change_apply) # check param call function get_cognito_user_info_by_user_name mock_get_cognito_user_info_by_user_name.assert_called_once_with( apply_id, user_id) # check param call function update_cognito_user_attributes mock_update_cognito_user_attributes.update_cognito_user_attributes( apply_id, user_id, user_attributes)