Exemple #1
0
def _transmogrify_contacts(now_app, now_sub, mms_now_sub):
    for c in now_sub.contacts:
        emailValidator = re.compile(r'[^@]+@[^@]+\.[^@]+')
        now_party_appt = None
        if c.type == 'Individual' and c.contacttype and c.ind_lastname and c.ind_firstname and c.ind_phonenumber:
            now_party = Party(
                party_name=c.ind_lastname,
                first_name=c.ind_firstname,
                party_type_code='PER',
                phone_no=c.ind_phonenumber[:3] + "-" + c.ind_phonenumber[3:6] +
                "-" + c.ind_phonenumber[6:],
                email=c.email
                if c.email and emailValidator.match(c.email) else None,
            )
            now_party_mine_party_appt_type = MinePartyAppointmentType.find_by_mine_party_appt_type_code(
                _map_contact_type(c.contacttype))
            now_party_appt = app_models.NOWPartyAppointment(
                mine_party_appt_type_code=now_party_mine_party_appt_type.
                mine_party_appt_type_code,
                mine_party_appt_type=now_party_mine_party_appt_type,
                party=now_party)
        if c.type == 'Organization' and c.contacttype and c.org_legalname and c.dayphonenumber:
            now_party = Party(
                party_name=c.org_legalname,
                party_type_code='ORG',
                phone_no=c.dayphonenumber[:3] + "-" + c.dayphonenumber[3:6] +
                "-" + c.dayphonenumber[6:],
                phone_ext=c.dayphonenumberext,
                email=c.email
                if c.email and emailValidator.match(c.email) else None,
            )
            now_party_mine_party_appt_type = MinePartyAppointmentType.find_by_mine_party_appt_type_code(
                _map_contact_type(c.contacttype))
            now_party_appt = app_models.NOWPartyAppointment(
                mine_party_appt_type_code=now_party_mine_party_appt_type.
                mine_party_appt_type_code,
                mine_party_appt_type=now_party_mine_party_appt_type,
                party=now_party)

        if now_party_appt:
            validPostalCode = re.compile(r"\s*([a-zA-Z]\s*\d\s*){3}$")
            post_code = c.mailingaddresspostalzip.replace(
                " ",
                "") if c.mailingaddresspostalzip and validPostalCode.match(
                    c.mailingaddresspostalzip.replace(" ", "")) else None
            if c.mailingaddressline1 and c.mailingaddresscity and c.mailingaddressprovstate and c.mailingaddresscountry:
                now_address = Address(
                    address_line_1=c.mailingaddressline1,
                    address_line_2=c.mailingaddressline2,
                    city=c.mailingaddresscity,
                    sub_division_code=c.mailingaddressprovstate.replace(
                        " ", ""),
                    post_code=post_code,
                    address_type_code='CAN'
                    if c.mailingaddresscountry == 'Canada' else 'USA')
                now_party_appt.party.address.append(now_address)
            now_app.contacts.append(now_party_appt)
    return
Exemple #2
0
    def put(self, party_guid):
        data = PartyResource.parser.parse_args()
        existing_party = Party.find_by_party_guid(party_guid)
        if not existing_party:
            raise NotFound('Party not found.')

        current_app.logger.info(f'Updating {existing_party} with {data}')
        for key, value in data.items():
            if key in ['party_type_code']:
                continue     # non-editable fields from put
            setattr(existing_party, key, value)

        # We are now allowing parties to be created without an address
        if (data.get('suite_no') or data.get('address_line_1') or data.get('address_line_2')
                or data.get('city') or data.get('sub_division_code')
                or data.get('post_code')):                                                   # and check that we are changing the address
            if len(existing_party.address) == 0:
                address = Address.create()
                existing_party.address.append(address)

            for key, value in data.items():
                setattr(existing_party.address[0], key, value)

        existing_party.save()

        return existing_party
Exemple #3
0
    def post(self, party_guid=None):
        if party_guid:
            raise BadRequest('Unexpected party id in Url.')
        data = PartyListResource.parser.parse_args()

        party = Party.create(
            data.get('party_name'),
            data.get('phone_no'),
            data.get('party_type_code'),
            # Nullable fields
            email=data.get('email'),
            first_name=data.get('first_name'),
            phone_ext=data.get('phone_ext'))

        if not party:
            raise InternalServerError('Error: Failed to create party')

        # If no address data is provided do not create an address.
        if (data.get('suite_no') or data.get('address_line_1') or data.get('address_line_2')
                or data.get('city') or data.get('sub_division_code') or data.get('post_code')):
            address = Address.create(suite_no=data.get('suite_no'),
                                     address_line_1=data.get('address_line_1'),
                                     address_line_2=data.get('address_line_2'),
                                     city=data.get('city'),
                                     sub_division_code=data.get('sub_division_code'),
                                     post_code=data.get('post_code'))
            party.address.append(address)

        party.save()
        return party
Exemple #4
0
    def put(self, mine_guid, variance_guid):
        variance = Variance.find_by_mine_guid_and_variance_guid(
            mine_guid, variance_guid)
        if variance is None:
            raise NotFound('Unable to fetch variance')

        data = self.parser.parse_args()

        inspector_party_guid = data.get('inspector_party_guid')
        if inspector_party_guid:
            inspector = Party.find_by_party_guid(inspector_party_guid)
            if not inspector:
                raise BadRequest('Unable to find new inspector.')
            if not 'INS' in inspector.business_roles_codes:
                raise BadRequest('Party is not an inspector.')

            variance.inspector_party_guid = inspector_party_guid

        for key, value in data.items():
            if key in ['inspector_party_guid']:
                continue
            setattr(variance, key, value)

        # A manual check to prevent a stack trace dump on a foreign key /
        # constraint error because global error handling doesn't currently work
        # with these errors
        Variance.validate_status_with_other_values(
            status=variance.variance_application_status_code,
            issue=variance.issue_date,
            expiry=variance.expiry_date,
            inspector=variance.inspector_party_guid)

        variance.save()
        return variance
Exemple #5
0
def test_party_model_validate_first_name(test_client, auth_headers):
    with pytest.raises(AssertionError) as e:
        Party(party_name='test_fail_party_name',
              first_name=''.join(['{}'.format(x) for x in range(100)]),
              party_type_code='PER',
              phone_no='123-123-1234',
              phone_ext='1234')
    assert 'Person first name must not exceed 100 characters.' in str(e.value)
