def test_テーブルへのアイテム追加(self): pm_organizations.create_organization( trace_id, insert_organization['OrganizationID'], insert_organization['OrganizationName'], insert_organization['Contract'], insert_organization['ContractStatus']) insert_result = pm_organizations.get_organization( trace_id, insert_organization_id) self.organization_result_check( actual_organization=insert_result, expected_organization=insert_organization)
def test_テーブルへのアイテム追加_重複エラー(self): pm_organizations.create_organization( trace_id, insert_organization['OrganizationID'], insert_organization['OrganizationName'], insert_organization['Contract'], insert_organization['ContractStatus']) with self.assertRaises(NoRetryException): pm_organizations.create_organization( trace_id, insert_organization['OrganizationID'], insert_organization['OrganizationName'], insert_organization['Contract'], insert_organization['ContractStatus'])
def setUp(self): dotenv_path = Path(os.getcwd()).joinpath('.env') if os.path.exists(dotenv_path): load_dotenv(dotenv_path) num = 0 while num < 4: tmp_affiliation = copy.copy(affiliation_template) tmp_affiliation['MailAddress'] = affiliation_template[ 'MailAddress'].format(str(num)) tmp_affiliation['UserID'] = affiliation_template['UserID'].format( str(num)) tmp_affiliation['OrganizationID'] = affiliation_template[ 'OrganizationID'].format(str(num)) tmp_affiliation['InvitationStatus'] = num % 3 - 1 if (num < 3): tmp_affiliation['Authority'] = num + 1 else: tmp_affiliation['Authority'] = 3 pm_affiliation.create_affiliation( trace_id, tmp_affiliation['MailAddress'], tmp_affiliation['UserID'], tmp_affiliation['OrganizationID'], tmp_affiliation['Authority'], tmp_affiliation['InvitationStatus']) # Create data table Organization tmp_organization = copy.copy(organization_template) tmp_organization[ 'OrganizationID'] = affiliation_org_id_template.format( str(num)) pm_organizations.create_organization( trace_id, tmp_organization['OrganizationID'], tmp_organization['OrganizationName'], tmp_organization['Contract'], tmp_organization['ContractStatus']) num += 1
def setUp(self): dotenv_path = Path(os.getcwd()).joinpath('.env') if os.path.exists(dotenv_path): load_dotenv(dotenv_path) pm_organizations.create_organization( trace_id, test_organization['OrganizationID'], test_organization['OrganizationName'], test_organization['Contract'], test_organization['ContractStatus']) pm_organizations.create_organization( trace_id, delete_organization['OrganizationID'], delete_organization['OrganizationName'], delete_organization['Contract'], delete_organization['ContractStatus']) pm_organizations.create_organization( trace_id, update_organization['OrganizationID'], update_organization['OrganizationName'], update_organization['Contract'], update_organization['ContractStatus'])
def setUp(self): dotenv_path = Path(os.getcwd()).joinpath('.env') if os.path.exists(dotenv_path): load_dotenv(dotenv_path) # Create Organization pm_organizations.create_organization( trace_id, organization_template['OrganizationID'], organization_template['OrganizationName'], organization_template['Contract'], organization_template['ContractStatus']) # Create Projects pm_projects.create_projects(trace_id, projects_template['ProjectID'], projects_template['ProjectName'], projects_template['Description'], projects_template['OrganizationID']) # Create awscoop pm_awsAccountCoops.create_awscoops( trace_id, awscoops_template["CoopID"], awscoops_template["AWSAccount"], awscoops_template['AWSAccountName'], awscoops_template["RoleName"], awscoops_template["ExternalID"], awscoops_template["Description"], awscoops_template["Effective"], awscoops_template["OrganizationID"], awscoops_template["ProjectID"]) # Create awscoop members enable pm_awsAccountCoops.create_awscoops( trace_id, coop_id_members_enable, awscoops_template["AWSAccount"], awscoops_template['AWSAccountName'], awscoops_template["RoleName"], awscoops_template["ExternalID"], awscoops_template["Description"], awscoops_template["Effective"], awscoops_template["OrganizationID"], awscoops_template["ProjectID"]) attribute = {'Members': {"Value": 1}} pm_awsAccountCoops.update_awscoops(trace_id, coop_id_members_enable, attribute) # Create awscoop delete tmp_awscoops = copy.copy(awscoops_template) tmp_awscoops["CoopID"] = coop_id.format(str(999)) pm_awsAccountCoops.create_awscoops( trace_id, tmp_awscoops["CoopID"], tmp_awscoops["AWSAccount"], awscoops_template['AWSAccountName'], tmp_awscoops["RoleName"], tmp_awscoops["ExternalID"], tmp_awscoops["Description"], tmp_awscoops["Effective"], tmp_awscoops["OrganizationID"], tmp_awscoops["ProjectID"]) num = 1 while num < 4: # Create Affiliation tmp_affiliation = copy.copy(affiliation_template) tmp_affiliation['MailAddress'] = mail_address.format(str(num)) tmp_affiliation['UserID'] = user_id.format(str(num)) tmp_affiliation['Authority'] = num pm_affiliation.create_affiliation( trace_id, tmp_affiliation['MailAddress'], tmp_affiliation['UserID'], tmp_affiliation['OrganizationID'], tmp_affiliation['Authority'], tmp_affiliation['InvitationStatus']) num += 1
def setUp(self): dotenv_path = Path(os.getcwd()).joinpath('.env') if os.path.exists(dotenv_path): load_dotenv(dotenv_path) # Create Organization pm_organizations.create_organization( trace_id, organization_template['OrganizationID'], organization_template['OrganizationName'], organization_template['Contract'], organization_template['ContractStatus']) # Create Projects pm_projects.create_projects(trace_id, projects_template['ProjectID'], projects_template['ProjectName'], projects_template['Description'], projects_template['OrganizationID']) # Create awscoop pm_awsAccountCoops.create_awscoops( trace_id, awscoops_template["CoopID"], awscoops_template["AWSAccountName"], awscoops_template["AWSAccount"], awscoops_template["RoleName"], awscoops_template["ExternalID"], awscoops_template["Description"], awscoops_template["Effective"], awscoops_template["OrganizationID"], awscoops_template["ProjectID"]) num = 1 while num < 7: # Create Report tmp_report = copy.copy(reports_template) pm_reports.create_report( trace_id, tmp_report['ReportID'].format(str(num)), tmp_report['ReportName'], tmp_report['GenerateUser'], tmp_report['AWSAccounts'], 4, tmp_report['ResourceInfoPath'], tmp_report['JsonOutputPath'], tmp_report['JsonOutputTime'], tmp_report['HTMLOutputStatus'], tmp_report['HTMLPath'], tmp_report['HTMLOutputTime'], 2, tmp_report['ExcelPath'], tmp_report['ExcelOutputTime'], tmp_report['SchemaVersion'], tmp_report['OrganizationID'], tmp_report['ProjectID']) # Create organization task tmp_organization_task = copy.copy(organization_task_template) tmp_organization_task['TaskStatus'] = num if (num == 3 and num == 6): tmp_organization_task['TaskStatus'] = 0 elif (num == 4): tmp_organization_task['TaskStatus'] = -1 elif (num == 5): tmp_organization_task['TaskStatus'] = -1 tmp_organization_task[ 'RetryCount'] = tmp_organization_task['MaxRetry'] + 1 pm_organizationTasks.create_organizationTask( trace_id, tmp_organization_task['TaskID'].format(str(num)), tmp_organization_task['Code'], tmp_organization_task['Target'].format(str(num)), tmp_organization_task['UserID'], tmp_organization_task['MailAddress'], tmp_organization_task['TaskStatus'], tmp_organization_task['RetryCount'], tmp_organization_task['MaxRetry']) num += 1 # create data error no project # Create Organization pm_organizations.create_organization( trace_id, organization_id_error.format(str(1)), organization_template['OrganizationName'], organization_template['Contract'], organization_template['ContractStatus']) # Create organization task tmp_organization_task = copy.copy(organization_task_template) pm_organizationTasks.create_organizationTask( trace_id, tmp_organization_task['TaskID'].format(str(7)), tmp_organization_task['Code'], project_id_error.format(str(1)), tmp_organization_task['UserID'], tmp_organization_task['MailAddress'], tmp_organization_task['TaskStatus'], tmp_organization_task['RetryCount'], tmp_organization_task['MaxRetry']) # create data error no awscoops and no reports # Create organization task tmp_organization_task = copy.copy(organization_task_template) pm_organizationTasks.create_organizationTask( trace_id, tmp_organization_task['TaskID'].format(str(8)), tmp_organization_task['Code'], project_id_error.format(str(1)), tmp_organization_task['UserID'], tmp_organization_task['MailAddress'], tmp_organization_task['TaskStatus'], tmp_organization_task['RetryCount'], tmp_organization_task['MaxRetry']) # Create Projects pm_projects.create_projects(trace_id, project_id_error.format(str(1)), projects_template['ProjectName'], projects_template['Description'], organization_id_error.format(str(1))) # create data error no reports # Create organization task tmp_organization_task = copy.copy(organization_task_template) pm_organizationTasks.create_organizationTask( trace_id, tmp_organization_task['TaskID'].format(str(9)), tmp_organization_task['Code'], project_id_error.format(str(1)), tmp_organization_task['UserID'], tmp_organization_task['MailAddress'], tmp_organization_task['TaskStatus'], tmp_organization_task['RetryCount'], tmp_organization_task['MaxRetry']) # Create awscoop pm_awsAccountCoops.create_awscoops( trace_id, coop_id.format(str(2)), awscoops_template["AWSAccount"], awscoops_template["AWSAccountName"], awscoops_template["RoleName"], awscoops_template["ExternalID"], awscoops_template["Description"], awscoops_template["Effective"], organization_id_error.format(str(1)), project_id_error.format(str(1)))
def setUp(self): dotenv_path = Path(os.getcwd()).joinpath('.env') if os.path.exists(dotenv_path): load_dotenv(dotenv_path) num = 0 while num < 2: # Create data table Affiliation tmp_affiliation = copy.copy(affiliation_template) tmp_affiliation['MailAddress'] = affiliation_template[ 'MailAddress'].format(str(num)) tmp_affiliation['UserID'] = affiliation_template['UserID'].format( str(num)) if num == 1: tmp_affiliation['Authority'] = 3 else: tmp_affiliation['Authority'] = num tmp_affiliation[ 'OrganizationID'] = template_organization_id.format( str(num)) pm_affiliation.create_affiliation( trace_id, tmp_affiliation['MailAddress'], tmp_affiliation['UserID'], tmp_affiliation['OrganizationID'], tmp_affiliation['Authority'], tmp_affiliation['InvitationStatus']) # Create data table Organization tmp_organization = copy.copy(organization_template) tmp_organization[ 'OrganizationID'] = template_organization_id.format( str(num)) pm_organizations.create_organization( trace_id, tmp_organization['OrganizationID'], tmp_organization['OrganizationName'], tmp_organization['Contract'], tmp_organization['ContractStatus']) # Create data table Projects tmp_projects = copy.copy(projects_template) tmp_projects['ProjectID'] = projects_id_template.format(str(num)) pm_projects.create_projects(trace_id, tmp_projects['ProjectID'], tmp_projects['ProjectName'], tmp_projects['Description'], tmp_projects['OrganizationID']) num += 1 # creat data test function delete organaization while num < 4: tmp_affiliation = copy.copy(affiliation_template) tmp_affiliation['MailAddress'] = affiliation_template[ 'MailAddress'].format(str(num)) tmp_affiliation['UserID'] = affiliation_template['UserID'].format( str(num)) tmp_affiliation['OrganizationID'] = affiliation_template[ 'OrganizationID'].format(str(num)) tmp_affiliation['InvitationStatus'] = num % 3 - 1 if (num < 3): tmp_affiliation['Authority'] = num + 1 else: tmp_affiliation['Authority'] = 3 pm_affiliation.create_affiliation( trace_id, tmp_affiliation['MailAddress'], tmp_affiliation['UserID'], tmp_affiliation['OrganizationID'], tmp_affiliation['Authority'], tmp_affiliation['InvitationStatus']) # Create data table Organization tmp_organization = copy.copy(organization_template) tmp_organization[ 'OrganizationID'] = template_organization_id.format(str(num)) pm_organizations.create_organization( trace_id, tmp_organization['OrganizationID'], tmp_organization['OrganizationName'], tmp_organization['Contract'], tmp_organization['ContractStatus']) num += 1
for awsAccountCoop in awsAccountCoops: pm_awsAccountCoops.create_awscoops( trace_id, awsAccountCoop['CoopID'], awsAccountCoop['AWSAccount'], awsAccountCoop['AWSAccountName'], awsAccountCoop['RoleName'], awsAccountCoop['ExternalID'], awsAccountCoop['Description'], awsAccountCoop['Effective'], awsAccountCoop['OrganizationID'], awsAccountCoop['ProjectID']) for project in projects: pm_projects.create_projects(trace_id, project['ProjectID'], project['ProjectName'], project['Description'], project['OrganizationID']) for organization in organizations: pm_organizations.create_organization(trace_id, organization['OrganizationID'], organization['OrganizationName'], organization['Contract'], organization['ContractStatus']) for affiliation in affiliations: pm_affiliation.create_affiliation(trace_id, affiliation['MailAddress'], affiliation['UserID'], affiliation['OrganizationID'], affiliation['Authority'], affiliation['InvitationStatus']) except Exception as error: raise PmError(cause_error=error)
def setUp(self): dotenv_path = Path(os.getcwd()).joinpath('.env') if os.path.exists(dotenv_path): load_dotenv(dotenv_path) # Create Organization pm_organizations.create_organization( trace_id, organization_template['OrganizationID'], organization_template['OrganizationName'], organization_template['Contract'], organization_template['ContractStatus']) # Create Projects pm_projects.create_projects(trace_id, projects_template['ProjectID'], projects_template['ProjectName'], projects_template['Description'], projects_template['OrganizationID']) # Create ReportJobDefs num = 1 while num < 4: if num == 1: report_job_def_aws['Code'] = code_aws report_job_def_aws['JobDefinition'] = job_definition_aws elif num == 2: report_job_def_aws['Code'] = code_json report_job_def_aws['JobDefinition'] = job_definition_json else: 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']) num += 1 num = 1 while num < 4: # Create Affiliation tmp_affiliation = copy.copy(affiliation_template) tmp_affiliation['MailAddress'] = mail_address.format(str(num)) tmp_affiliation['UserID'] = user_id.format(str(num)) tmp_affiliation['Authority'] = num pm_affiliation.create_affiliation( trace_id, tmp_affiliation['MailAddress'], tmp_affiliation['UserID'], tmp_affiliation['OrganizationID'], tmp_affiliation['Authority'], tmp_affiliation['InvitationStatus']) # Create list reports tmp_report = copy.copy(reports_template) tmp_report['ReportStatus'] = num + 1 pm_reports.create_report( trace_id, tmp_report['ReportID'].format(str(num)), tmp_report['ReportName'], tmp_report['GenerateUser'], tmp_report['AWSAccounts'], tmp_report['ReportStatus'], tmp_report['ResourceInfoPath'], tmp_report['JsonOutputPath'], tmp_report['JsonOutputTime'], tmp_report['HTMLOutputStatus'], tmp_report['HTMLPath'], tmp_report['HTMLOutputTime'], tmp_report['ExcelOutputStatus'], tmp_report['ExcelPath'], tmp_report['ExcelOutputTime'], tmp_report['SchemaVersion'], tmp_report['OrganizationID'], tmp_report['ProjectID']) num += 1 pm_reports.create_report( trace_id, tmp_report['ReportID'].format(str(4)), tmp_report['ReportName'], tmp_report['GenerateUser'], tmp_report['AWSAccounts'], 4, tmp_report['ResourceInfoPath'], tmp_report['JsonOutputPath'], tmp_report['JsonOutputTime'], tmp_report['HTMLOutputStatus'], tmp_report['HTMLPath'], tmp_report['HTMLOutputTime'], 2, tmp_report['ExcelPath'], tmp_report['ExcelOutputTime'], tmp_report['SchemaVersion'], tmp_report['OrganizationID'], tmp_report['ProjectID']) pm_reports.create_report( trace_id, tmp_report['ReportID'].format(str(5)), tmp_report['ReportName'], tmp_report['GenerateUser'], tmp_report['AWSAccounts'], 4, tmp_report['ResourceInfoPath'], tmp_report['JsonOutputPath'], tmp_report['JsonOutputTime'], tmp_report['HTMLOutputStatus'], tmp_report['HTMLPath'], tmp_report['HTMLOutputTime'], 1, tmp_report['ExcelPath'], tmp_report['ExcelOutputTime'], tmp_report['SchemaVersion'], tmp_report['OrganizationID'], tmp_report['ProjectID']) pm_reports.create_report( trace_id, tmp_report['ReportID'].format(str(6)), tmp_report['ReportName'], tmp_report['GenerateUser'], tmp_report['AWSAccounts'], 2, tmp_report['ResourceInfoPath'], tmp_report['JsonOutputPath'], tmp_report['JsonOutputTime'], tmp_report['HTMLOutputStatus'], tmp_report['HTMLPath'], tmp_report['HTMLOutputTime'], 2, tmp_report['ExcelPath'], tmp_report['ExcelOutputTime'], tmp_report['SchemaVersion'], tmp_report['OrganizationID'], tmp_report['ProjectID'])
def create_organization(trace_id, email, data_body): pm_logger = common_utils.begin_logger(trace_id, __name__, inspect.currentframe()) # Parse JSON try: body_object = json.loads(data_body) organization_name = body_object["name"] contract = body_object["contract"] contract_status = body_object["contractStatus"] except Exception as e: return common_utils.error_exception(MsgConst.ERR_REQUEST_202, HTTPStatus.BAD_REQUEST, e, pm_logger, True) # Validate list_error = validate_insert(organization_name, contract, contract_status) if list_error: return common_utils.error_validate(MsgConst.ERR_REQUEST_201, HTTPStatus.UNPROCESSABLE_ENTITY, list_error, pm_logger) # Create Organization organization_id = str(uuid.uuid4()) try: pm_organizations.create_organization(trace_id, organization_id, organization_name, contract, contract_status) except PmError as e: return common_utils.error_exception(MsgConst.ERR_DB_403, HTTPStatus.INTERNAL_SERVER_ERROR, e, pm_logger, True) # Create Affiliation try: pm_affiliation.create_affiliation(trace_id, email, trace_id, organization_id, Authority.Owner.value, InvitationStatus.Belong.value) except PmError as e: # Delete Organizations pm_organizations.delete_organization(trace_id, organization_id) # 例外スタックトレースをログに出力する。 return common_utils.error_exception(MsgConst.ERR_DB_403, HTTPStatus.INTERNAL_SERVER_ERROR, e, pm_logger, True) # 組織情報を取得します。 try: organization_item = pm_organizations.get_organization( trace_id, organization_id, True) except PmError as e: return common_utils.error_exception(MsgConst.ERR_402, HTTPStatus.INTERNAL_SERVER_ERROR, e, pm_logger, True) response = common_utils.get_response_by_response_body( HTTPStatus.CREATED, organization_item) # return data response return common_utils.response(response, pm_logger)