def test_get_mine_application_list_success(self, test_client, db_session, auth_headers): """Should return the records for the mine with a 200 response code""" batch_size = 5 other_applications = NOWApplicationIdentityFactory.create_batch(size=batch_size) mine = MineFactory(minimal=True) now_submission_1 = NOWSubmissionFactory(mine=mine) identity_1 = NOWApplicationIdentityFactory(now_submission=now_submission_1, mine=mine) now_submission_2 = NOWSubmissionFactory(mine=mine) identity_2 = NOWApplicationIdentityFactory(now_submission=now_submission_2, mine=mine) get_resp = test_client.get( f'now-applications?mine_guid={mine.mine_guid}', headers=auth_headers['full_auth_header']) assert get_resp.status_code == 200, get_resp.response get_data = json.loads(get_resp.data.decode()) assert len(get_data['records']) == 2 assert all( str(submission.now_application_guid) not in map(lambda x: x['now_application_guid'], get_data['records']) for submission in other_applications) assert all( str(submission.now_application_guid) in map(lambda x: x['now_application_guid'], get_data['records']) for submission in [now_submission_1, now_submission_1])
def test_get_mine_application_list_filter_by_noticeofworktype(self, test_client, db_session, auth_headers): """Should return the records filtered by noticeofworktype""" mine = MineFactory(minimal=True) now_submission_1 = NOWSubmissionFactory(mine=mine, noticeofworktype='dog') identity_1 = NOWApplicationIdentityFactory( now_submission=now_submission_1, mine=mine, submission_only=True) now_submission_2 = NOWSubmissionFactory(mine=mine, noticeofworktype='dog') identity_2 = NOWApplicationIdentityFactory( now_submission=now_submission_2, mine=mine, submission_only=True) now_submission_3 = NOWSubmissionFactory(mine=mine, noticeofworktype='cat') identity_3 = NOWApplicationIdentityFactory( now_submission=now_submission_3, mine=mine, submission_only=True) now_submission_4 = NOWSubmissionFactory(mine=mine, noticeofworktype='parrot') identity_4 = NOWApplicationIdentityFactory( now_submission=now_submission_4, mine=mine, submission_only=True) get_resp = test_client.get( f'now-applications?mine_guid={mine.mine_guid}¬ice_of_work_type_description=dog', headers=auth_headers['full_auth_header']) assert get_resp.status_code == 200, get_resp.response get_data = json.loads(get_resp.data.decode()) assert len(get_data['records']) == 2 assert all( str(submission.now_application_guid) in map(lambda x: x['now_application_guid'], get_data['records']) for submission in [now_submission_1, now_submission_2]) assert all( str(submission.now_application_guid) not in map(lambda x: x['now_application_guid'], get_data['records']) for submission in [now_submission_3, now_submission_4])
def test_get_mine_application_list_filter_by_status(self, test_client, db_session, auth_headers): """Should return the records filtered by status""" mine = MineFactory(minimal=True) now_submission_1 = NOWSubmissionFactory(mine=mine, status='Approved') identity_1 = NOWApplicationIdentityFactory(now_submission=now_submission_1, mine=mine) now_submission_2 = NOWSubmissionFactory(mine=mine, status='Received') identity_2 = NOWApplicationIdentityFactory(now_submission=now_submission_2, mine=mine) now_submission_3 = NOWSubmissionFactory(mine=mine, status='Rejected') identity_3 = NOWApplicationIdentityFactory(now_submission=now_submission_3, mine=mine) now_submission_4 = NOWSubmissionFactory(mine=mine, status='Rejected') identity_4 = NOWApplicationIdentityFactory(now_submission=now_submission_4, mine=mine) get_resp = test_client.get( f'now-applications?mine_guid={mine.mine_guid}&now_application_status_description=Approved&now_application_status_description=Received', headers=auth_headers['full_auth_header']) assert get_resp.status_code == 200, get_resp.response get_data = json.loads(get_resp.data.decode()) assert len(get_data['records']) == 2 assert all( str(submission.now_application_guid) in map(lambda x: x['now_application_guid'], get_data['records']) for submission in [now_submission_1, now_submission_2]) assert all( str(submission.now_application_guid) not in map(lambda x: x['now_application_guid'], get_data['records']) for submission in [now_submission_3, now_submission_4])
def test_get_application_list_pagination(self, test_client, db_session, auth_headers): """Should return paginated records""" batch_size = PER_PAGE_DEFAULT + 1 NOWApplicationIdentityFactory.create_batch(size=batch_size) get_resp = test_client.get('/now-applications', headers=auth_headers['full_auth_header']) assert get_resp.status_code == 200, get_resp.response get_data = json.loads(get_resp.data.decode()) assert len(get_data['records']) == PER_PAGE_DEFAULT assert get_data['current_page'] == PAGE_DEFAULT assert get_data['total'] == batch_size
def test_post_now_application_import_success(self, test_client, db_session, auth_headers): now_application_identity = NOWApplicationIdentityFactory() post_resp = test_client.post( f'/now-applications/{now_application_identity.now_application_guid}/import', json={'mine_guid': now_application_identity.mine_guid}, headers=auth_headers['full_auth_header']) assert post_resp.status_code == 200, post_resp.response post_data = json.loads(post_resp.data.decode())
def test_get_now_application_review_success(self, test_client, db_session, auth_headers): now_application = NOWApplicationFactory() now_application_identity = NOWApplicationIdentityFactory( now_application=now_application) post_resp = test_client.get( f'/now-applications/{now_application_identity.now_application_guid}/reviews', headers=auth_headers['full_auth_header']) assert post_resp.status_code == 200, post_resp.response post_data = json.loads(post_resp.data.decode()) assert len(post_data['records']) > 0 assert 'response_date' in post_data['records'][0]
def test_get_now_application_status_by_now_number_success( self, test_client, db_session, auth_headers): """Should return the correct record with a 200 response code""" now_submission = NOWSubmissionFactory() identity = NOWApplicationIdentityFactory(now_submission=now_submission) get_resp = test_client.get( f'/now-submissions/applications/{identity.now_number}/status', headers=auth_headers['full_auth_header']) assert get_resp.status_code == 200, get_resp.response get_data = json.loads(get_resp.data.decode()) assert get_data['now_application_status_code'] is not None assert get_data[ 'now_application_status_code'] == identity.now_application.now_application_status_code
def test_get_now_application_list_success(self, test_client, db_session, auth_headers): """Should return the correct records with a 200 response code""" batch_size = 5 submissions = NOWApplicationIdentityFactory.create_batch(size=batch_size) get_resp = test_client.get('/now-applications', headers=auth_headers['full_auth_header']) assert get_resp.status_code == 200, get_resp.response get_data = json.loads(get_resp.data.decode()) assert len(get_data['records']) == batch_size assert get_data['total'] == batch_size assert all( str(submission.now_application_guid) in map(lambda x: x['now_application_guid'], get_data['records']) for submission in submissions)
def test_post_now_application_progress_success(self, test_client, db_session, auth_headers): now_application = NOWApplicationFactory(application_progress=None) now_application_identity = NOWApplicationIdentityFactory( now_application=now_application) test_progress_data = { 'application_progress_status_code': 'REV', } post_resp = test_client.post( f'/now-applications/{now_application_identity.now_application_guid}/progress', json=test_progress_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[ 'application_progress_status_code'] == test_progress_data[ 'application_progress_status_code']
def test_post_now_application_review_success(self, test_client, db_session, auth_headers): now_application = NOWApplicationFactory() now_application_identity = NOWApplicationIdentityFactory( now_application=now_application) test_progress_data = { 'now_application_review_type_code': 'REF', 'referee_name': 'Fred', } post_resp = test_client.post( f'/now-applications/{now_application_identity.now_application_guid}/reviews', json=test_progress_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[ 'now_application_review_type_code'] == test_progress_data[ 'now_application_review_type_code']
def test_post_now_application_progress_duplicate_type( self, test_client, db_session, auth_headers): mine = MineFactory(major_mine_ind=True) now_application = NOWApplicationFactory(application_progress=None) now_application_identity = NOWApplicationIdentityFactory( now_application=now_application, mine=mine) test_progress_data = { 'application_progress_status_code': 'REV', } post_resp = test_client.post( f'/now-applications/{now_application_identity.now_application_guid}/progress', json=test_progress_data, headers=auth_headers['full_auth_header']) assert post_resp.status_code == 201, post_resp.response post_resp = test_client.post( f'/now-applications/{now_application_identity.now_application_guid}/progress', json=test_progress_data, headers=auth_headers['full_auth_header']) assert post_resp.status_code == 400, post_resp.response
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') if len(mine.mine_permit) > 0: permitee = MinePartyAppointmentFactory( mine=mine, mine_party_appt_type_code='PMT', party__company=True) NOWApplicationIdentityFactory(mine=mine) try: db.session.commit() print(f'Created {num} random mines with related data.') except DBAPIError: db.session.rollback() raise
def test_get_now_application_status_updates_since_success( self, test_client, db_session, auth_headers): """Should return the correct records with a 200 response code""" today = datetime.datetime.today() status_updated_date = today identities = [] for i in range(3): now_submission = NOWSubmissionFactory() identity = NOWApplicationIdentityFactory( now_submission=now_submission) identity.now_application.status_updated_date = status_updated_date status_updated_date = status_updated_date + datetime.timedelta( days=+1) identity.save() identities.append(identity) get_resp = test_client.get( f'/now-submissions/applications/status?status_updated_date_since={today}', headers=auth_headers['full_auth_header']) assert get_resp.status_code == 200, get_resp.response get_data = json.loads(get_resp.data.decode()) assert len(get_data) == 3 status_updated_date = today for identity in identities: identity.now_application.status_updated_date = status_updated_date status_updated_date = status_updated_date + datetime.timedelta( days=-1) identity.save() get_resp = test_client.get( f'/now-submissions/applications/status?status_updated_date_since={today}', headers=auth_headers['full_auth_header']) assert get_resp.status_code == 200, get_resp.response get_data = json.loads(get_resp.data.decode()) assert len(get_data) == 1 get_resp = test_client.get( f'/now-submissions/applications/status?status_updated_date_since={today + datetime.timedelta(days=+42)}', headers=auth_headers['full_auth_header']) assert get_resp.status_code == 200, get_resp.response get_data = json.loads(get_resp.data.decode()) assert len(get_data) == 0