def test_spending_by_award_type_success(client): # test small request resp = client.post( '/api/v2/search/spending_by_award/', content_type='application/json', data=json.dumps({ "fields": ["Award ID", "Recipient Name"], "filters": { "award_type_codes": ["A", "B", "C"] } })) assert resp.status_code == status.HTTP_200_OK # test all features resp = client.post( '/api/v2/search/spending_by_award', content_type='application/json', data=json.dumps({ "fields": ["Award ID", "Recipient Name"], "filters": all_filters() })) assert resp.status_code == status.HTTP_200_OK # test subawards resp = client.post( '/api/v2/search/spending_by_award', content_type='application/json', data=json.dumps({ "fields": ["Award ID", "Recipient Name"], "filters": all_filters(), "subawards": True })) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_award_type_success(client, refresh_matviews): # test small request resp = client.post( "/api/v2/search/spending_by_award/", content_type="application/json", data=json.dumps({ "fields": ["Award ID", "Recipient Name"], "filters": { "award_type_codes": ["A", "B", "C"] } }), ) assert resp.status_code == status.HTTP_200_OK # test IDV award types resp = client.post( "/api/v2/search/spending_by_award/", content_type="application/json", data=json.dumps({ "fields": ["Award ID", "Recipient Name"], "filters": { "award_type_codes": [ "IDV_A", "IDV_B", "IDV_B_A", "IDV_B_B", "IDV_B_C", "IDV_C", "IDV_D", "IDV_E" ] }, }), ) assert resp.status_code == status.HTTP_200_OK # test all features resp = client.post( "/api/v2/search/spending_by_award", content_type="application/json", data=json.dumps({ "fields": ["Award ID", "Recipient Name"], "filters": all_filters() }), ) assert resp.status_code == status.HTTP_200_OK # test subawards resp = client.post( "/api/v2/search/spending_by_award", content_type="application/json", data=json.dumps({ "fields": ["Sub-Award ID"], "filters": all_filters(), "subawards": True }), ) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_geography_state_success(client, refresh_matviews): # test for required filters resp = client.post('/api/v2/search/spending_by_geography', content_type='application/json', data=json.dumps({ "scope": "place_of_performance", "geo_layer": "state", "filters": { 'recipient_locations': [{ 'country': 'ABC' }] } })) assert resp.status_code == status.HTTP_200_OK # test all filters resp = client.post('/api/v2/search/spending_by_geography', content_type='application/json', data=json.dumps({ "scope": "recipient_location", "geo_layer": "county", "geo_layer_filters": ["WA"], "filters": all_filters() })) assert resp.status_code == status.HTTP_200_OK
def test_spending_over_time_success(client, refresh_matviews): # test for needed filters resp = client.post( "/api/v2/search/spending_over_time", content_type="application/json", data=json.dumps({ "group": "fiscal_year", "filters": { "keywords": ["test", "testing"] } }), ) assert resp.status_code == status.HTTP_200_OK # test all filters resp = client.post( "/api/v2/search/spending_over_time", content_type="application/json", data=json.dumps({ "group": "quarter", "filters": all_filters() }), ) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_geography_congressional_success(client, refresh_matviews): # test for required filters resp = client.post( "/api/v2/search/spending_by_geography", content_type="application/json", data=json.dumps({ "scope": "place_of_performance", "geo_layer": "district", "filters": { "recipient_locations": [{ "country": "ABC" }] }, }), ) assert resp.status_code == status.HTTP_200_OK # test all filters resp = client.post( "/api/v2/search/spending_by_geography", content_type="application/json", data=json.dumps({ "scope": "recipient_location", "geo_layer": "district", "geo_layer_filters": ["01"], "filters": all_filters(), }), ) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_geography_state_success(client, refresh_matviews): # test for required filters resp = client.post( '/api/v2/search/spending_by_geography', content_type='application/json', data=json.dumps({ "scope": "place_of_performance", "geo_layer": "state", "filters": { 'recipient_locations': [{'country': 'ABC'}] } })) assert resp.status_code == status.HTTP_200_OK # test all filters resp = client.post( '/api/v2/search/spending_by_geography', content_type='application/json', data=json.dumps({ "scope": "recipient_location", "geo_layer": "county", "geo_layer_filters": ["WA"], "filters": all_filters() })) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_award_count_filters(client, refresh_matviews): resp = client.post( "/api/v2/search/spending_by_award_count", content_type="application/json", data=json.dumps({"filters": all_filters()}), ) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_award_type_success(client, refresh_matviews): # test small request resp = client.post( '/api/v2/search/spending_by_award/', content_type='application/json', data=json.dumps({ "fields": ["Award ID", "Recipient Name"], "filters": { "award_type_codes": ["A", "B", "C"] } })) assert resp.status_code == status.HTTP_200_OK # test IDV award types resp = client.post( '/api/v2/search/spending_by_award/', content_type='application/json', data=json.dumps({ "fields": ["Award ID", "Recipient Name"], "filters": { "award_type_codes": ["IDV_A", "IDV_B", "IDV_B_A", "IDV_B_B", "IDV_B_C", "IDV_C", "IDV_D", "IDV_E"] } })) assert resp.status_code == status.HTTP_200_OK # test all features resp = client.post( '/api/v2/search/spending_by_award', content_type='application/json', data=json.dumps({ "fields": ["Award ID", "Recipient Name"], "filters": all_filters() })) assert resp.status_code == status.HTTP_200_OK # test subawards resp = client.post( '/api/v2/search/spending_by_award', content_type='application/json', data=json.dumps({ "fields": ["Sub-Award ID"], "filters": all_filters(), "subawards": True })) assert resp.status_code == status.HTTP_200_OK
def test_spending_over_time_subawards_success(client, refresh_matviews): resp = client.post('/api/v2/search/spending_over_time', content_type='application/json', data=json.dumps({ "group": "quarter", "filters": all_filters(), "subawards": True })) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_geography_incorrect_district(client, refresh_matviews): resp = client.post('/api/v2/search/spending_by_geography/', content_type='application/json', data=json.dumps({ 'scope': 'place_of_performance', 'geo_layer': 'district', "geo_layer_filters": ["01"], 'filters': all_filters() })) assert len(resp.data['results']) == 0
def test_spending_over_time_subawards_success(client, refresh_matviews): resp = client.post( '/api/v2/search/spending_over_time', content_type='application/json', data=json.dumps({ "group": "quarter", "filters": all_filters(), "subawards": True })) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_geography_incorrect_state(client, refresh_matviews): resp = client.post('/api/v2/search/spending_by_geography/', content_type='application/json', data=json.dumps({ 'scope': 'place_of_performance', 'geo_layer': 'state', "geo_layer_filters": ["01"], 'filters': all_filters() })) assert resp.data['results'][0]['display_name'] in ['Alabama', 'None']
def test_spending_by_geography_incorrect_county(client, refresh_matviews): resp = client.post('/api/v2/search/spending_by_geography/', content_type='application/json', data=json.dumps({ 'scope': 'place_of_performance', 'geo_layer': 'county', "geo_layer_filters": ["01"], 'filters': all_filters() })) # raise Exception(resp.content) assert resp.data['results'][0]['display_name'] == 'County'
def test_spending_by_geography_subawards_failure(client): resp = client.post('/api/v2/search/spending_by_geography', content_type='application/json', data=json.dumps({ "scope": "recipient_location", "geo_layer": "county", "filters": all_filters(), "subawards": "string" })) assert resp.status_code == status.HTTP_400_BAD_REQUEST
def test_spending_over_time_subawards_failure(client, refresh_matviews): """Verify error on bad autocomplete request for budget function.""" resp = client.post('/api/v2/search/spending_over_time', content_type='application/json', data=json.dumps({ "group": "quarter", "filters": all_filters(), "subawards": "string" })) assert resp.status_code == status.HTTP_400_BAD_REQUEST
def test_spending_by_award_subaward_success(client, refresh_matviews): resp = client.post('/api/v2/search/spending_by_award', content_type='application/json', data=json.dumps({ "subawards": True, "fields": ["Sub-Award ID"], "sort": "Sub-Award ID", "filters": all_filters() })) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_geography_subawards_success(client, refresh_matviews): resp = client.post('/api/v2/search/spending_by_geography', content_type='application/json', data=json.dumps({ "scope": "recipient_location", "geo_layer": "county", "geo_layer_filters": ["01"], "filters": all_filters(), "subawards": True })) assert resp.status_code == status.HTTP_200_OK
def test_spending_over_time_subawards_failure(client, refresh_matviews): """Verify error on bad autocomplete request for budget function.""" resp = client.post( '/api/v2/search/spending_over_time', content_type='application/json', data=json.dumps({ "group": "quarter", "filters": all_filters(), "subawards": "string" })) assert resp.status_code == status.HTTP_400_BAD_REQUEST
def test_spending_by_geography_subawards_failure(client, refresh_matviews): resp = client.post( '/api/v2/search/spending_by_geography', content_type='application/json', data=json.dumps({ "scope": "recipient_location", "geo_layer": "county", "geo_layer_filters": ["01"], "filters": all_filters(), "subawards": "string" })) assert resp.status_code == status.HTTP_400_BAD_REQUEST
def test_spending_by_geography_incorrect_district(client, refresh_matviews): resp = client.post( "/api/v2/search/spending_by_geography/", content_type="application/json", data=json.dumps({ "scope": "place_of_performance", "geo_layer": "district", "geo_layer_filters": ["01"], "filters": all_filters(), }), ) assert len(resp.data["results"]) == 0
def test_spending_by_geography_incorrect_state(client, refresh_matviews): resp = client.post( "/api/v2/search/spending_by_geography/", content_type="application/json", data=json.dumps({ "scope": "place_of_performance", "geo_layer": "state", "geo_layer_filters": ["01"], "filters": all_filters(), }), ) assert resp.data["results"][0]["display_name"] in ["Alabama", "None"]
def test_spending_by_geography_incorrect_state(client, refresh_matviews): resp = client.post( '/api/v2/search/spending_by_geography/', content_type='application/json', data=json.dumps({ 'scope': 'place_of_performance', 'geo_layer': 'state', "geo_layer_filters": ["01"], 'filters': all_filters() }) ) assert resp.data['results'][0]['display_name'] in ['Alabama', 'None']
def test_spending_by_geography_incorrect_district(client, refresh_matviews): resp = client.post( '/api/v2/search/spending_by_geography/', content_type='application/json', data=json.dumps({ 'scope': 'place_of_performance', 'geo_layer': 'district', "geo_layer_filters": ["01"], 'filters': all_filters() }) ) assert len(resp.data['results']) == 0
def test_spending_by_geography_incorrect_county(client, refresh_matviews): resp = client.post( '/api/v2/search/spending_by_geography/', content_type='application/json', data=json.dumps({ 'scope': 'place_of_performance', 'geo_layer': 'county', "geo_layer_filters": ["01"], 'filters': all_filters() }) ) # raise Exception(resp.content) assert resp.data['results'][0]['display_name'] == 'County'
def test_spending_by_geography_incorrect_county(client, refresh_matviews): resp = client.post( "/api/v2/search/spending_by_geography/", content_type="application/json", data=json.dumps({ "scope": "place_of_performance", "geo_layer": "county", "geo_layer_filters": ["01"], "filters": all_filters(), }), ) # raise Exception(resp.content) assert resp.data["results"][0]["display_name"] == "County"
def test_spending_by_geography_subawards_failure(client, refresh_matviews): resp = client.post( "/api/v2/search/spending_by_geography", content_type="application/json", data=json.dumps({ "scope": "recipient_location", "geo_layer": "county", "geo_layer_filters": ["01"], "filters": all_filters(), "subawards": "string", }), ) assert resp.status_code == status.HTTP_400_BAD_REQUEST
def test_naics_autocomplete_failure(client, refresh_matviews): """Verify error on bad autocomplete request for budget function.""" resp = client.post('/api/v2/search/spending_by_category/', content_type='application/json', data=json.dumps({})) assert resp.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY resp = client.post('/api/v2/search/spending_by_category', content_type='application/json', data=json.dumps({ "group": "quarter", "filters": all_filters() })) assert resp.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
def test_spending_by_award_type_success(client): # test for filters resp = client.post('/api/v2/search/spending_by_award_count/', content_type='application/json', data=json.dumps( {"filters": { "award_type_codes": ["A", "B", "C"] }})) assert resp.status_code == status.HTTP_200_OK resp = client.post('/api/v2/search/spending_by_award_count', content_type='application/json', data=json.dumps({"filters": all_filters()})) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_award_type_success(client, refresh_matviews): # test for filters resp = client.post( "/api/v2/search/spending_by_award_count/", content_type="application/json", data=json.dumps({"filters": {"award_type_codes": ["A", "B", "C"]}}), ) assert resp.status_code == status.HTTP_200_OK resp = client.post( "/api/v2/search/spending_by_award_count", content_type="application/json", data=json.dumps({"filters": all_filters()}), ) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_category_success(client, refresh_matviews): # test for required functions resp = client.post('/api/v2/search/spending_by_category', content_type='application/json', data=json.dumps({ "category": "funding_agency", "filters": { "keywords": ["test", "testing"] } })) assert resp.status_code == status.HTTP_200_OK resp = client.post('/api/v2/search/spending_by_category', content_type='application/json', data=json.dumps({ "category": "cfda", "filters": all_filters() })) assert resp.status_code == status.HTTP_200_OK
def test_spending_over_time_success(client): # test for needed filters resp = client.post('/api/v2/search/spending_over_time', content_type='application/json', data=json.dumps({ "group": "fiscal_year", "filters": { "keyword": "test" } })) assert resp.status_code == status.HTTP_200_OK # test all filters resp = client.post('/api/v2/search/spending_over_time', content_type='application/json', data=json.dumps({ "group": "quarter", "filters": all_filters() })) assert resp.status_code == status.HTTP_200_OK
def test_spending_over_time_success(client, refresh_matviews): # test for needed filters resp = client.post( '/api/v2/search/spending_over_time', content_type='application/json', data=json.dumps({ "group": "fiscal_year", "filters": { "keywords": ["test", "testing"] } })) assert resp.status_code == status.HTTP_200_OK # test all filters resp = client.post( '/api/v2/search/spending_over_time', content_type='application/json', data=json.dumps({ "group": "quarter", "filters": all_filters() })) assert resp.status_code == status.HTTP_200_OK
def test_spending_by_award_success(client, refresh_matviews): resp = client.post( "/api/v2/search/spending_by_award", content_type="application/json", data=json.dumps({"subawards": False, "fields": ["Award ID"], "sort": "Award ID", "filters": all_filters()}), ) assert resp.status_code == status.HTTP_200_OK