Exemple #6
0
def test_party_model_validate_phone_no_not_provided(test_client, auth_headers):
    with pytest.raises(AssertionError) as e:
        Party(party_name='party_name_pass',
              first_name='test_first_name_fail',
              party_type_code='PER',
              phone_no='',
              phone_ext='1234')
    assert 'Party phone number is not provided.' in str(e.value)
Exemple #7
0
def test_party_model_validate_party_name_not_provided():
    with pytest.raises(AssertionError) as e:
        Party(party_name='',
              first_name='fail_name',
              party_type_code='PER',
              phone_no='123-123-1234',
              phone_ext='1234')
    assert 'Party name is not provided.' in str(e.value)
Exemple #8
0
def test_party_model_validate_party_name_exceeds_100_chars():
    with pytest.raises(AssertionError) as e:
        Party(party_name='p' * 101,
              first_name='test_first_name_fail',
              party_type_code='PER',
              phone_no='123-123-1234',
              phone_ext='1234')
    assert 'Party name must not exceed 100 characters.' in str(e.value)
Exemple #9
0
    def post(self, mine_guid, permit_guid, permit_amendment_guid=None):
        if permit_amendment_guid:
            raise BadRequest('Unexpected permit_amendement_guid.')

        permit = Permit.find_by_permit_guid(permit_guid)
        if not permit:
            raise NotFound('Permit does not exist.')

        if not str(permit.mine_guid) == mine_guid:
            raise BadRequest(
                'Permits mine_guid and provided mine_guid mismatch.')

        data = self.parser.parse_args()
        current_app.logger.info(f'creating permit_amendment with >> {data}')

        party = Party.find_by_party_guid(data.get('permittee_party_guid'))
        if not party:
            raise NotFound('Party not found')

        party_is_active_permittee = False

        permittees = MinePartyAppointment.find_by_permit_guid(permit_guid)

        for permittee in permittees:
            if permittee.end_date is None:
                if permittee.party_guid == party.party_guid:
                    party_is_active_permittee = True
                else:  # inactive old permittees
                    permittee.end_date = datetime.utcnow()
                    permittee.save()

        if not party_is_active_permittee:
            new_permittee = MinePartyAppointment.create(permit.mine_guid,
                                                        data.get(
                                                            'permittee_party_guid'), 'PMT',
                                                        datetime.utcnow(), None,
                                                        self.get_user_info(), permit_guid, True)
            new_permittee.save()

        new_pa = PermitAmendment.create(
            permit,
            data.get('received_date'),
            data.get('issue_date'),
            data.get('authorization_end_date'),
            data.get('permit_amendment_type_code', 'AMD'),
            description=data.get('description'))

        uploadedFiles = data.get('uploadedFiles', [])
        for newFile in uploadedFiles:
            new_pa_doc = PermitAmendmentDocument(
                document_name=newFile['fileName'],
                document_manager_guid=newFile['document_manager_guid'],
                mine_guid=permit.mine_guid,
            )
            new_pa.related_documents.append(new_pa_doc)
        new_pa.save()
        return new_pa
Exemple #10
0
def test_party_model_validate_phone_no_invalid_format():
    with pytest.raises(AssertionError) as e:
        Party(party_name='party_name_pass',
              first_name='test_first_name_fail',
              party_type_code='PER',
              phone_no='12--123-1234',
              phone_ext='1234')
    assert 'Invalid phone number format, must be of XXX-XXX-XXXX.' in str(
        e.value)
Exemple #11
0
    def post(self, mine_guid):
        data = self.parser.parse_args()

        mine = Mine.find_by_mine_guid(mine_guid)
        if not mine:
            raise NotFound(
                'There was no mine found with the provided mine_guid.')

        party = Party.find_by_party_guid(data.get('permittee_party_guid'))
        if not party:
            raise NotFound('Party not found')

        permit = Permit.find_by_permit_no(data.get('permit_no'))
        if permit:
            raise BadRequest("That permit number is already in use.")

        uploadedFiles = data.get('uploadedFiles', [])

        permit = Permit.create(mine.mine_guid, data.get('permit_no'),
                               data.get('permit_status_code'))

        amendment = PermitAmendment.create(
            permit,
            data.get('received_date'),
            data.get('issue_date'),
            data.get('authorization_end_date'),
            'OGP',
            description='Initial permit issued.')

        db.session.add(permit)
        db.session.add(amendment)

        for newFile in uploadedFiles:
            new_pa_doc = PermitAmendmentDocument(
                document_name=newFile['fileName'],
                document_manager_guid=newFile['document_manager_guid'],
                mine_guid=permit.mine_guid,
            )
            amendment.related_documents.append(new_pa_doc)
        db.session.commit()

        permittee_start_date = data.get('issue_date'),
        permittee = MinePartyAppointment.create(
            mine.mine_guid,
            data.get('permittee_party_guid'),
            'PMT',
            start_date=permittee_start_date,
            processed_by=self.get_user_info(),
            permit_guid=permit.permit_guid)
        db.session.add(permittee)
        db.session.commit()

        return permit
Exemple #12
0
    def delete(self, party_guid):
        party = Party.find_by_party_guid(party_guid)
        if not party:
            raise NotFound(f'Party guid with "{party_guid}" not found.')

        mine_party_appts = MinePartyAppointment.find_by_party_guid(party_guid)
        for mine_party_appt in mine_party_appts:
            mine_party_appt.deleted_ind = True
            mine_party_appt.save()

        party.deleted_ind = True
        party.save()
        return ('', 204)
Exemple #13
0
    def post(self, party_guid):
        party = Party.find_by_party_guid(party_guid)
        if party is None:
            raise NotFound('Party not found.')

        if PartyOrgBookEntity.find_by_party_guid(party_guid) is not None:
            raise BadRequest(
                'This party is already associated with an OrgBook entity.')

        data = PartyOrgBookEntityListResource.parser.parse_args()
        credential_id = data.get('credential_id')

        if PartyOrgBookEntity.find_by_credential_id(credential_id) is not None:
            raise BadRequest(
                'An OrgBook entity with the provided credential ID already exists.'
            )

        resp = OrgBookService.get_credential(credential_id)
        if resp.status_code != requests.codes.ok:
            raise BadGateway(
                f'OrgBook API responded with {resp.status_code}: {resp.reason}'
            )

        try:
            credential = json.loads(resp.text)
            registration_id = credential['topic']['source_id']
            registration_status = not (credential['inactive'])
            registration_date = credential['effective_date']
            name_id = credential['names'][0]['id']
            name_text = credential['names'][0]['text']
        except:
            raise BadGateway('OrgBook API responded with unexpected data.')

        party_orgbook_entity = PartyOrgBookEntity.create(
            registration_id, registration_status, registration_date, name_id,
            name_text, credential_id, party_guid)
        if not party_orgbook_entity:
            raise InternalServerError(
                'Failed to create the Party OrgBook Entity.')

        party_orgbook_entity.save()

        party.party_name = name_text
        party.save()

        return party_orgbook_entity, 201
