Example #1
0
def setup_info(db_session):
    mine = MineFactory()
    eor = MinePartyAppointmentFactory(mine=mine, mine_party_appt_type_code='EOR')
    mine_manager = MinePartyAppointmentFactory(mine=mine, mine_party_appt_type_code='MMG')
    permitee = MinePartyAppointmentFactory(
        mine=mine, mine_party_appt_type_code='PMT', party__company=True)

    yield dict(
        mine_guid=str(mine.mine_guid),
        eor_party_guid=str(eor.party.party_guid),
        mine_manager_appt_guid=str(mine_manager.mine_party_appt_guid),
        tsf_guid=str(
            mine.mine_tailings_storage_facilities[0].mine_tailings_storage_facility_guid))
def test_post_permit_amendment_with_date_params(test_client, db_session, auth_headers):
    permit = PermitFactory()
    permit_guid = permit.permit_guid
    #TODO Figure out how to make permit factory make it's own initial permittee
    permittee = MinePartyAppointmentFactory(
        permit_guid=permit_guid, mine_party_appt_type_code='PMT', mine=permit.mine)
    party_guid = PartyFactory(company=True).party_guid
    data = {
        'permittee_party_guid': party_guid,
        'received_date': datetime.today().date().isoformat(),
        'issue_date': datetime.today().date().isoformat(),
        'authorization_end_date': (datetime.today() + timedelta(days=1)).date().isoformat(),
    }

    post_resp = test_client.post(
        f'/mines/{permit.mine_guid}/permits/{permit_guid}/amendments',
        json=data,
        headers=auth_headers['full_auth_header'])
    post_data = json.loads(post_resp.data.decode())

    assert post_resp.status_code == 200, post_resp.response
    #assert post_data['permit_guid'] == str(permit_guid), str(post_data)
    assert parser.parse(post_data['received_date']) == parser.parse(data['received_date'])
    assert parser.parse(post_data['issue_date']) == parser.parse(data['issue_date'])
    assert parser.parse(post_data['authorization_end_date']) == parser.parse(
        data['authorization_end_date'])
    assert permit.permittee_appointments[0].party_guid == party_guid

    #permit_amdendment is actually in db
    assert PermitAmendment.find_by_permit_amendment_guid(post_data['permit_amendment_guid'])
def setup_info(db_session):
    mine = MineFactory()
    existing_mine_manager = MinePartyAppointmentFactory(
        mine=mine,
        mine_party_appt_type_code='MMG',
        start_date=datetime.today(),
        end_date=datetime.today() + APPT_LENGTH)
    moving_mine_manager = MinePartyAppointmentFactory(
        mine=mine,
        mine_party_appt_type_code='MMG',
        start_date=datetime.today() + timedelta(days=500),
        end_date=datetime.today() + timedelta(days=500))

    yield dict(mine_guid=str(mine.mine_guid),
               party_guid=str(existing_mine_manager.party.party_guid),
               existing_mine_manager=existing_mine_manager,
               moving_mine_manager=moving_mine_manager)
Example #4
0
def test_permittee_model_find_by_permit_guid(test_client, db_session,
                                             auth_headers):
    appt_guid = MinePartyAppointmentFactory(
        mine_party_appt_type_code='PMT').mine_party_appt_guid

    permittee = MinePartyAppointment.find_by_mine_party_appt_guid(
        str(appt_guid))
    assert permittee.mine_party_appt_guid == appt_guid
def test_get_permittee(test_client, db_session, auth_headers):
    appt_guid = MinePartyAppointmentFactory(mine_party_appt_type_code='PMT').mine_party_appt_guid

    get_resp = test_client.get(
        f'/parties/mines/{appt_guid}', headers=auth_headers['full_auth_header'])
    get_data = json.loads(get_resp.data.decode())
    assert get_resp.status_code == 200, str(get_resp.response)
    assert get_data['mine_party_appt_guid'] == str(appt_guid)
    assert get_data['mine_party_appt_type_code'] == 'PMT'
Example #6
0
 def _create_data(num):
     User._test_mode = True
     with app.app_context():
         for _ in range(int(num)):
             mine = MineFactory()
             eor = MinePartyAppointmentFactory(
                 mine=mine, mine_party_appt_type_code='EOR')
             mine_manager = MinePartyAppointmentFactory(
                 mine=mine, mine_party_appt_type_code='MMG')
             permitee = MinePartyAppointmentFactory(
                 mine=mine,
                 mine_party_appt_type_code='PMT',
                 party__company=True)
         try:
             db.session.commit()
             print(f'Created {num} random mines with related data.')
         except DBAPIError:
             db.session.rollback()
             raise
    def test_put_file(self, test_client, db_session, auth_headers):
        """Should associate the MineDocument with the MinePartyAppointment and return 200"""

        mine = MineFactory()
        mpa = MinePartyAppointmentFactory(mine=mine)
        document_count = len(mpa.documents)
        data = {
            'document_manager_guid': uuid.uuid4(),
            'document_name': 'my_document.pdf'
        }

        put_resp = test_client.put(
            f'/mines/{mine.mine_guid}/party-appts/{mpa.mine_party_appt_guid}/documents',
            headers=auth_headers['full_auth_header'],
            data=data)
        put_data = json.loads(put_resp.data.decode())
        assert put_resp.status_code == 200, put_resp.response
        assert len(put_data['documents']) == document_count + 1
def test_party_appt_model_find_by_party_guid(db_session):
    party_guid = MinePartyAppointmentFactory().party.party_guid

    mpas = MinePartyAppointment.find_by_party_guid(str(party_guid))
    assert len(mpas) == 1
    assert mpas[0].party_guid == party_guid
def test_mine_party_appt_to_csv(db_session):
    mpa = MinePartyAppointmentFactory()

    csv = MinePartyAppointment.to_csv([mpa], ['processed_by', 'processed_on'])
    second_row = str(mpa.processed_by) + ',' + str(mpa.processed_on)
    assert csv == "processed_by,processed_on\n" + second_row
def test_party_appt_model_find_by(db_session):
    batch_size = 3
    MinePartyAppointmentFactory.create_batch(size=batch_size)

    mine_party_appts = MinePartyAppointment.find_by()
    assert len(mine_party_appts) == batch_size