def test_search_org_by_explicit(test_client, db_session, auth_headers): PartyFactory(company=True, party_name='a company') PartyFactory(company=True, party_name='CompanyInc') PartyFactory(company=True, party_name='Company & Company LTD') get_resp = test_client.get('/parties?party_name=a company&type=ORG', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 200 assert len(get_data['records']) == 1 assert get_data['records'][0]['party_name'] == 'a company'
def test_simple_search_parties_only(test_client, db_session, auth_headers): searchString = 'Abb' party = PartyFactory(person=True, first_name="Rod", party_name="Stewart") for x in range(3): PartyFactory(person=True, first_name='Abbot') get_resp = test_client.get(f'/search/simple?search_term={searchString}', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert len(get_data['search_results']) == 3 assert get_resp.status_code == 200
def test_search_person_by_explicit(test_client, db_session, auth_headers): person1 = PartyFactory(person=True, first_name='a name') person2 = PartyFactory(person=True, first_name='OtherName') person3 = PartyFactory(person=True, first_name='Mr name') get_resp = test_client.get('/parties?type=PER', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 200 assert get_data['records'][0]['first_name'] in [ person1.first_name, person2.first_name, person3.first_name ]
def test_search_persons_by_implicit(test_client, db_session, auth_headers): PartyFactory(person=True, first_name='a name') PartyFactory(person=True, first_name='OtherName') PartyFactory(person=True, first_name='Mr name') get_resp = test_client.get('/parties?first_name=a name', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 200 assert len(get_data['records']) == 1 assert get_data['records'][0]['first_name'] == 'a name'
def test_get_parties_and_mines(test_client, db_session, auth_headers): searchString = 'Abbot' mine = MineFactory(mine_name="Test") party = PartyFactory(person=True, first_name="Rod", party_name="Stewart") for x in range(3): PartyFactory(person=True, first_name='Abbot') MineFactory(mine_name='Abbot Mines') get_resp = test_client.get(f'/search?search_term={searchString}', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) mines = get_data['search_results']['mine'] parties = get_data['search_results']['party'] assert len(mines) == 3 assert len(parties) == 3 assert get_resp.status_code == 200
def test_put_person_success(test_client, db_session, auth_headers): party_guid = PartyFactory(person=True).party_guid test_person_data = { "party_name": "Changedlast", "email": "*****@*****.**", "phone_no": "682-732-8490", "party_type_code": "PER", "first_name": "Changedfirst", "suite_no": "1234", "address_line_1": "1234 Foo Street", "address_line_2": "1234 Bar Blvd", "city": "Baz Town", "sub_division_code": "BC", "post_code": "X0X0X0", "address_type_code": "CAN" } put_resp = test_client.put( f'/parties/{party_guid}', data=test_person_data, headers=auth_headers['full_auth_header']) put_data = json.loads(put_resp.data.decode()) assert put_resp.status_code == 200 assert put_data['party_name'] == test_person_data['party_name'] assert put_data['email'] == test_person_data['email'] assert put_data['phone_no'] == test_person_data['phone_no'] assert put_data['party_type_code'] == test_person_data['party_type_code'] assert put_data['first_name'] == test_person_data['first_name'] address = put_data['address'][0] assert address['suite_no'] == test_person_data['suite_no'] assert address['address_line_1'] == test_person_data['address_line_1'] assert address['address_line_2'] == test_person_data['address_line_2'] assert address['city'] == test_person_data['city'] assert address['sub_division_code'] == test_person_data['sub_division_code'] assert address['post_code'] == test_person_data['post_code'] assert address['address_type_code'] == test_person_data['address_type_code']
def test_post_permit(test_client, db_session, auth_headers): mine = MineFactory() party_guid = PartyFactory(company=True).party_guid no_of_permits = len(mine.mine_permit) PERMIT_NO = 'mx-test-999' data = { 'permittee_party_guid': str(party_guid), 'permit_no': PERMIT_NO, 'permit_status_code': 'O', 'received_date': '1999-12-12', 'issue_date': '1999-12-21', 'authorization_end_date': '2012-12-02' } post_resp = test_client.post(f'/mines/{mine.mine_guid}/permits', headers=auth_headers['full_auth_header'], json=data) post_data = json.loads(post_resp.data.decode()) updated_mine = Mine.find_by_mine_guid(str(mine.mine_guid)) permittees = MinePartyAppointment.find_by_permit_guid( updated_mine.mine_permit[0].permit_guid) assert post_resp.status_code == 200 assert updated_mine.mine_permit[0].permit_no == PERMIT_NO assert permittees[0].party_guid == party_guid assert len(updated_mine.mine_permit) == no_of_permits + 1
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 test_get_person(test_client, db_session, auth_headers): party_guid = PartyFactory(person=True).party_guid get_resp = test_client.get(f'/parties/{party_guid}', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 200 assert get_data['party_guid'] == str(party_guid)
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'])
def test_delete_person_as_admin(test_client, db_session, auth_headers): party_guid = PartyFactory(person=True).party_guid delete_resp = test_client.delete( f'/parties/{party_guid}', headers=auth_headers['full_auth_header']) assert delete_resp.status_code == 204 get_resp = test_client.get(f'/parties/{party_guid}', headers=auth_headers['full_auth_header']) assert get_resp.status_code == 404
def test_post_mine_party_appt_missing_mine_guid(test_client, db_session, auth_headers, setup_info): party_guid = PartyFactory(person=True).party_guid test_data = {'party_guid': str(party_guid), 'mine_party_appt_type_code': 'BLA'} post_resp = test_client.post( '/parties/mines', data=test_data, headers=auth_headers['full_auth_header']) post_data = json.loads(post_resp.data.decode()) assert post_resp.status_code == 400
def test_get_empty_return(test_client, db_session, auth_headers): PartyFactory(person=True) get_resp = test_client.get('/parties?first_name=IMAFAKE', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 200 assert len(get_data['records']) == 0
def test_post_permit_with_duplicate_permit_no(test_client, db_session, auth_headers): mine_guid = MineFactory().mine_guid permit_no = PermitFactory().permit_no party_guid = PartyFactory(company=True).party_guid data = {'permittee_party_guid': str(party_guid), 'permit_no': permit_no} post_resp = test_client.post(f'/mines/{mine_guid}/permits', headers=auth_headers['full_auth_header'], json=data) assert post_resp.status_code == 400
def test_filter_by_first_name_and_phone(test_client, db_session, auth_headers): wanted_party = PartyFactory(person=True) PartyFactory.create_batch(size=5, person=True) get_resp = test_client.get( f'/parties?first_name={wanted_party.first_name}&phone_no={wanted_party.phone_no}', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 200 assert len(get_data['records']) == 1 assert get_data['records'][0]['party_guid'] == str(wanted_party.party_guid)
def test_post_permittee_permit_guid_not_found(test_client, db_session, auth_headers): party_guid = PartyFactory(person=True).party_guid data = { 'party_guid': str(party_guid), 'permit_guid': str(uuid.uuid4()), 'effective_date': datetime.today().strftime("%Y-%m-%d") } post_resp = test_client.post( '/parties/mines', data=data, headers=auth_headers['full_auth_header']) post_data = json.loads(post_resp.data.decode()) assert post_resp.status_code == 400, str(post_resp.response) assert post_data['message']
def test_post_mine_party_appt_EOR_success(test_client, db_session, auth_headers, setup_info): party_guid = PartyFactory(person=True).party_guid test_data = { 'mine_guid': setup_info['mine_guid'], 'party_guid': str(party_guid), 'mine_party_appt_type_code': 'EOR', 'related_guid': setup_info['tsf_guid'], } post_resp = test_client.post( '/parties/mines', data=test_data, headers=auth_headers['full_auth_header']) post_data = json.loads(post_resp.data.decode()) assert post_resp.status_code == 200, str(post_resp.response) assert post_data['mine_guid'] == setup_info['mine_guid']
def test_search_party(test_client, db_session, auth_headers): party = PartyFactory(person=True) get_resp = test_client.get(f'/search?search_term={str(party.first_name)}', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) parties = get_data['search_results']['party'] assert len(parties) == 1 assert party.first_name in parties[0]['result']['name'] assert uuid.UUID(parties[0]['result']['party_guid']) == party.party_guid assert len([ key for key, value in get_data['search_results'].items() if key is not 'party' and len(value) is 0 ]) == 4 assert get_resp.status_code == 200
def test_post_a_bond_bad_permit_guid(self, test_client, db_session, auth_headers): """Should return an error and a 400 response code""" party1 = PartyFactory(person=True) BOND_POST_DATA['bond']['payer_party_guid'] = party1.party_guid BOND_POST_DATA['permit_guid'] = BAD_GUID post_resp = test_client.post('/securities/bonds', json=BOND_POST_DATA, headers=auth_headers['full_auth_header']) assert post_resp.status_code == 400, post_resp.response post_data = json.loads(post_resp.data.decode()) assert post_data['message'] is not None
def test_post_variance_non_existent_mine_guid(test_client, db_session, auth_headers): fake_guid = uuid.uuid4() party = PartyFactory(person=True) test_variance_data = { 'compliance_article_id': RandomComplianceArticleId(), 'note': 'Biggest mine yet', 'received_date': '2019-04-23', 'applicant_guid': party.party_guid } post_resp = test_client.post(f'/mines/{fake_guid}/variances', data=test_variance_data, headers=auth_headers['full_auth_header']) post_data = json.loads(post_resp.data.decode()) assert post_resp.status_code == 404, post_resp.response
def test_post_a_bond(self, test_client, db_session, auth_headers): """Should return the created bond with a 201 response code""" mine = MineFactory(minimal=True) party1 = PartyFactory(person=True) permit = PermitFactory(mine=mine) BOND_POST_DATA['bond']['payer_party_guid'] = party1.party_guid BOND_POST_DATA['permit_guid'] = permit.permit_guid post_resp = test_client.post('/securities/bonds', json=BOND_POST_DATA, headers=auth_headers['full_auth_header']) assert post_resp.status_code == 201, post_resp.response post_data = json.loads(post_resp.data.decode()) assert post_data['permit_guid'] == str(permit.permit_guid) assert post_data['payer_party_guid'] == str(party1.party_guid)
def test_post_permittee(test_client, db_session, auth_headers): permit = PermitFactory() party_guid = PartyFactory(person=True).party_guid data = { 'mine_guid': str(permit.mine.mine_guid), 'party_guid': str(party_guid), 'mine_party_appt_type_code': 'PMT', 'related_guid': str(permit.permit_guid), 'effective_date': datetime.today().strftime("%Y-%m-%d") } post_resp = test_client.post( '/parties/mines', data=data, headers=auth_headers['full_auth_header']) post_data = json.loads(post_resp.data.decode()) assert post_resp.status_code == 200, str(post_resp.response) assert post_data['party_guid'] == str(party_guid)
def test_post_variance_application_with_issue_date(test_client, db_session, auth_headers): variance = VarianceFactory() party = PartyFactory(person=True) approved_variance = VarianceFactory(approved=True) data = { 'compliance_article_id': variance.compliance_article_id, 'note': variance.note, 'received_date': variance.received_date, 'applicant_guid': party.party_guid, 'issue_date': approved_variance.issue_date } post_resp = test_client.post(f'/mines/{variance.mine_guid}/variances', headers=auth_headers['full_auth_header'], data=data) post_data = json.loads(post_resp.data.decode()) assert post_resp.status_code == 400, post_resp.response assert 'issue' in post_data['message'].lower()
def test_post_variance_application(test_client, db_session, auth_headers): mine = MineFactory() party = PartyFactory(person=True) test_variance_data = { 'compliance_article_id': RandomComplianceArticleId(), 'note': 'Biggest mine yet', 'received_date': '2019-04-23', 'applicant_guid': party.party_guid } post_resp = test_client.post(f'/mines/{mine.mine_guid}/variances', data=test_variance_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['compliance_article_id'] == test_variance_data[ 'compliance_article_id'] assert post_data['note'] == test_variance_data['note'] assert post_data['received_date'] == test_variance_data['received_date'] assert post_data['applicant_guid'] == str( test_variance_data['applicant_guid'])
def test_post_variance_application_with_expiry_date(self, test_client, db_session, auth_headers): """Should return a 400 and a relevant error message if the variance is in-review with an expiry date""" variance = VarianceFactory() party = PartyFactory(person=True) approved_variance = VarianceFactory(approved=True) data = { 'compliance_article_id': variance.compliance_article_id, 'note': variance.note, 'received_date': variance.received_date, 'applicant_guid': party.party_guid, 'expiry_date': approved_variance.expiry_date } post_resp = test_client.post( f'/mines/{variance.mine_guid}/variances', headers=auth_headers['full_auth_header'], data=data) post_data = json.loads(post_resp.data.decode()) assert post_resp.status_code == 400, post_resp.response assert 'expiry' in post_data['message'].lower()
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
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
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