Пример #1
0
def setup_info(test_client):
    permit = Permit.find_by_permit_guid(TEST_PERMIT_GUID_1)

    test_pa = PermitAmendment.create(permit, None, None, None, 'AMD')
    test_pa.save()

    test_pa_doc = PermitAmendmentDocument(
        document_name="test1.pdf",
        mine_guid=TEST_MINE_GUID,
        permit_amendment_id=test_pa.permit_amendment_id,
        document_manager_guid=TEST_DOCUMENT_MANAGER_GUID_1)
    test_pa_doc.save()

    test_orphan_doc = PermitAmendmentDocument(
        document_name="orphan.pdf",
        mine_guid=TEST_MINE_GUID,
        permit_amendment_id=None,
        document_manager_guid=TEST_DOCUMENT_MANAGER_GUID_2)
    test_orphan_doc.save()

    yield {
        'permit_amendment_1': test_pa,
        'permit_amendment_document_1': test_pa_doc,
        'test_orphan_document_1': test_orphan_doc
    }

    db.session.delete(test_pa)
    db.session.delete(test_pa_doc)
    db.session.delete(test_orphan_doc)
    try:
        #it may have been deleted by the test that executed, don't freak out.
        db.session.commit()
    except:
        pass
Пример #2
0
def setup_info(test_client):
    test_permit_no = 'mx-test-231'
    mine_1 = Mine.create_mine('1234567', 'TestMine', True, 'SW', DUMMY_USER_KWARGS)
    mine_2 = Mine.create_mine('7654321', 'TestingMine', True, 'NW', DUMMY_USER_KWARGS)
    mine_1.save()
    mine_2.save()

    permit = Permit.create(mine_2.mine_guid, test_permit_no, 'O')
    permit.save()

    MINE_1_GUID = str(mine_1.mine_guid)
    MINE_2_GUID = str(mine_2.mine_guid)
    MINE_2_PERMIT_GUID = str(permit.permit_guid)
    NON_EXISTENT_GUID = '8ef23184-02c4-4472-a912-380b5a0d9cae'

    yield dict(
        mine_1_guid=MINE_1_GUID,
        mine_2_guid=MINE_2_GUID,
        mine_2_permit_guid=MINE_2_PERMIT_GUID,
        bad_guid=NON_EXISTENT_GUID,
        in_use_permit_no=test_permit_no)

    db.session.query(PermitAmendment).delete()
    db.session.commit()
    db.session.query(Permit).delete()
    db.session.commit()
    db.session.delete(mine_1)
    db.session.delete(mine_2)
    db.session.commit()
Пример #3
0
def test_permit_model_validate_permit_no_max_char(test_client, auth_headers):
    with pytest.raises(AssertionError) as e:
        Permit(permit_guid=uuid.uuid4(),
               mine_guid=uuid.uuid4(),
               permit_no=''.join(['{}'.format(x) for x in range(17)]),
               permit_status_code='O',
               received_date=datetime.today(),
               issue_date=datetime.today())
    assert 'Permit number must not exceed 16 characters.' in str(e.value)
Пример #4
0
def test_permit_model_validate_permit_no(test_client, auth_headers):
    with pytest.raises(AssertionError) as e:
        Permit(permit_guid=uuid.uuid4(),
               mine_guid=uuid.uuid4(),
               permit_no='',
               permit_status_code='O',
               received_date=datetime.today(),
               issue_date=datetime.today())
    assert 'Permit number is not provided.' in str(e.value)
Пример #5
0
def test_permit_model_validate_status_code(test_client, auth_headers):
    with pytest.raises(AssertionError) as e:
        Permit(permit_guid=uuid.uuid4(),
               mine_guid=uuid.uuid4(),
               permit_no=''.join(['{}'.format(x) for x in range(11)]),
               permit_status_code='',
               received_date=datetime.today(),
               issue_date=datetime.today())
    assert 'Permit status code is not provided.' in str(e.value)