Exemple #14
0
def test_party_model_find_by_mine_guid(test_client, auth_headers):
    party = Party.find_by_mine_guid(TEST_MINE_GUID)
    assert str(party.mgr_appointment[0].mine_guid) == TEST_MINE_GUID
Exemple #15
0
def setup_data(session):
    # Clear data
    clear_data(session)

    # Insert Region Code
    for region_code_value, display_order_value in zip(
            TEST_REGION_CODES, TEST_REGION_CODE_DISPLAY_ORDER):
        region_code = MineRegionCode(mine_region_code=region_code_value,
                                     description=TEST_REGION_DESCRIPTION,
                                     display_order=display_order_value,
                                     **DUMMY_USER_KWARGS)
        region_code.save()

    # Insert Mine Tenure Types
    for code, description in zip(TEST_MINE_TENURE_TYPE_CODES,
                                 TEST_MINE_TENURE_TYPE_DESCRIPTIONS):
        mine_tenure_type_code = MineTenureTypeCode(mine_tenure_type_code=code,
                                                   description=description,
                                                   **DUMMY_USER_KWARGS)
        mine_tenure_type_code.save()

    # Insert Mine Disturbance Codes
    for code, description in zip(TEST_MINE_DISTURBANCE_CODES,
                                 TEST_MINE_DISTURBANCE_DESCRIPTIONS):
        mine_disturbance_code = MineDisturbanceCode(mine_disturbance_code=code,
                                                    description=description,
                                                    **DUMMY_USER_KWARGS)
        mine_disturbance_code.save()

    # Insert Mine Commodity Codes
    for code, description in zip(TEST_MINE_COMMODITY_CODES,
                                 TEST_MINE_COMMODITY_DESCRIPTIONS):
        mine_commodity_code = MineCommodityCode(mine_commodity_code=code,
                                                description=description,
                                                **DUMMY_USER_KWARGS)
        mine_commodity_code.save()

    # Test Mine Data
    mine = Mine(mine_guid=uuid.UUID(TEST_MINE_GUID),
                mine_no=TEST_MINE_NO,
                mine_name=TEST_MINE_NAME,
                mine_region=TEST_REGION_CODE,
                **DUMMY_USER_KWARGS)
    mine.save()

    # Test Mine Type
    mine_type = MineType(mine_type_guid=uuid.UUID(TEST_MINE_TYPE_GUID),
                         mine_guid=uuid.UUID(TEST_MINE_GUID),
                         mine_tenure_type_code=TEST_MINE_TENURE_TYPE_CODES[0],
                         active_ind=True,
                         **DUMMY_USER_KWARGS)
    mine_type.save()

    # Test Mine Type Detail
    mine_type_detail = MineTypeDetail(
        mine_type_detail_xref_guid=uuid.UUID(TEST_MINE_TYPE_DETAIL_GUID),
        mine_type_guid=uuid.UUID(TEST_MINE_TYPE_GUID),
        mine_disturbance_code=TEST_MINE_DISTURBANCE_CODES[0],
        active_ind=True,
        **DUMMY_USER_KWARGS)
    mine_type_detail.save()

    # Test Tenure Data
    tenure = MineralTenureXref(
        mineral_tenure_xref_guid=uuid.UUID(TEST_TENURE_GUID),
        mine_guid=uuid.UUID(TEST_MINE_GUID),
        tenure_number_id=TEST_TENURE_ID,
        **DUMMY_USER_KWARGS)
    tenure.save()

    # Test Location Data
    mine_location = MineLocation(
        mine_location_guid=uuid.UUID(TEST_LOCATION_GUID),
        mine_guid=uuid.UUID(TEST_MINE_GUID),
        latitude=TEST_LAT_1,
        longitude=TEST_LONG_1,
        effective_date=datetime.today(),
        expiry_date=datetime.today(),
        **DUMMY_USER_KWARGS)
    mine_location.save()

    # Test Person Type Codes
    for k, v in PARTY_STATUS_CODE.items():
        party_code = PartyTypeCode(party_type_code=v,
                                   description=v,
                                   **DUMMY_USER_KWARGS)
        party_code.save()
    session.commit()

    # Test Party Region Codes
    for code, description in zip(TEST_SUB_DIVISION_CODES,
                                 TEST_SUB_DIVISION_CODE_DESCRIPTIONS):
        sub_division_code = SubDivisionCode(sub_division_code=code,
                                            description=description,
                                            **DUMMY_USER_KWARGS)
        sub_division_code.save()

    # Test Operation Codes
    for k, v in MINE_OPERATION_STATUS.items():
        mine_operation_status_code = MineOperationStatusCode(
            mine_operation_status_code=v['value'],
            description=v['label'],
            **DUMMY_USER_KWARGS)
        mine_operation_status_code.save()
    for k, v in MINE_OPERATION_STATUS_REASON.items():
        mine_operation_status_reason_code = MineOperationStatusReasonCode(
            mine_operation_status_reason_code=v['value'],
            description=v['label'],
            **DUMMY_USER_KWARGS)
        mine_operation_status_reason_code.save()
    for k, v in MINE_OPERATION_STATUS_SUB_REASON.items():
        mine_operation_status_sub_reason_code = MineOperationStatusSubReasonCode(
            mine_operation_status_sub_reason_code=v['value'],
            description=v['label'],
            **DUMMY_USER_KWARGS)
        mine_operation_status_sub_reason_code.save()

    session.commit()

    # Insert Operation Code Xref
    for status_k, status_v in MINE_OPERATION_STATUS.items():
        for reason_k, reason_v in MINE_OPERATION_STATUS_REASON.items():
            for sub_k, sub_v in MINE_OPERATION_STATUS_SUB_REASON.items():
                mine_status_xref = MineStatusXref(
                    mine_status_xref_guid=uuid.uuid4(),
                    mine_operation_status_code=status_v['value'],
                    mine_operation_status_reason_code=reason_v['value'],
                    mine_operation_status_sub_reason_code=sub_v['value'],
                    **DUMMY_USER_KWARGS)
                mine_status_xref.save()

    # Test Person Data
    person = Party(party_guid=uuid.UUID(TEST_PARTY_PER_GUID_1),
                   first_name=TEST_PARTY_PER_FIRST_NAME_1,
                   party_name=TEST_PARTY_PER_PARTY_NAME_1,
                   email=TEST_PARTY_PER_EMAIL_1,
                   phone_no=TEST_PARTY_PER_PHONE_1,
                   phone_ext=TEST_PARTY_PER_PHONE_EXT_1,
                   party_type_code=TEST_PARTY_TYPE,
                   **DUMMY_USER_KWARGS)
    person.save(commit=False)
    person2 = Party(party_guid=uuid.UUID(TEST_PARTY_PER_GUID_2),
                    first_name=TEST_PARTY_PER_FIRST_NAME_2,
                    party_name=TEST_PARTY_PER_PARTY_NAME_2,
                    email=TEST_PARTY_PER_EMAIL_2,
                    phone_no=TEST_PARTY_PER_PHONE_2,
                    phone_ext=TEST_PARTY_PER_PHONE_EXT_2,
                    party_type_code=TEST_PARTY_TYPE,
                    **DUMMY_USER_KWARGS)
    person2.save(commit=False)
    person3 = Party(party_guid=uuid.UUID(TEST_PARTY_PER_GUID_3),
                    first_name=TEST_PARTY_PER_FIRST_NAME_3,
                    party_name=TEST_PARTY_PER_PARTY_NAME_3,
                    email=TEST_PARTY_PER_EMAIL_3,
                    phone_no=TEST_PARTY_PER_PHONE_3,
                    phone_ext=TEST_PARTY_PER_PHONE_EXT_3,
                    party_type_code=TEST_PARTY_TYPE,
                    **DUMMY_USER_KWARGS)
    person3.save(commit=False)
    party_org = Party(party_guid=uuid.UUID(TEST_PARTY_ORG_GUID),
                      party_name=TEST_PARTY_ORG_NAME,
                      email=TEST_PARTY_ORG_EMAIL,
                      phone_no=TEST_PARTY_ORG_PHONE,
                      phone_ext=TEST_PARTY_ORG_EXT,
                      party_type_code=TEST_ORG_TYPE,
                      **DUMMY_USER_KWARGS)
    party_org.save()

    # Test Permit Status Codes
    for permit_code_value in TEST_PERMIT_STATUS_CODES:
        permit_code = PermitStatusCode(
            permit_status_code=permit_code_value,
            description=TEST_PERMIT_STATUS_CODE_NAME_1,
            **DUMMY_USER_KWARGS)
        permit_code.save()

    # Test Permit Data
    permit = Permit(permit_guid=TEST_PERMIT_GUID_1,
                    mine_guid=TEST_MINE_GUID,
                    permit_no=TEST_PERMIT_NO_1,
                    permit_status_code=TEST_PERMIT_STATUS_CODE_1,
                    **DUMMY_USER_KWARGS)
    permit.save()

    permit_amendment_status_code = PermitAmendmentStatusCode(
        permit_amendment_status_code=TEST_PERMIT_AMENDMENT_STATUS_CODE,
        description=TEST_PERMIT_AMENDMENT_STATUS_CODE_NAME,
        **DUMMY_USER_KWARGS)
    permit_amendment_status_code.save()

    permit_amendment_status_code2 = PermitAmendmentStatusCode(
        permit_amendment_status_code=TEST_PERMIT_AMENDMENT_STATUS_CODE_2,
        description=TEST_PERMIT_AMENDMENT_STATUS_CODE_NAME,
        **DUMMY_USER_KWARGS)
    permit_amendment_status_code2.save()

    permit_amendment_type_code = PermitAmendmentTypeCode(
        permit_amendment_type_code=TEST_PERMIT_AMENDMENT_TYPE_CODE,
        description=TEST_PERMIT_AMENDMENT_TYPE_CODE_NAME,
        **DUMMY_USER_KWARGS)
    permit_amendment_type_code.save()

    permit_amendment_type_code2 = PermitAmendmentTypeCode(
        permit_amendment_type_code=TEST_PERMIT_AMENDMENT_TYPE_CODE_2,
        description=TEST_PERMIT_AMENDMENT_TYPE_CODE_NAME,
        **DUMMY_USER_KWARGS)
    permit_amendment_type_code2.save()

    required_document_due_date_type1 = RequiredDocumentDueDateType(
        req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[0],
        req_document_due_date_description=
        TEST_REQUIRED_REPORT_DUE_DATE_DESCRIPTION[0],
        **DUMMY_USER_KWARGS)
    required_document_due_date_type1.save()

    required_document_due_date_type2 = RequiredDocumentDueDateType(
        req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[1],
        req_document_due_date_description=
        TEST_REQUIRED_REPORT_DUE_DATE_DESCRIPTION[1],
        **DUMMY_USER_KWARGS)
    required_document_due_date_type2.save()

    required_document_category1 = RequiredDocumentCategory(
        req_document_category=TEST_REQUIRED_REPORT_CATEGORY_TAILINGS)
    required_document_category1.save()

    required_document_category2 = RequiredDocumentCategory(
        req_document_category='OTH')
    required_document_category2.save()

    required_document1 = RequiredDocument(
        req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID1),
        req_document_name=TEST_REQUIRED_REPORT_NAME1,
        req_document_category=required_document_category1.
        req_document_category,
        req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[0],
        req_document_due_date_period_months=12,
        **DUMMY_USER_KWARGS)
    required_document1.save()

    required_document_sub_category = RequiredDocumentSubCategory(
        req_document_sub_category_code=TEST_REQUIRED_REPORT_SUB_CATEGORY_1)
    required_document_sub_category.save()

    required_document2 = RequiredDocument(
        req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID2),
        req_document_name=TEST_REQUIRED_REPORT_NAME2,
        req_document_category=required_document_category1.
        req_document_category,
        req_document_sub_category_code=required_document_sub_category.
        req_document_sub_category_code,
        req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[0],
        req_document_due_date_period_months=12,
        **DUMMY_USER_KWARGS)
    required_document2.save()

    required_document3 = RequiredDocument(
        req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID3),
        req_document_name=TEST_REQUIRED_REPORT_NAME3,
        req_document_category=required_document_category2.
        req_document_category,
        req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[1],
        req_document_due_date_period_months=12,
        **DUMMY_USER_KWARGS)
    required_document3.save()

    expected_document_status1 = ExpectedDocumentStatus(
        exp_document_status_code=TEST_EXPECTED_DOCUMENT_STATUS_CODE1,
        description="Not Received",
        display_order=10,
        **DUMMY_USER_KWARGS)
    expected_document_status1.save()

    expected_document_status2 = ExpectedDocumentStatus(
        exp_document_status_code=TEST_EXPECTED_DOCUMENT_STATUS_CODE2,
        description="Pending Review",
        display_order=20,
        **DUMMY_USER_KWARGS)
    expected_document_status2.save()

    expected_document1 = MineExpectedDocument(
        exp_document_guid=uuid.UUID(TEST_EXPECTED_DOCUMENT_GUID1),
        req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID1),
        mine_guid=TEST_MINE_GUID,
        exp_document_name=TEST_EXPECTED_DOCUMENT_NAME1,
        due_date=datetime.strptime('1984-06-18', '%Y-%m-%d'),
        received_date=datetime.strptime('1984-06-18', '%Y-%m-%d'),
        exp_document_status_code=expected_document_status1.
        exp_document_status_code,
        **DUMMY_USER_KWARGS)
    expected_document1.save()

    mine_tsf1 = MineTailingsStorageFacility(
        mine_tailings_storage_facility_guid=
        TEST_TAILINGS_STORAGE_FACILITY_GUID1,
        mine_guid=TEST_MINE_GUID,
        mine_tailings_storage_facility_name=
        TEST_TAILINGS_STORAGE_FACILITY_NAME1,
        **DUMMY_USER_KWARGS)
    mine_tsf1.save()

    mpat1 = MinePartyAppointmentType(
        mine_party_appt_type_code=TEST_MINE_PARTY_APPT_TYPE_CODE1,
        description=TEST_MINE_PARTY_APPT_TYPE_DESCRIPTION1,
        grouping_level=2,
        **DUMMY_USER_KWARGS)
    mpat1.save()

    mpat2 = MinePartyAppointmentType(
        mine_party_appt_type_code=TEST_MINE_PARTY_APPT_TYPE_CODE2,
        description=TEST_MINE_PARTY_APPT_TYPE_DESCRIPTION2,
        grouping_level=2,
        **DUMMY_USER_KWARGS)
    mpat2.save()

    mpat3 = MinePartyAppointmentType(mine_party_appt_type_code='EOR',
                                     description='Engineer of Record',
                                     grouping_level=1,
                                     **DUMMY_USER_KWARGS)
    mpat3.save()

    mpat4 = MinePartyAppointmentType(mine_party_appt_type_code='PMT',
                                     description='Engineer of Record',
                                     grouping_level=1,
                                     **DUMMY_USER_KWARGS)
    mpat4.save()

    mpat5 = MinePartyAppointmentType(mine_party_appt_type_code='MMG',
                                     description='Mine Manager',
                                     grouping_level=1,
                                     **DUMMY_USER_KWARGS)
    mpat5.save()

    mine_doc1 = MineDocument(
        mine_guid=uuid.UUID(TEST_MINE_GUID),
        document_name=TEST_MINE_DOCUMENT_NAME1,
        document_manager_guid=TEST_DOCUMENT_MANAGER_FILE_GUID,
        **DUMMY_USER_KWARGS)
    mine_doc1.mine_expected_document.append(expected_document1)
    mine_doc1.save()

    application_status_code_1 = ApplicationStatusCode(
        application_status_code='RIP',
        description='In Review',
        display_order=10,
        **DUMMY_USER_KWARGS)
    application_status_code_1.save()

    application_status_code_2 = ApplicationStatusCode(
        application_status_code='APR',
        description='Approved',
        display_order=20,
        **DUMMY_USER_KWARGS)
    application_status_code_2.save()
