def create_project(trace_id, organization_id, data_body): # Get logging pm_logger = common_utils.begin_logger(trace_id, __name__, inspect.currentframe()) # Parse JSON try: body_object = json.loads(data_body) project_name = body_object["name"] description = body_object["description"] except Exception as e: return common_utils.error_exception(MsgConst.ERR_REQUEST_202, HTTPStatus.BAD_REQUEST, e, pm_logger, True) # Validate list_error = validate_project(trace_id, project_name) if list_error: return common_utils.error_validate(MsgConst.ERR_REQUEST_201, HTTPStatus.UNPROCESSABLE_ENTITY, list_error, pm_logger) # Create Project project_id = str(uuid.uuid4()) if common_utils.is_null(description): description = None try: pm_projects.create_projects(trace_id, project_id, project_name, description, organization_id) except PmError as e: return common_utils.error_exception(MsgConst.ERR_DB_403, HTTPStatus.INTERNAL_SERVER_ERROR, e, pm_logger, True) try: project_item = pm_projects.get_projects(trace_id, project_id, convert_response=True) except PmError as e: return common_utils.error_exception(MsgConst.ERR_402, HTTPStatus.INTERNAL_SERVER_ERROR, e, pm_logger, True) # return data response response = common_utils.get_response_by_response_body( HTTPStatus.CREATED, project_item[0]) return common_utils.response(response, pm_logger)
def test_delete_project_success(self): test_organization_id = template_organization_id.format(str(1)) test_mail_address = affiliation_template_address.format(str(1)) test_user_id = affiliation_template_user_id.format(str(1)) project_id = projects_id_template.format(998) # Create data delete tmp_projects = copy.copy(projects_template) tmp_projects['ProjectID'] = project_id pm_projects.create_projects(trace_id, tmp_projects['ProjectID'], tmp_projects['ProjectName'], tmp_projects['Description'], tmp_projects['OrganizationID']) # handler path_parameters = { "organization_id": test_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) response = projects.delete_project_handler(event_mock, {}) # Get data response status_code = response['statusCode'] response_body = json.loads(response['body']) # Get data in database filter = Attr('OrganizationID').eq(test_organization_id) project = pm_projects.get_projects( trace_id, project_id, filter, convert_response=True) # Check data self.assertEqual(len(project), 0) self.assertEqual(response_body, None) self.assertEqual(status_code, HTTPStatus.NO_CONTENT)
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
"CreatedAt": "2017-11-23 07:46:14.520", "OrganizationID": "3c9381d8-9267-47b8-83b9-4281250f8d96", "UpdatedAt": "2017-11-23 07:46:14.520" }] 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'])
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'])