Ejemplo n.º 1
0
def test_permit_amendment_model_find_by_permit_id(db_session):
    batch_size = 3
    permit_id = PermitFactory(permit_amendments=batch_size).permit_id

    permit_amendments = PermitAmendment.find_by_permit_id(permit_id)
    assert len(permit_amendments) == batch_size
    assert all(pa.permit_id == permit_id for pa in permit_amendments)
Ejemplo n.º 2
0
def test_post_permit_amendment_with_date_params(test_client, db_session,
                                                auth_headers):
    permit_guid = PermitFactory().permit_guid
    party_guid = PartyFactory(company=True).party_guid

    data = {
        'permittee_party_guid':
        party_guid,
        'received_date':
        datetime.today().strftime('%Y-%m-%d'),
        'issue_date':
        datetime.today().strftime('%Y-%m-%d'),
        'authorization_end_date':
        (datetime.today() + timedelta(days=1)).strftime('%Y-%m-%d')
    }

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

    permittees = MinePartyAppointment.find_by_permit_guid(permit_guid)

    assert post_resp.status_code == 200, post_resp.response
    assert post_data['permit_guid'] == str(permit_guid), str(post_data)
    assert post_data['received_date'] == data['received_date']
    assert post_data['issue_date'] == data['issue_date']
    assert post_data['authorization_end_date'] == data[
        'authorization_end_date']
    assert permittees[0].party_guid == party_guid

    #permit_amdendment is actually in db
    assert PermitAmendment.find_by_permit_amendment_guid(
        post_data['permit_amendment_guid'])
Ejemplo n.º 3
0
def test_delete_permit_amendment(test_client, db_session, auth_headers):
    am_guid = PermitAmendmentFactory().permit_amendment_guid

    del_resp = test_client.delete(f'/permits/amendments/{am_guid}',
                                  headers=auth_headers['full_auth_header'])
    assert del_resp.status_code == 204, del_resp
    assert PermitAmendment.find_by_permit_amendment_guid(str(am_guid)) is None
Ejemplo n.º 4
0
def test_permit_amendment_model_find_by_permit_amendment_id(db_session):
    permit = PermitFactory(permit_amendments=1)

    permit_amendment = PermitAmendment.find_by_permit_amendment_id(
        permit.permit_amendments[0].permit_amendment_id)
    assert permit_amendment.permit_amendment_id == permit.permit_amendments[
        0].permit_amendment_id
Ejemplo n.º 5
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
Ejemplo n.º 6
0
def test_permit_amendment_model_validate_type_code():
    with pytest.raises(AssertionError) as e:
        PermitAmendment(permit_amendment_guid=uuid.uuid4(),
                        permit_id=0,
                        permit_amendment_status_code='A',
                        permit_amendment_type_code='',
                        received_date=datetime.today(),
                        issue_date=datetime.today(),
                        authorization_end_date=datetime.today())
    assert 'Permit amendment type code is not provided.' in str(e.value)
def test_permit_amendment_model_validate_status_code(test_client, auth_headers,
                                                     setup_info):
    with pytest.raises(AssertionError) as e:
        PermitAmendment(permit_amendment_guid=uuid.uuid4(),
                        permit_id=setup_info['permit_1'].permit_id,
                        permit_amendment_status_code='',
                        permit_amendment_type_code='AM',
                        received_date=datetime.today(),
                        issue_date=datetime.today(),
                        authorization_end_date=datetime.today())
    assert 'Permit amendment status code is not provided.' in str(e.value)
Ejemplo n.º 8
0
def test_permit_model_validate_issue_date(db_session):
    with pytest.raises(AssertionError) as e:
        PermitAmendment(permit_amendment_guid=uuid.uuid4(),
                        permit_id=0,
                        permit_amendment_status_code='A',
                        permit_amendment_type_code='AM',
                        received_date=datetime.today(),
                        issue_date=datetime.today() + timedelta(days=1),
                        authorization_end_date=datetime.today())
    assert 'Permit amendment issue date cannot be set to the future.' in str(
        e.value)
def test_permit_model_validate_received_date(test_client, auth_headers,
                                             setup_info):
    with pytest.raises(AssertionError) as e:
        PermitAmendment(permit_amendment_guid=uuid.uuid4(),
                        permit_id=setup_info['permit_1'].permit_id,
                        permit_amendment_status_code='A',
                        permit_amendment_type_code='AM',
                        received_date=datetime.today() + timedelta(days=1),
                        issue_date=datetime.today(),
                        authorization_end_date=datetime.today())
    assert 'Permit amendment received date cannot be set to the future.' in str(
        e.value)
def test_post_permit_amendment_no_params(test_client, auth_headers, setup_info):
    post_resp = test_client.post(
        f'/permits/{TEST_PERMIT_GUID_1}/amendments', 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'] == TEST_PERMIT_GUID_1, str(post_data)
    assert post_data['received_date'] is None
    assert post_data['issue_date'] is None
    assert post_data['authorization_end_date'] is None

    #permit_amdendment is actually in db
    assert PermitAmendment.find_by_permit_amendment_guid(post_data['permit_amendment_guid'])
Ejemplo n.º 11
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()

    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
def test_post_permit_amendment_with_type_params(test_client, auth_headers, setup_info):
    data = {'permit_amendment_type_code': 'OGP'}

    post_resp = test_client.post(
        f'/permits/{TEST_PERMIT_GUID_1}/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'] == TEST_PERMIT_GUID_1, str(post_data)
    assert post_data['permit_amendment_type_code'] == "OGP"
    assert post_data['permit_amendment_status_code'] == "ACT"

    #permit_amdendment is actually in db
    assert PermitAmendment.find_by_permit_amendment_guid(post_data['permit_amendment_guid'])
Ejemplo n.º 13
0
def test_post_permit_amendment_no_params(test_client, db_session,
                                         auth_headers):
    permit_guid = PermitFactory().permit_guid

    post_resp = test_client.post(f'/permits/{permit_guid}/amendments',
                                 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 post_data['received_date'] is None
    assert post_data['issue_date'] is None
    assert post_data['authorization_end_date'] is None

    #permit_amdendment is actually in db
    assert PermitAmendment.find_by_permit_amendment_guid(
        post_data['permit_amendment_guid'])
Ejemplo n.º 14
0
def test_post_permit_amendment_with_type_params(test_client, db_session,
                                                auth_headers):
    permit_guid = PermitFactory().permit_guid

    data = {'permit_amendment_type_code': 'OGP'}

    post_resp = test_client.post(f'/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 post_data['permit_amendment_type_code'] == "OGP"
    assert post_data['permit_amendment_status_code'] == "ACT"

    #permit_amdendment is actually in db
    assert PermitAmendment.find_by_permit_amendment_guid(
        post_data['permit_amendment_guid'])
Ejemplo n.º 15
0
def test_permit_amendment_model_find_by_permit_id(test_client, auth_headers,
                                                  setup_info):
    permit_amendments = PermitAmendment.find_by_permit_id(
        setup_info['permit_1'].permit_id)
    assert all(pa.permit_id == setup_info['permit_1'].permit_id
               for pa in permit_amendments)