Exemple #16
0
def test_party_model_find_by_person_guid(db_session):
    party_guid = PartyFactory(person=True).party_guid

    party = Party.find_by_party_guid(str(party_guid))
    assert party.party_guid == party_guid
Exemple #17
0
def test_party_model_find_by_person_guid(test_client, auth_headers):
    party = Party.find_by_party_guid(TEST_PARTY_PER_GUID_1)
    assert str(party.party_guid) == TEST_PARTY_PER_GUID_1
Exemple #18
0
    def post(self, mine_guid, permit_guid, permit_amendment_guid=None):
        if permit_amendment_guid:
            raise BadRequest('Unexpected permit_amendement_guid.')

        permit = Permit.find_by_permit_guid(permit_guid)
        if not permit:
            raise NotFound('Permit does not exist.')

        if not str(permit.mine_guid) == mine_guid:
            raise BadRequest('Permits mine_guid and provided mine_guid mismatch.')

        data = self.parser.parse_args()
        current_app.logger.info(f'creating permit_amendment with >> {data}')

        party = Party.find_by_party_guid(data.get('permittee_party_guid'))
        if not party:
            raise NotFound('Party not found')

        permittees = MinePartyAppointment.find_by_permit_guid(permit_guid)
        if not permittees:
            raise NotFound('Party appointments not found')

        permit_issue_datetime = data.get('issue_date')
        # convert permit_issue_date to a date object to compare with permittee start_date,
        #Both dates are stored in the DB as Dates, and are being converted to SQLAlchemy dateTimes in the modals, but for some reason being returned as Python Dates.
        permit_issue_date = datetime.date(permit_issue_datetime)
        is_historical_permit = False

        new_end_dates = MinePartyAppointment.find_appointment_end_dates(
            permit_guid, permit_issue_date)

        for permittee in permittees:
            # check if the new appointment is older than the current appointment, if so create a new permittee appointment
            if permittee.start_date > permit_issue_date:
                is_historical_permit = True
            else:
                # if the amendment is the newest, change the end dates of the other appointments
                position = new_end_dates.index(permittee.start_date)
                if new_end_dates.index(permittee.start_date) == 0:
                    permittee.save()
                else:
                    permittee.end_date = new_end_dates[position - 1]
                    permittee.save()

        permittee_start_date = permit_issue_date
        position = new_end_dates.index(permit_issue_date)
        permittee_end_date = new_end_dates[position - 1] if is_historical_permit else None

        # create a new appointment, so every amendment is associated with a permittee
        new_permittee = MinePartyAppointment.create(
            permit.mine_guid,
            data.get('permittee_party_guid'),
            'PMT',
            self.get_user_info(),
            start_date=permittee_start_date,
            end_date=permittee_end_date,
            permit_guid=permit_guid)

        new_permittee.save()
        new_pa = PermitAmendment.create(
            permit,
            data.get('received_date'),
            data.get('issue_date'),
            data.get('authorization_end_date'),
            data.get('permit_amendment_type_code', 'AMD'),
            description=data.get('description'))

        uploadedFiles = data.get('uploadedFiles', [])
        for newFile in uploadedFiles:
            new_pa_doc = PermitAmendmentDocument(
                document_name=newFile['fileName'],
                document_manager_guid=newFile['document_manager_guid'],
                mine_guid=permit.mine_guid,
            )
            new_pa.related_documents.append(new_pa_doc)

        new_pa.save()
        return new_pa
