Exemple #1
0
    def test_execute_change_email_case_record_email_change_apply_is_zero(self):
        # patch mock
        patch_read_yaml = patch('premembers.common.FileUtils.read_yaml')

        # start mock object
        mock_read_yaml = patch_read_yaml.start()

        # mock data
        mock_read_yaml.return_value = data_config

        # addCleanup stop mock object
        self.addCleanup(patch_read_yaml.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 write log warning
        mock_method_warning.assert_called_once_with(
            "メールアドレス変更申請テーブルでレコードが存在しませんでした。変更申請ID: %s", apply_id)
Exemple #2
0
def execute_change_email_handler(event, context):
    apply_id = eventhelper.get_apply_id(event)

    pm_logger = common_utils.begin_logger(apply_id, __name__,
                                          inspect.currentframe())
    # return data response
    response = user_logic.execute_change_email(apply_id)
    return common_utils.response(response, pm_logger)
Exemple #3
0
    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の項目変更に失敗しました。")
Exemple #4
0
    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のメールアドレスと合致しませんでした。")
Exemple #5
0
    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)
Exemple #6
0
    def test_execute_change_email_case_read_yaml_error(self):
        # patch mock
        patch_read_yaml = patch('premembers.common.FileUtils.read_yaml')
        mock_error_exception = mock_common_utils.mock_error_exception(self)

        # start mock object
        mock_read_yaml = patch_read_yaml.start()

        # mock data
        mock_read_yaml.side_effect = PmError()

        # addCleanup stop mock object
        self.addCleanup(patch_read_yaml.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_insightwatch,
                         response_body)
        self.assertEqual(content_type_text_html,
                         response_headers['content-type'])

        # check param call function read_yaml
        mock_read_yaml.assert_called_once_with(apply_id, s3_setting_bucket,
                                               notify_config_cis_result_mail)

        mock_error_exception.assert_called_once()

        # check write log error
        mock_method_error.assert_called_once_with(
            "メールアドレス変更通知メール送信設定ファイルの取得に失敗しました。:s3://%s/%s",
            common_utils.get_environ(s3_setting_bucket),
            notify_config_cis_result_mail)
Exemple #7
0
    def test_execute_change_email_case_error_get_record_pm_email_change_apply(
            self):
        # patch mock
        patch_read_yaml = patch('premembers.common.FileUtils.read_yaml')
        query_key_patch = patch(
            'premembers.repository.pm_emailChangeApply.query_key')

        # start mock object
        mock_read_yaml = patch_read_yaml.start()
        mock_query_key = query_key_patch.start()

        # mock data
        mock_read_yaml.return_value = data_config
        mock_query_key.side_effect = PmError()

        # addCleanup stop mock object
        self.addCleanup(patch_read_yaml.stop)
        self.addCleanup(query_key_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_insightwatch,
                         response_body)
        self.assertEqual(content_type_text_html,
                         response_headers['content-type'])

        # check param call function query_key
        mock_query_key.assert_called_once_with(apply_id, apply_id, None)

        # check write log error
        mock_method_error.assert_called_once_with(
            "メールアドレス変更申請テーブルでレコード取得に失敗しました。変更申請ID: %s", apply_id)