def test_get_variances_invalid_mine_guid(test_client, db_session, auth_headers): batch_size = 3 VarianceFactory.create_batch(size=batch_size) get_resp = test_client.get(f'/mines/abc123/variances', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 400
def test_get_variances_invalid_mine_guid(self, test_client, db_session, auth_headers): """Should return a 400 when an invalid mine guid is provided""" batch_size = 3 VarianceFactory.create_batch(size=batch_size) get_resp = test_client.get(f'/mines/abc123/variances', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 400
def test_get_variances_non_existent_mine_guid(test_client, db_session, auth_headers): batch_size = 3 fake_guid = uuid.uuid4() VarianceFactory.create_batch(size=batch_size) get_resp = test_client.get(f'/mines/{fake_guid}/variances', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 404
def test_get_variances_non_existent_mine_guid(self, test_client, db_session, auth_headers): """Should return a 404 when the provided mine guid does not exist""" batch_size = 3 fake_guid = uuid.uuid4() VarianceFactory.create_batch(size=batch_size) get_resp = test_client.get(f'/mines/{fake_guid}/variances', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 404
def test_get_variances_for_a_mine(test_client, db_session, auth_headers): batch_size = 3 mine = MineFactory(minimal=True) VarianceFactory.create_batch(size=batch_size, mine=mine) VarianceFactory.create_batch(size=batch_size) get_resp = test_client.get(f'/mines/{mine.mine_guid}/variances', 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']) == batch_size
def test_get_variances_application_filter_by_mine_region(self, test_client, db_session, auth_headers): """Should filter variances by mine region""" region_code = "NW" mine_with_region_nw = MineFactory(mine_region='NW') mine_with_region_sw = MineFactory(mine_region="SW") batch_size = 3 VarianceFactory.create_batch(size=batch_size) VarianceFactory(mine=mine_with_region_nw) VarianceFactory(mine=mine_with_region_sw) get_resp = test_client.get(f'/variances?region={region_code}',headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 200 assert all(map( lambda v: v['mine_name'] == mine_with_region_nw.mine_name, get_data['records']))
def test_get_variances_application_filter_by_compliance_code(self, test_client, db_session, auth_headers): """Should filter variances by compliance code""" compliance_codes = [RandomComplianceArticleId(),RandomComplianceArticleId()] batch_size = 3 VarianceFactory.create_batch(size=batch_size) VarianceFactory(compliance_article_id=compliance_codes[0]) VarianceFactory(compliance_article_id=compliance_codes[1]) get_resp = test_client.get( f'/variances?compliance_code={compliance_codes[0]}&compliance_code={compliance_codes[1]}', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 200 assert all(map( lambda v: v['compliance_article_id'] in compliance_codes, get_data['records']))
def test_get_variances_pagination(self, test_client, db_session, auth_headers): """Should return paginated records""" batch_size = PER_PAGE_DEFAULT + 1 variances = VarianceFactory.create_batch(size=batch_size) get_resp = test_client.get('/variances', 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']) == PER_PAGE_DEFAULT assert get_data['current_page'] == PAGE_DEFAULT assert get_data['total'] == batch_size
def test_get_variances_application_status_filter(self, test_client, db_session, auth_headers): """Should respect variance_application_status_code query param""" batch_size = 3 variances = VarianceFactory.create_batch(size=batch_size) status_code = RandomVarianceApplicationStatusCode() get_resp = test_client.get( f'/variances?variance_application_status_code={status_code}', headers=auth_headers['full_auth_header']) get_data = json.loads(get_resp.data.decode()) assert get_resp.status_code == 200 assert all(map(lambda v: v['variance_application_status_code'] == status_code, get_data['records']))
def test_get_variances(self, test_client, db_session, auth_headers): """Should return all records and a 200 response code""" batch_size = 3 variances = VarianceFactory.create_batch(size=batch_size) get_resp = test_client.get('/variances', 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']) == batch_size assert all( str(variance.variance_guid) in map(lambda v: v['variance_guid'], get_data['records']) for variance in variances)