Exemple #19
0
def setup_data(session):
    # Clear data
    clear_data(session)

    # Insert Region Code
    for region_code_value, display_order_value in zip(
            TEST_REGION_CODES, TEST_REGION_CODE_DISPLAY_ORDER):
        region_code = MineRegionCode(mine_region_code=region_code_value,
                                     description=TEST_REGION_DESCRIPTION,
                                     display_order=display_order_value,
                                     **DUMMY_USER_KWARGS)
        region_code.save()

    # Insert Mine Tenure Types
    for code, description in zip(TEST_MINE_TENURE_TYPE_CODES,
                                 TEST_MINE_TENURE_TYPE_DESCRIPTIONS):
        mine_tenure_type_code = MineTenureTypeCode(mine_tenure_type_code=code,
                                                   description=description,
                                                   **DUMMY_USER_KWARGS)
        mine_tenure_type_code.save()

    # Insert Mine Disturbance Codes
    for code, description in zip(TEST_MINE_DISTURBANCE_CODES,
                                 TEST_MINE_DISTURBANCE_DESCRIPTIONS):
        mine_disturbance_code = MineDisturbanceCode(mine_disturbance_code=code,
                                                    description=description,
                                                    **DUMMY_USER_KWARGS)
        mine_disturbance_code.save()

    # Insert Mine Commodity Codes
    for code, description in zip(TEST_MINE_COMMODITY_CODES,
                                 TEST_MINE_COMMODITY_DESCRIPTIONS):
        mine_commodity_code = MineCommodityCode(mine_commodity_code=code,
                                                description=description,
                                                **DUMMY_USER_KWARGS)
        mine_commodity_code.save()

    # Test Mine Data
    mine_identity = MineIdentity(mine_guid=uuid.UUID(TEST_MINE_GUID),
                                 **DUMMY_USER_KWARGS)
    mine_detail = MineDetail(mine_detail_guid=uuid.UUID(TEST_MINE_DETAIL_GUID),
                             mine_guid=uuid.UUID(TEST_MINE_GUID),
                             mine_no=TEST_MINE_NO,
                             mine_name=TEST_MINE_NAME,
                             mine_region=TEST_REGION_CODE,
                             **DUMMY_USER_KWARGS)
    mine_identity.save()
    mine_detail.save()

    # Test Mine Type
    mine_type = MineType(mine_type_guid=uuid.UUID(TEST_MINE_TYPE_GUID),
                         mine_guid=uuid.UUID(TEST_MINE_GUID),
                         mine_tenure_type_code=TEST_MINE_TENURE_TYPE_CODES[0],
                         active_ind=True,
                         **DUMMY_USER_KWARGS)
    mine_type.save()

    # Test Mine Type Detail
    mine_type_detail = MineTypeDetail(
        mine_type_detail_xref_guid=uuid.UUID(TEST_MINE_TYPE_DETAIL_GUID),
        mine_type_guid=uuid.UUID(TEST_MINE_TYPE_GUID),
        mine_disturbance_code=TEST_MINE_DISTURBANCE_CODES[0],
        active_ind=True,
        **DUMMY_USER_KWARGS)
    mine_type_detail.save()

    # Test Tenure Data
    tenure = MineralTenureXref(
        mineral_tenure_xref_guid=uuid.UUID(TEST_TENURE_GUID),
        mine_guid=uuid.UUID(TEST_MINE_GUID),
        tenure_number_id=TEST_TENURE_ID,
        **DUMMY_USER_KWARGS)
    tenure.save()

    # Test Location Data
    mine_location = MineLocation(
        mine_location_guid=uuid.UUID(TEST_LOCATION_GUID),
        mine_guid=uuid.UUID(TEST_MINE_GUID),
        latitude=TEST_LAT_1,
        longitude=TEST_LONG_1,
        effective_date=datetime.today(),
        expiry_date=datetime.today(),
        **DUMMY_USER_KWARGS)
    mine_location.save()

    # Test Person Type Codes
    for k, v in PARTY_STATUS_CODE.items():
        party_code = PartyTypeCode(party_type_code=v,
                                   description=v,
                                   **DUMMY_USER_KWARGS)
        party_code.save()
    session.commit()

    # Test Operation Codes
    for k, v in MINE_OPERATION_STATUS.items():
        mine_operation_status_code = MineOperationStatusCode(
            mine_operation_status_code=v['value'],
            description=v['label'],
            **DUMMY_USER_KWARGS)
        mine_operation_status_code.save()
    for k, v in MINE_OPERATION_STATUS_REASON.items():
        mine_operation_status_reason_code = MineOperationStatusReasonCode(
            mine_operation_status_reason_code=v['value'],
            description=v['label'],
            **DUMMY_USER_KWARGS)
        mine_operation_status_reason_code.save()
    for k, v in MINE_OPERATION_STATUS_SUB_REASON.items():
        mine_operation_status_sub_reason_code = MineOperationStatusSubReasonCode(
            mine_operation_status_sub_reason_code=v['value'],
            description=v['label'],
            **DUMMY_USER_KWARGS)
        mine_operation_status_sub_reason_code.save()

    session.commit()

    # Test Person Data
    person = Party(party_guid=uuid.UUID(TEST_PARTY_PER_GUID_1),
                   first_name=TEST_PARTY_PER_FIRST_NAME_1,
                   party_name=TEST_PARTY_PER_PARTY_NAME_1,
                   email=TEST_PARTY_PER_EMAIL_1,
                   phone_no=TEST_PARTY_PER_PHONE_1,
                   phone_ext=TEST_PARTY_PER_PHONE_EXT_1,
                   party_type_code=TEST_PARTY_TYPE,
                   **DUMMY_USER_KWARGS)
    person.save(commit=False)
    person2 = Party(party_guid=uuid.UUID(TEST_PARTY_PER_GUID_2),
                    first_name=TEST_PARTY_PER_FIRST_NAME_2,
                    party_name=TEST_PARTY_PER_PARTY_NAME_2,
                    email=TEST_PARTY_PER_EMAIL_2,
                    phone_no=TEST_PARTY_PER_PHONE_2,
                    phone_ext=TEST_PARTY_PER_PHONE_EXT_2,
                    party_type_code=TEST_PARTY_TYPE,
                    **DUMMY_USER_KWARGS)
    person2.save(commit=False)
    person3 = Party(party_guid=uuid.UUID(TEST_PARTY_PER_GUID_3),
                    first_name=TEST_PARTY_PER_FIRST_NAME_3,
                    party_name=TEST_PARTY_PER_PARTY_NAME_3,
                    email=TEST_PARTY_PER_EMAIL_3,
                    phone_no=TEST_PARTY_PER_PHONE_3,
                    phone_ext=TEST_PARTY_PER_PHONE_EXT_3,
                    party_type_code=TEST_PARTY_TYPE,
                    **DUMMY_USER_KWARGS)
    person3.save(commit=False)
    party_org = Party(party_guid=uuid.UUID(TEST_PARTY_ORG_GUID),
                      party_name=TEST_PARTY_ORG_NAME,
                      email=TEST_PARTY_ORG_EMAIL,
                      phone_no=TEST_PARTY_ORG_PHONE,
                      phone_ext=TEST_PARTY_ORG_EXT,
                      party_type_code=TEST_ORG_TYPE,
                      **DUMMY_USER_KWARGS)
    party_org.save()
    # Test Manager Data
    manager = MgrAppointment(mgr_appointment_guid=uuid.UUID(TEST_MANAGER_GUID),
                             party_guid=uuid.UUID(TEST_PARTY_PER_GUID_1),
                             mine_guid=uuid.UUID(TEST_MINE_GUID),
                             effective_date=datetime.today() -
                             timedelta(days=10),
                             **DUMMY_USER_KWARGS)
    manager.save()

    # Test Permit Status Codes
    for permit_code_value in TEST_PERMIT_STATUS_CODES:
        permit_code = PermitStatusCode(
            permit_status_code=permit_code_value,
            description=TEST_PERMIT_STATUS_CODE_NAME_1,
            **DUMMY_USER_KWARGS)
        permit_code.save()

    # Test Permit Data
    permit = Permit(permit_guid=TEST_PERMIT_GUID_1,
                    mine_guid=TEST_MINE_GUID,
                    permit_no=TEST_PERMIT_NO_1,
                    permit_status_code=TEST_PERMIT_STATUS_CODE_1,
                    received_date=datetime.today(),
                    issue_date=datetime.today(),
                    **DUMMY_USER_KWARGS)
    permit.save()

    # Test Permittee Data
    permittee = Permittee(permittee_guid=uuid.UUID(TEST_PERMITTEE_GUID),
                          permit_guid=uuid.UUID(TEST_PERMIT_GUID_1),
                          party_guid=uuid.UUID(TEST_PARTY_PER_GUID_1),
                          **DUMMY_USER_KWARGS)
    permittee.save()

    required_document_due_date_type1 = RequiredDocumentDueDateType(
        req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[0],
        req_document_due_date_description=
        TEST_REQUIRED_REPORT_DUE_DATE_DESCRIPTION[0],
        **DUMMY_USER_KWARGS)
    required_document_due_date_type1.save()

    required_document_due_date_type2 = RequiredDocumentDueDateType(
        req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[1],
        req_document_due_date_description=
        TEST_REQUIRED_REPORT_DUE_DATE_DESCRIPTION[1],
        **DUMMY_USER_KWARGS)
    required_document_due_date_type2.save()

    required_document_category1 = RequiredDocumentCategory(
        req_document_category_guid=TEST_REQUIRED_REPORT_CATEGORY_TAILINGS_GUID,
        req_document_category=TEST_REQUIRED_REPORT_CATEGORY_TAILINGS)
    required_document_category1.save()

    required_document_category2 = RequiredDocumentCategory(
        req_document_category_guid=TEST_REQUIRED_REPORT_CATEGORY_OTHER_GUID,
        req_document_category=TEST_REQUIRED_REPORT_CATEGORY_OTHER)
    required_document_category2.save()

    required_document1 = RequiredDocument(
        req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID1),
        req_document_name=TEST_REQUIRED_REPORT_NAME1,
        req_document_category_guid=TEST_REQUIRED_REPORT_CATEGORY_TAILINGS_GUID,
        req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[0],
        req_document_due_date_period_months=12,
        **DUMMY_USER_KWARGS)
    required_document1.save()

    required_document2 = RequiredDocument(
        req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID2),
        req_document_name=TEST_REQUIRED_REPORT_NAME2,
        req_document_category_guid=TEST_REQUIRED_REPORT_CATEGORY_TAILINGS_GUID,
        req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[0],
        req_document_due_date_period_months=12,
        **DUMMY_USER_KWARGS)
    required_document2.save()

    required_document3 = RequiredDocument(
        req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID3),
        req_document_name=TEST_REQUIRED_REPORT_NAME3,
        req_document_category_guid=TEST_REQUIRED_REPORT_CATEGORY_OTHER_GUID,
        req_document_due_date_type=TEST_REQUIRED_REPORT_DUE_DATE_TYPE[1],
        req_document_due_date_period_months=12,
        **DUMMY_USER_KWARGS)
    required_document3.save()

    expected_document1 = MineExpectedDocument(
        exp_document_guid=uuid.UUID(TEST_EXPECTED_DOCUMENT_GUID1),
        req_document_guid=uuid.UUID(TEST_REQUIRED_REPORT_GUID1),
        mine_guid=TEST_MINE_GUID,
        exp_document_name=TEST_EXPECTED_DOCUMENT_NAME1,
        due_date=datetime.strptime('1984-06-18', '%Y-%m-%d'),
        received_date=datetime.strptime('1984-06-18', '%Y-%m-%d'),
        **DUMMY_USER_KWARGS)
    expected_document1.save()

    mine_tsf1 = MineTailingsStorageFacility(
        mine_tailings_storage_facility_guid=
        TEST_TAILINGS_STORAGE_FACILITY_GUID1,
        mine_guid=TEST_MINE_GUID,
        mine_tailings_storage_facility_name=
        TEST_TAILINGS_STORAGE_FACILITY_NAME1,
        **DUMMY_USER_KWARGS)
    mine_tsf1.save()

    mpat1 = MinePartyAppointmentType(
        mine_party_appt_type_code=TEST_MINE_PARTY_APPT_TYPE_CODE1,
        description=TEST_MINE_PARTY_APPT_TYPE_DESCRIPTION1,
        **DUMMY_USER_KWARGS)
    mpat1.save()

    mpat2 = MinePartyAppointmentType(
        mine_party_appt_type_code=TEST_MINE_PARTY_APPT_TYPE_CODE2,
        description=TEST_MINE_PARTY_APPT_TYPE_DESCRIPTION2,
        **DUMMY_USER_KWARGS)
    mpat2.save()

    mpat3 = MinePartyAppointmentType(mine_party_appt_type_code='EOR',
                                     description='Engineer of Record',
                                     **DUMMY_USER_KWARGS)
    mpat3.save()

    mpa = MinePartyAppointment(
        mine_party_appt_guid=TEST_MINE_PARTY_APPT_GUID,
        mine_guid=uuid.UUID(TEST_MINE_GUID),
        party_guid=uuid.UUID(TEST_PARTY_PER_GUID_1),
        mine_party_appt_type_code=TEST_MINE_PARTY_APPT_TYPE_CODE1,
        **DUMMY_USER_KWARGS)
    mpa.save()

    mine_doc1 = MineDocument(
        mine_guid=uuid.UUID(TEST_MINE_GUID),
        document_name=TEST_MINE_DOCUMENT_NAME1,
        document_manager_guid=TEST_DOCUMENT_MANAGER_FILE_GUID,
        **DUMMY_USER_KWARGS)
    mine_doc1.mine_expected_document.append(expected_document1)
    mine_doc1.save()