Пример #6
0
def test_permit_model_validate_status_code():
    with pytest.raises(AssertionError) as e:
        Permit(permit_guid=uuid.uuid4(),
               mine_guid=uuid.uuid4(),
               permit_no='6' * 11,
               permit_status_code='',
               received_date=datetime.today(),
               issue_date=datetime.today())
    assert 'Permit status code is not provided.' in str(e.value)
Пример #7
0
def test_permit_model_validate_permit_no_max_char():
    with pytest.raises(AssertionError) as e:
        Permit(permit_guid=uuid.uuid4(),
               mine_guid=uuid.uuid4(),
               permit_no='6' * 17,
               permit_status_code='O',
               received_date=datetime.today(),
               issue_date=datetime.today())
    assert 'Permit number must not exceed 16 characters.' in str(e.value)
Пример #8
0
def test_permit_model_validate_issue_date(test_client, auth_headers):
    with pytest.raises(AssertionError) as e:
        Permit(permit_guid=uuid.uuid4(),
               mine_guid=uuid.uuid4(),
               permit_no=''.join(['{}'.format(x) for x in range(7)]),
               permit_status_code='O',
               received_date=datetime.today(),
               issue_date=datetime.today() + timedelta(days=1))
    assert 'Permit issue date cannot be set to the future.' in str(e.value)
Пример #9
0
def test_post_permit_with_duplicate_permit_no(test_client, setup_info,
                                              auth_headers):
    permit = Permit.find_by_permit_guid(setup_info.get('mine_2_permit_guid'))
    data = {
        'mine_guid': setup_info.get('mine_1_guid'),
        'permit_no': permit.permit_no
    }
    post_resp = test_client.post('/permits',
                                 headers=auth_headers['full_auth_header'],
                                 json=data)

    assert post_resp.status_code == 400
Пример #10
0
def test_put_permit(test_client, setup_info, auth_headers):
    permit_guid = setup_info.get('mine_2_permit_guid')
    permit = Permit.find_by_permit_guid(permit_guid)
    old_permit_status = permit.permit_status_code
    data = {'permit_status_code': 'C'}
    put_resp = test_client.put(
        '/permits/' + permit_guid, headers=auth_headers['full_auth_header'], json=data)

    put_data = json.loads(put_resp.data.decode())

    assert put_resp.status_code == 200
    assert put_data.get('permit_status_code') == 'C'
    assert put_data.get('permit_status_code') != old_permit_status
def setup_info(test_client):
    permit = Permit.find_by_permit_guid(TEST_PERMIT_GUID_1)

    test_pa = PermitAmendment.create(permit, None, None, None, 'AMD')
    test_pa.save()

    yield {'permit_1': permit, 'permit_amendment_1': test_pa}

    db.session.delete(test_pa)
    try:
        #it may have been deleted by the test that executed, don't freak out.
        db.session.commit()
    except:
        pass
Пример #12
0
def test_permit_model_find_by_mine_guid(test_client, auth_headers):
    permit = Permit.find_by_mine_guid(TEST_MINE_GUID)
    assert str(permit[0].mine_guid) == TEST_MINE_GUID
Пример #13
0
def test_permit_model_find_by_permit_guid(test_client, auth_headers):
    permit = Permit.find_by_permit_guid(TEST_PERMIT_GUID_1)
    assert str(permit.permit_guid) == TEST_PERMIT_GUID_1
Пример #14
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()
Пример #15
0
def test_permit_model_find_by_permit_guid(db_session):
    permit_guid = PermitFactory().permit_guid

    permit = Permit.find_by_permit_guid(str(permit_guid))
    assert permit.permit_guid == permit_guid
Пример #16
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()
Пример #17
0
def test_permit_model_find_by_mine_guid(db_session):
    mine_guid = MineFactory(mine_permit=1).mine_guid

    permits = Permit.find_by_mine_guid(str(mine_guid))
    assert permits[0].mine_guid == mine_guid