def tearDown(self):
     pm_organizations.delete_organization(trace_id, test_organization_id)
     pm_organizations.delete_organization(trace_id, insert_organization_id)
     pm_organizations.delete_organization(trace_id, update_organization_id)
     pm_organizations.delete_organization(trace_id, delete_organization_id)
     pm_organizations.delete_organization(trace_id, batch_organization_id)
     pm_affiliation.delete_affiliation(batch_affiliation_user_id,
                                       batch_organization_id)
Пример #2
0
 def tearDown(self):
     num = 1
     while num < 4:
         pm_affiliation.delete_affiliation(user_id.format(str(num)),
                                           organization_id)
         num += 1
     pm_projects.delete_projects(trace_id, project_id)
     pm_organizations.delete_organization(trace_id, organization_id)
     pm_awsAccountCoops.delete_awscoops(trace_id,
                                        awscoops_template["CoopID"])
     pm_awsAccountCoops.delete_awscoops(trace_id, coop_id.format(str(999)))
     pm_awsAccountCoops.delete_awscoops(trace_id, coop_id_members_enable)
Пример #3
0
 def tearDown(self):
     num = 1
     while num < 7:
         pm_organizationTasks.delete(trace_id, task_id.format(str(num)))
         pm_reports.delete_reports(trace_id, report_id.format(str(num)))
         num += 1
     pm_organizationTasks.delete(trace_id, task_id.format(str(7)))
     pm_organizationTasks.delete(trace_id, task_id.format(str(8)))
     pm_awsAccountCoops.delete_awscoops(trace_id, coop_id.format(str(1)))
     pm_projects.delete_projects(trace_id, project_id)
     pm_projects.delete_projects(trace_id, project_id_error.format(str(1)))
     pm_organizations.delete_organization(trace_id, organization_id)
     pm_organizations.delete_organization(
         trace_id, organization_id_error.format(str(1)))
Пример #4
0
    def tearDown(self):
        num = 0
        while num < 4:
            delete_user_id = affiliation_template['UserID'].format(str(num))
            pm_affiliation.delete_affiliation(
                user_id=delete_user_id,
                organization_id=affiliation_org_id_template.format(str(num)))
            num += 1

        num = 0
        while num < 4:
            delete_user_id = affiliation_template['UserID'].format(str(num))
            pm_organizations.delete_organization(
                trace_id,
                organization_id=affiliation_org_id_template.format(str(num)))
            num += 1
Пример #5
0
 def tearDown(self):
     num = 1
     while num < 4:
         pm_affiliation.delete_affiliation(user_id.format(str(num)),
                                           organization_id)
         pm_reports.delete_reports(trace_id, report_id.format(str(num)))
         num += 1
     pm_projects.delete_projects(trace_id, project_id)
     pm_organizations.delete_organization(trace_id, organization_id)
     # Delete ReportJobDefs
     pm_batchJobDefs.delete_report_job_def(trace_id, code_aws)
     pm_batchJobDefs.delete_report_job_def(trace_id, code_json)
     pm_batchJobDefs.delete_report_job_def(trace_id, code_excel)
     pm_reports.delete_reports(trace_id, report_id.format(str(4)))
     pm_reports.delete_reports(trace_id, report_id.format(str(5)))
     pm_reports.delete_reports(trace_id, report_id.format(str(6)))
Пример #6
0
    def tearDown(self):
        num = 0
        while num < 2:
            # Get data user_id delete and organization_id delete
            user_id = affiliation_template['UserID'].format(str(num))
            organization_id = template_organization_id.format(
                str(num))

            # Delete data table Organization and Affiliation
            pm_affiliation.delete_affiliation(user_id, organization_id)
            pm_organizations.delete_organization(trace_id, organization_id)
            pm_projects.delete_projects(
                trace_id, projects_id_template.format(str(num)))
            num += 1

        # remove data test function delete organaization
        while num < 4:
            delete_user_id = affiliation_template['UserID'].format(str(num))
            pm_affiliation.delete_affiliation(
                user_id=delete_user_id,
                organization_id=template_organization_id.format(str(num)))
            num += 1

        num = 0
        while num < 4:
            delete_user_id = affiliation_template['UserID'].format(str(num))
            pm_organizations.delete_organization(
                trace_id,
                organization_id=template_organization_id.format(str(num)))
            num += 1

        num = 0
        while num < 4:
            delete_project_id = projects_template['ProjectID'].format(str(num))
            pm_projects.delete_projects(trace_id, delete_project_id)
            num += 1
 def test_テーブルへのアイテム削除(self):
     pm_organizations.delete_organization(trace_id, delete_organization_id)
     delete_result = pm_organizations.delete_organization(
         trace_id, delete_organization_id)
     self.assertIsNone(delete_result)
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)
def delete_organization(trace_id, email, organization_id):
    pm_logger = common_utils.begin_logger(trace_id, __name__,
                                          inspect.currentframe())
    try:
        organization_item = pm_organizations.get_organization(
            trace_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    if (not organization_item):
        return common_utils.error_common(MsgConst.ERR_301,
                                         HTTPStatus.NOT_FOUND, pm_logger)

    try:
        # delete organization
        pm_organizations.delete_organization(trace_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_405,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)
    try:
        # get affiliations get by organization id
        affiliation_items = pm_affiliation.query_organization_index(
            trace_id, organization_id)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_402,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    for affiliation in affiliation_items:
        try:
            # delete affiliations get by organization id
            pm_affiliation.delete_affiliation(affiliation["UserID"],
                                              organization_id)
        except PmError as e:
            return common_utils.error_exception(
                MsgConst.ERR_DB_405, HTTPStatus.INTERNAL_SERVER_ERROR, e,
                pm_logger, True)

        # set task informaiton request delete in Organization Tasks
        task_id = common_utils.get_uuid4()
        target = CommonConst.TARGET_DELETE_ORG_USER.format(
            affiliation["UserID"], organization_id)

        try:
            # create task informaiton request delete in Organization Tasks
            pm_organizationTasks.create_organizationTask(
                trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG_USER,
                target, trace_id, email, Status.Waiting.value, 0, 3)
        except PmError as e:
            return common_utils.error_exception(
                MsgConst.ERR_DB_403, HTTPStatus.INTERNAL_SERVER_ERROR, e,
                pm_logger, True)

        try:
            # Send message to organization topic task
            aws_common.sns_organization_topic(
                trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG_USER)
        except PmError as e:
            common_utils.write_log_pm_error(e, pm_logger, exc_info=True)

    # set task informaiton request delete in Organization Tasks
    task_id = common_utils.get_uuid4()
    try:
        # create task informaiton request delete in Organization Tasks
        pm_organizationTasks.create_organizationTask(
            trace_id, task_id, CommonConst.TASK_TYPE_CODE_DELETE_ORG,
            organization_id, trace_id, email, 0, 0, 3)
    except PmError as e:
        return common_utils.error_exception(MsgConst.ERR_DB_403,
                                            HTTPStatus.INTERNAL_SERVER_ERROR,
                                            e, pm_logger, True)

    # Send message to organization topic task
    aws_common.sns_organization_topic(trace_id, task_id,
                                      CommonConst.TASK_TYPE_CODE_DELETE_ORG,
                                      organization_id, trace_id)
    # response if delete success
    response = common_utils.get_response_by_response_body(
        HTTPStatus.NO_CONTENT, None)
    return common_utils.response(response, pm_logger)