def test_delete_excluded_resources_case_error_validate_not_param_query_string_resource_type(
            self):
        resource_type = None

        # mock function error_validate
        mock_error_validate = mock_common_utils.mock_error_validate(self)

        # call Function test
        actual_response = checkitemsettings_logic.delete_excluded_resources(
            trace_id, organization_id, project_id, check_item_code, coop_id,
            region_name, resource_type, resource_name)

        # assert output function
        # check call function common write log error
        mock_error_validate.assert_called_once()

        # check response
        actual_actual_response_body = json.loads(actual_response["body"])
        message_201 = MsgConst.ERR_REQUEST_201
        self.assertEqual(message_201["code"],
                         actual_actual_response_body["code"])
        self.assertEqual(message_201["message"],
                         actual_actual_response_body["message"])
        self.assertEqual(HTTPStatus.UNPROCESSABLE_ENTITY.value,
                         actual_response["statusCode"])

        actual_response_error = actual_actual_response_body["errors"]
        err_val_101 = MsgConst.ERR_VAL_101
        self.assertEqual(err_val_101["code"], actual_response_error[0]["code"])
        self.assertEqual("resource_type", actual_response_error[0]["field"])
        self.assertEqual(None, actual_response_error[0]["value"])
        self.assertEqual(err_val_101["message"],
                         actual_response_error[0]["message"])
    def test_create_excluded_resources_case_error_validate_param_lenght_exclusion_comment_is_301(
            self):
        trace_id = user_id_authority_owner
        param_body = {
            "regionName":
            region_name,
            "resourceType":
            resource_type,
            "resourceName":
            resource_name,
            "exclusionComment":
            "チェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントメントトチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントメントトチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントチェック項目除外コメントメントトト"
        }
        body_object = json.dumps(param_body)

        # mock object
        patch_query_awscoop_coop_key = patch(
            "premembers.repository.pm_awsAccountCoops.query_awscoop_coop_key")

        # mock function error_exception
        mock_error_validate = mock_common_utils.mock_error_validate(self)
        mock_query_awscoop_coop_key = patch_query_awscoop_coop_key.start()

        # mock data
        mock_query_awscoop_coop_key.return_value = data_pm_aws_account_coops

        # addCleanup stop mock object
        self.addCleanup(patch_query_awscoop_coop_key.stop)

        # call Function test
        actual_response = checkitemsettings_logic.create_excluded_resources(
            trace_id, user_id_authority_owner, organization_id, project_id,
            coop_id, check_item_code, mail_address, body_object)

        # assert output function
        # check call function common write log error
        mock_error_validate.assert_called_once()

        # check response
        response_body = json.loads(actual_response["body"])
        message_201 = MsgConst.ERR_REQUEST_201
        self.assertEqual(response_body["code"], message_201["code"])
        self.assertEqual(response_body["message"], message_201["message"])
        self.assertEqual(actual_response["statusCode"],
                         HTTPStatus.UNPROCESSABLE_ENTITY.value)

        actual_response_error = response_body["errors"]
        err_val_303 = MsgConst.ERR_VAL_303
        self.assertEqual(err_val_303["code"], actual_response_error[0]["code"])
        self.assertEqual("exclusionComment", actual_response_error[0]["field"])
        self.assertEqual(param_body["exclusionComment"],
                         actual_response_error[0]["value"])
        self.assertEqual(err_val_303["message"].format(300),
                         actual_response_error[0]["message"])
    def test_test_create_invite_case_error_validate_cognito_not_exist_user(
            self):
        # mock object
        patch_get_cognito_user_pools = patch(
            "premembers.common.aws_common.get_cognito_user_pools")

        # start mock object
        mock_get_cognito_user_pools = patch_get_cognito_user_pools.start()
        mock_error_validate = mock_common_utils.mock_error_validate(self)

        # mock data
        mock_get_cognito_user_pools.return_value = []

        # addCleanup stop mock object
        self.addCleanup(patch_get_cognito_user_pools.stop)

        trace_id = user_id_authority_owner
        body_object = {
            "mailAddress": "*****@*****.**",
            "authority": 3
        }
        param_body = json.dumps(body_object)

        # call Function test
        response = organizations_logic.create_invite(trace_id,
                                                     organization_id_test,
                                                     param_body)

        # assert output function
        # check call function common write log error
        mock_error_validate.assert_called_once()

        # check response
        response_body = json.loads(response["body"])
        message_201 = MsgConst.ERR_REQUEST_201
        self.assertEqual(response_body["code"], message_201["code"])
        self.assertEqual(response_body["message"], message_201["message"])
        self.assertEqual(response["statusCode"],
                         HTTPStatus.UNPROCESSABLE_ENTITY.value)

        response_error = response_body["errors"]
        err_val_999 = MsgConst.ERR_VAL_999
        self.assertEqual(response_error[0]["code"], err_val_999["code"])
        self.assertEqual(response_error[0]["field"], "mail_address")
        self.assertEqual(response_error[0]["value"],
                         body_object['mailAddress'])
        self.assertEqual(response_error[0]["message"], err_val_999["message"])
Beispiel #4
0
    def test_update_user_attribute_case_error_validate_value_param_callerServiceName_invalid(
            self):
        data_body = {
            "userName": data_insert['UserName'],
            "companyName": data_insert['CompanyName'],
            "departmentName": data_insert['DepartmentName'],
            "countryCode": data_insert['CountryCode'],
            "companyFlg": data_insert['CompanyFlg'],
            "callerServiceName": "value_invald",
        }
        param_body = json.dumps(data_body)

        # mock function error_validate
        mock_error_validate = mock_common_utils.mock_error_validate(self)

        # call Function test
        response = user_logic.update_user_attributes(user_id, param_body)

        # assert output function
        # check call function common write log error
        mock_error_validate.assert_called_once()

        # check response
        response_body = json.loads(response["body"])
        message_201 = MsgConst.ERR_REQUEST_201
        self.assertEqual(response_body["code"], message_201["code"])
        self.assertEqual(response_body["message"], message_201["message"])
        self.assertEqual(response["statusCode"],
                         HTTPStatus.UNPROCESSABLE_ENTITY.value)

        response_error = response_body["errors"]
        err_val_302 = MsgConst.ERR_VAL_302
        self.assertEqual(response_error[0]["code"], err_val_302["code"])
        self.assertEqual(response_error[0]["field"], "callerServiceName")
        self.assertEqual(response_error[0]["value"], "value_invald")
        self.assertEqual(
            response_error[0]["message"],
            err_val_302["message"].format("insightwatch, opswitch"))