Exemple #20
0
def test_party_model_find_by_party_name(db_session):
    party = PartyFactory(company=True)

    party_org = Party.find_by_name(party.party_name)
    assert party_org.party_name == party.party_name
Exemple #21
0
def test_party_model_find_by_mgr_appointment(test_client, auth_headers):
    party = Party.find_by_mgr_appointment(TEST_MANAGER_GUID)
    assert str(
        party.mgr_appointment[0].mgr_appointment_guid) == TEST_MANAGER_GUID
Exemple #22
0
    def post(self, permit_guid=None, permit_amendment_guid=None):
        if not permit_guid:
            return self.create_error_payload(
                400, 'Permit_guid must be provided'), 400
        if permit_amendment_guid:
            return self.create_error_payload(
                400, 'unexpected permit_amendement_id'), 400

        permit = Permit.find_by_permit_guid(permit_guid)
        if not permit:
            return self.create_error_payload(404, 'permit does not exist'), 404

        data = self.parser.parse_args()
        current_app.logger.info(f'creating permit_amendment with >> {data}')

        received_date = data.get('received_date')
        issue_date = data.get('issue_date')
        authorization_end_date = data.get('authorization_end_date')
        permit_amendment_type_code = data.get('permit_amendment_type_code',
                                              'AMD')
        description = data.get('description')
        uploadedFiles = data.get('uploadedFiles', [])

        party = Party.find_by_party_guid(data.get('permittee_party_guid'))
        if not party:
            raise NotFound('Party not found')

        party_is_active_permittee = False

        permittees = MinePartyAppointment.find_by_permit_guid(permit_guid)

        for permittee in permittees:
            if permittee.end_date is None:
                if permittee.party_guid == party.party_guid:
                    party_is_active_permittee = True
                else:  # inactive old permittees
                    permittee.end_date = datetime.utcnow()
                    permittee.save()

        if not party_is_active_permittee:
            new_permittee = MinePartyAppointment.create(
                permit.mine_guid, data.get('permittee_party_guid'), 'PMT',
                datetime.utcnow(), None, self.get_user_info(), permit_guid,
                True)
            new_permittee.save()

        try:
            new_pa = PermitAmendment.create(permit,
                                            received_date,
                                            issue_date,
                                            authorization_end_date,
                                            permit_amendment_type_code,
                                            description=description)

            for newFile in uploadedFiles:
                new_pa_doc = PermitAmendmentDocument(
                    document_name=newFile['fileName'],
                    document_manager_guid=newFile['document_manager_guid'],
                    mine_guid=permit.mine_guid,
                )
                new_pa.documents.append(new_pa_doc)
            new_pa.save()
        except Exception as e:
            return self.create_error_payload(500, 'Error: {}'.format(e)), 500
        return new_pa.json()
Exemple #23
0
    def get(self, party_guid):
        party = Party.find_by_party_guid(party_guid)
        if not party:
            raise NotFound('Party not found')

        return party
Exemple #24
0
def test_person_model_find_by_name(test_client, auth_headers):
    party = Party.find_by_name(TEST_PARTY_PER_FIRST_NAME_1,
                               TEST_PARTY_PER_PARTY_NAME_1)
    assert party.first_name == TEST_PARTY_PER_FIRST_NAME_1
    assert party.party_name == TEST_PARTY_PER_PARTY_NAME_1
Exemple #25
0
def test_person_model_find_by_party_name(test_client, auth_headers):
    party_org = Party.find_by_party_name(TEST_PARTY_ORG_NAME)
    assert party_org.party_name == TEST_PARTY_ORG_NAME
Exemple #26
0
def test_person_model_find_by_name(db_session):
    party = PartyFactory(person=True)

    found_party = Party.find_by_name(party.party_name, party.first_name)
    assert found_party.first_name == party.first_name
    assert found_party.party_name == party.party_name