def test_create_report_error_record_zero_report_job_defs_excel(self):
        pm_batchJobDefs.delete_report_job_def(trace_id, code_excel)
        test_mail_address = mail_address.format(str(3))
        test_user_id = user_id.format(str(3))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id
        }
        event_mock = event_create.get_event_object(
            email=test_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(report_create))
        response = reports.create_report_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'], MsgConst.ERR_402['code'])
        self.assertEqual(response_body['message'], MsgConst.ERR_402['message'])
        self.assertEqual(response_body['description'],
                         MsgConst.ERR_402['description'])
        self.assertEqual(response['statusCode'],
                         HTTPStatus.INTERNAL_SERVER_ERROR.value)

        # Create ReportJobDefs
        report_job_def_aws['Code'] = code_excel
        report_job_def_aws['JobDefinition'] = job_definition_excel
        pm_batchJobDefs.create_report_job_def(
            trace_id, report_job_def_aws['Code'],
            report_job_def_aws['JobDefinition'],
            report_job_def_aws['JobQueue'], report_job_def_aws['MaxRetry'],
            report_job_def_aws['Environment'])
    def test_create_report_error_parse_json(self):
        test_mail_address = mail_address.format(str(3))
        test_user_id = user_id.format(str(3))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id
        }
        event_mock = event_create.get_event_object(
            email=test_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=report_create)
        response = reports.create_report_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'],
                         MsgConst.ERR_REQUEST_202['code'])
        self.assertEqual(response_body['message'],
                         MsgConst.ERR_REQUEST_202['message'])
        self.assertEqual(response_body['description'],
                         MsgConst.ERR_REQUEST_202['description'])
        self.assertEqual(response['statusCode'], HTTPStatus.BAD_REQUEST.value)
    def test_create_report_success(self):
        test_mail_address = mail_address.format(str(3))
        test_user_id = user_id.format(str(3))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id
        }
        event_mock = event_create.get_event_object(
            email=test_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(report_create))
        response = reports.create_report_handler(event_mock, {})

        # Get data response
        status_code = response['statusCode']
        response_body = json.loads(response['body'])
        id = response_body["id"]
        name = response_body['name']
        generateUser = response_body['generateUser']
        awsAccounts = response_body['awsAccounts']
        status = response_body['status']
        jsonOutputTime = response_body['jsonOutputTime']
        excelOutputStatus = response_body['excelOutputStatus']
        excelOutputTime = response_body['excelOutputTime']
        schemaVersion = response_body['schemaVersion']
        projectId = response_body['projectId']
        organizationId = response_body['organizationId']
        createdAt = response_body['createdAt']
        updatedAt = response_body['updatedAt']

        # Get data in database
        report_database = pm_reports.query_report(trace_id,
                                                  id,
                                                  convert_response=True)

        # Check data
        self.assertEqual(id, report_database['id'])
        self.assertEqual(name, report_database['name'])
        self.assertEqual(generateUser, report_database['generateUser'])
        self.assertEqual(awsAccounts, report_database['awsAccounts'])
        self.assertEqual(status, report_database['status'])
        self.assertEqual(jsonOutputTime, report_database['jsonOutputTime'])
        self.assertEqual(excelOutputStatus,
                         report_database['excelOutputStatus'])
        self.assertEqual(excelOutputTime, report_database['excelOutputTime'])
        self.assertEqual(schemaVersion, report_database['schemaVersion'])
        self.assertEqual(projectId, report_database['projectId'])
        self.assertEqual(organizationId, report_database['organizationId'])
        self.assertEqual(createdAt, report_database['createdAt'])
        self.assertEqual(updatedAt, report_database['updatedAt'])
        self.assertEqual(status_code, HTTPStatus.CREATED.value)
        pm_reports.delete_reports(trace_id, id)
    def test_create_report_error_validate_data(self):
        test_mail_address = mail_address.format(str(3))
        test_user_id = user_id.format(str(3))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id
        }
        event_mock = event_create.get_event_object(
            email=test_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(report_create_error_data))
        response = reports.create_report_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'],
                         MsgConst.ERR_REQUEST_201['code'])
        self.assertEqual(response_body['message'],
                         MsgConst.ERR_REQUEST_201['message'])
        self.assertEqual(response['statusCode'],
                         HTTPStatus.UNPROCESSABLE_ENTITY.value)

        response_error = response_body['errors']
        # レポート名
        self.assertEqual(response_error[0]['code'],
                         MsgConst.ERR_VAL_202['code'])
        self.assertEqual(response_error[0]['field'], "name")
        self.assertEqual(response_error[0]['value'],
                         report_create_error_data['name'])
        self.assertEqual(response_error[0]['message'],
                         MsgConst.ERR_VAL_202['message'])

        # AWSアカウントID
        self.assertEqual(response_error[1]['code'],
                         MsgConst.ERR_VAL_204['code'])
        self.assertEqual(response_error[1]['field'], "awsAccounts")
        self.assertEqual(response_error[1]['value'],
                         report_create_error_data['awsAccounts'])
        self.assertEqual(response_error[1]['message'],
                         MsgConst.ERR_VAL_204['message'])

        # レポート出力するファイル形式
        self.assertEqual(response_error[2]['code'],
                         MsgConst.ERR_VAL_302['code'])
        self.assertEqual(response_error[2]['field'], "outputFileType")
        self.assertEqual(response_error[2]['value'],
                         report_create_error_data['outputFileType'])
        self.assertEqual(response_error[2]['message'],
                         MsgConst.ERR_VAL_302['message'].format("EXCEL"))
    def test_create_report_project_error_record_zero(self):
        test_mail_address = mail_address.format(str(3))
        test_user_id = user_id.format(str(3))
        test_project_id = "not_exist"
        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": test_project_id
        }
        event_mock = event_create.get_event_object(
            email=test_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(report_create))
        response = reports.create_report_handler(event_mock, {})

        # Check data
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'], MsgConst.ERR_AWS_401['code'])
        self.assertEqual(response_body['message'],
                         MsgConst.ERR_AWS_401['message'])
        self.assertEqual(response['statusCode'],
                         HTTPStatus.UNPROCESSABLE_ENTITY.value)
    def test_create_report_error_access_authority(self):
        # Authority = 1
        tmp_mail_address = mail_address.format(str(1))
        test_user_id = user_id.format(str(1))

        # handler
        path_parameters = {
            "organization_id": organization_id,
            "project_id": project_id
        }
        event_mock = event_create.get_event_object(
            email=tmp_mail_address,
            path_parameters=path_parameters,
            trace_id=test_user_id,
            body=json.dumps(report_create))
        response = reports.create_report_handler(event_mock, {})

        # Check data
        message_101 = MsgConst.ERR_101
        response_body = json.loads(response['body'])
        self.assertEqual(response_body['code'], message_101['code'])
        self.assertEqual(response_body['message'], message_101['message'])
        self.assertEqual(response['statusCode'], HTTPStatus.FORBIDDEN.value)