def test_category_country_subawards(geo_test_data): test_payload = { "category": "country", "subawards": True, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "country", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 4, "code": "US", "name": "UNITED STATES", "id": None }], "messages": [get_time_period_message()], } assert expected_response == spending_by_category_logic
def test_category_cfda_subawards(cfda_test_data): test_payload = { "category": "cfda", "subawards": True, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "cfda", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 2, "code": "CFDA1234", "name": "CFDA TITLE 1234", "id": 1 }], "messages": [get_time_period_message()], } assert expected_response == spending_by_category_logic
def test_category_funding_subagency_subawards(agency_test_data): test_payload = { "category": "funding_subagency", "subawards": True, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "funding_subagency", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 150, "name": "Funding Subtier Agency 4", "code": "SA4", "id": 1004 }], "messages": [get_time_period_message()], } assert expected_response == spending_by_category_logic
def test_category_federal_accounts(federal_accounts_test_data): test_payload = { "category": "federal_account", "filters": { "recipient_id": "dece8b43-c2a8-d056-7e82-0fc2f1c7c4e4-R" }, "subawards": False, "page": 1, "limit": 50, } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "federal_account", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 3, "code": "020-0001", "name": "Test Federal Account", "id": 10 }], "messages": [get_time_period_message()], } assert expected_response == spending_by_category_logic
def test_category_state_territory_subawards(mock_matviews_qs): mock_model_1 = MockModel(pop_state_code="XY", amount=1) mock_model_2 = MockModel(pop_state_code="XY", amount=1) mommy.make("recipient.StateData", name="Test State", code="XY") add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) test_payload = { "category": "state_territory", "subawards": True, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "state_territory", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 2, "code": "XY", "name": "Test State", "id": None }], } assert expected_response == spending_by_category_logic
def test_category_recipient_parent_duns_subawards(mock_matviews_qs, mock_recipients): mock_recipient_1 = MockModel(recipient_unique_id='00UOP00', legal_entity_id=1) mock_recipient_2 = MockModel(recipient_unique_id='1234JD4321', legal_entity_id=2) mock_model_1 = MockModel(recipient_name='University of Pawnee', parent_recipient_unique_id='00UOP00', amount=1) mock_model_2 = MockModel(recipient_name='University of Pawnee', parent_recipient_unique_id='00UOP00', amount=1) mock_model_3 = MockModel(recipient_name='John Doe', parent_recipient_unique_id='1234JD4321', amount=1) mock_model_4 = MockModel(recipient_name='John Doe', parent_recipient_unique_id='1234JD4321', amount=10) add_to_mock_objects( mock_matviews_qs, [mock_model_1, mock_model_2, mock_model_3, mock_model_4]) add_to_mock_objects(mock_recipients, [mock_recipient_1, mock_recipient_2]) test_payload = { 'category': 'recipient_parent_duns', 'subawards': True, 'page': 1, 'limit': 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { 'category': 'recipient_parent_duns', 'limit': 50, 'page_metadata': { 'page': 1, 'next': None, 'previous': None, 'hasNext': False, 'hasPrevious': False }, 'results': [{ 'amount': 11, 'name': 'John Doe', 'code': '1234JD4321', 'id': 2, }, { 'amount': 2, 'name': 'University of Pawnee', 'code': '00UOP00', 'id': 1, }] } assert expected_response == spending_by_category_logic
def test_category_awarding_subagency_subawards(mock_matviews_qs, mock_agencies): mock_subtier = MockModel(subtier_agency_id=1, name="Department of Sub-pizza", abbreviation="DOSP") mock_agency = MockModel(id=2, subtier_agency=mock_subtier, toptier_flag=False) mock_agency_1 = MockModel(id=3, subtier_agency=mock_subtier, toptier_flag=True) mock_model_1 = MockModel( awarding_agency_id=2, awarding_subtier_agency_name="Department of Sub-pizza", awarding_subtier_agency_abbreviation="DOSP", amount=10, ) mock_model_2 = MockModel( awarding_agency_id=3, awarding_subtier_agency_name="Department of Sub-pizza", awarding_subtier_agency_abbreviation="DOSP", amount=10, ) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) add_to_mock_objects(mock_agencies["agency"], [mock_agency, mock_agency_1]) test_payload = { "category": "awarding_subagency", "subawards": True, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "awarding_subagency", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 20, "name": "Department of Sub-pizza", "code": "DOSP", "id": 2 }], } assert expected_response == spending_by_category_logic
def test_category_naics_awards(mock_matviews_qs): mock_model_1 = MockModel(naics_code="NAICS 1234", naics_description="NAICS DESC 1234", generated_pragmatic_obligation=1) mock_model_2 = MockModel(naics_code="NAICS 1234", naics_description="NAICS DESC 1234", generated_pragmatic_obligation=1) mock_model_3 = MockModel(naics_code="NAICS 9876", naics_description="NAICS DESC 9876", generated_pragmatic_obligation=2) mock_model_4 = MockModel(naics_code="NAICS 9876", naics_description="NAICS DESC 9876", generated_pragmatic_obligation=2) add_to_mock_objects( mock_matviews_qs, [mock_model_1, mock_model_2, mock_model_3, mock_model_4]) test_payload = { "category": "naics", "subawards": False, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "naics", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [ { "amount": 4, "code": "NAICS 9876", "name": "NAICS DESC 9876", "id": None }, { "amount": 2, "code": "NAICS 1234", "name": "NAICS DESC 1234", "id": None }, ], } assert expected_response == spending_by_category_logic
def test_category_funding_agency_awards(mock_matviews_qs, mock_agencies): mock_toptier = MockModel(toptier_agency_id=1, name="Department of Calzone", abbreviation="DOC") mock_agency = MockModel(id=2, toptier_agency=mock_toptier, toptier_flag=True) mock_agency_1 = MockModel(id=3, toptier_agency=mock_toptier, toptier_flag=False) mock_model_1 = MockModel( funding_agency_id=2, funding_toptier_agency_name="Department of Calzone", funding_toptier_agency_abbreviation="DOC", generated_pragmatic_obligation=50, ) mock_model_2 = MockModel( funding_agency_id=3, funding_toptier_agency_name="Department of Calzone", funding_toptier_agency_abbreviation="DOC", generated_pragmatic_obligation=50, ) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) add_to_mock_objects(mock_agencies["agency"], [mock_agency, mock_agency_1]) test_payload = { "category": "funding_agency", "subawards": False, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "funding_agency", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 100, "name": "Department of Calzone", "code": "DOC", "id": 2 }], } assert expected_response == spending_by_category_logic
def test_category_psc_awards(mock_matviews_qs, mock_psc): mock_psc_1 = MockModel(code="PSC 1234", description="PSC DESCRIPTION UP") mock_psc_2 = MockModel(code="PSC 9876", description="PSC DESCRIPTION DOWN") mock_model_1 = MockModel(product_or_service_code="PSC 1234", generated_pragmatic_obligation=1) mock_model_2 = MockModel(product_or_service_code="PSC 1234", generated_pragmatic_obligation=1) mock_model_3 = MockModel(product_or_service_code="PSC 9876", generated_pragmatic_obligation=2) mock_model_4 = MockModel(product_or_service_code="PSC 9876", generated_pragmatic_obligation=2) add_to_mock_objects( mock_matviews_qs, [mock_model_1, mock_model_2, mock_model_3, mock_model_4]) add_to_mock_objects(mock_psc, [mock_psc_1, mock_psc_2]) test_payload = { "category": "psc", "subawards": False, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "psc", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [ { "amount": 4, "code": "PSC 9876", "id": None, "name": "PSC DESCRIPTION DOWN" }, { "amount": 2, "code": "PSC 1234", "id": None, "name": "PSC DESCRIPTION UP" }, ], } assert expected_response == spending_by_category_logic
def test_category_awarding_subagency_subawards(mock_matviews_qs, mock_agencies): mock_subtier = MockModel(subtier_agency_id=1, name='Department of Sub-pizza', abbreviation='DOSP') mock_agency = MockModel(id=2, subtier_agency=mock_subtier, toptier_flag=False) mock_agency_1 = MockModel(id=3, subtier_agency=mock_subtier, toptier_flag=True) mock_model_1 = MockModel( awarding_agency_id=2, awarding_subtier_agency_name='Department of Sub-pizza', awarding_subtier_agency_abbreviation='DOSP', amount=10) mock_model_2 = MockModel( awarding_agency_id=3, awarding_subtier_agency_name='Department of Sub-pizza', awarding_subtier_agency_abbreviation='DOSP', amount=10) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) add_to_mock_objects(mock_agencies['agency'], [mock_agency, mock_agency_1]) test_payload = { 'category': 'awarding_subagency', 'subawards': True, 'page': 1, 'limit': 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { 'category': 'awarding_subagency', 'limit': 50, 'page_metadata': { 'page': 1, 'next': None, 'previous': None, 'hasNext': False, 'hasPrevious': False }, 'results': [{ 'amount': 20, 'name': 'Department of Sub-pizza', 'code': 'DOSP', 'id': 2 }] } assert expected_response == spending_by_category_logic
def test_category_funding_agency_awards(mock_matviews_qs, mock_agencies): mock_toptier = MockModel(toptier_agency_id=1, name='Department of Calzone', abbreviation='DOC') mock_agency = MockModel(id=2, toptier_agency=mock_toptier, toptier_flag=True) mock_agency_1 = MockModel(id=3, toptier_agency=mock_toptier, toptier_flag=False) mock_model_1 = MockModel( funding_agency_id=2, funding_toptier_agency_name='Department of Calzone', funding_toptier_agency_abbreviation='DOC', generated_pragmatic_obligation=50) mock_model_2 = MockModel( funding_agency_id=3, funding_toptier_agency_name='Department of Calzone', funding_toptier_agency_abbreviation='DOC', generated_pragmatic_obligation=50) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) add_to_mock_objects(mock_agencies['agency'], [mock_agency, mock_agency_1]) test_payload = { 'category': 'funding_agency', 'subawards': False, 'page': 1, 'limit': 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { 'category': 'funding_agency', 'limit': 50, 'page_metadata': { 'page': 1, 'next': None, 'previous': None, 'hasNext': False, 'hasPrevious': False }, 'results': [{ 'amount': 100, 'name': 'Department of Calzone', 'code': 'DOC', 'id': 2 }] } assert expected_response == spending_by_category_logic
def test_category_federal_accounts(mock_matviews_qs): mock_model_1 = MockModel( federal_account_id=10, federal_account_display="020-0001", account_title="Test Federal Account", recipient_hash="00000-00000-00000-00000-00000", parent_recipient_unique_id="000000", generated_pragmatic_obligation=1, ) mock_model_2 = MockModel( federal_account_id=10, federal_account_display="020-0001", account_title="Test Federal Account", recipient_hash="00000-00000-00000-00000-00000", parent_recipient_unique_id="000000", generated_pragmatic_obligation=2, ) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) test_payload = { "category": "federal_account", "filters": { "recipient_id": "00000-00000-00000-00000-00000-C" }, "subawards": False, "page": 1, "limit": 50, } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "federal_account", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 3, "code": "020-0001", "name": "Test Federal Account", "id": 10 }], } assert expected_response == spending_by_category_logic
def test_category_naics_awards(mock_matviews_qs): mock_model_1 = MockModel(naics_code='NAICS 1234', naics_description='NAICS DESC 1234', generated_pragmatic_obligation=1) mock_model_2 = MockModel(naics_code='NAICS 1234', naics_description='NAICS DESC 1234', generated_pragmatic_obligation=1) mock_model_3 = MockModel(naics_code='NAICS 9876', naics_description='NAICS DESC 9876', generated_pragmatic_obligation=2) mock_model_4 = MockModel(naics_code='NAICS 9876', naics_description='NAICS DESC 9876', generated_pragmatic_obligation=2) add_to_mock_objects( mock_matviews_qs, [mock_model_1, mock_model_2, mock_model_3, mock_model_4]) test_payload = { 'category': 'naics', 'subawards': False, 'page': 1, 'limit': 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { 'category': 'naics', 'limit': 50, 'page_metadata': { 'page': 1, 'next': None, 'previous': None, 'hasNext': False, 'hasPrevious': False }, 'results': [{ 'amount': 4, 'code': 'NAICS 9876', 'name': 'NAICS DESC 9876', 'id': None }, { 'amount': 2, 'code': 'NAICS 1234', 'name': 'NAICS DESC 1234', 'id': None }] } assert expected_response == spending_by_category_logic
def test_category_psc_awards(mock_matviews_qs, mock_psc): mock_psc_1 = MockModel(code='PSC 1234', description='PSC DESCRIPTION UP') mock_psc_2 = MockModel(code='PSC 9876', description='PSC DESCRIPTION DOWN') mock_model_1 = MockModel(product_or_service_code='PSC 1234', generated_pragmatic_obligation=1) mock_model_2 = MockModel(product_or_service_code='PSC 1234', generated_pragmatic_obligation=1) mock_model_3 = MockModel(product_or_service_code='PSC 9876', generated_pragmatic_obligation=2) mock_model_4 = MockModel(product_or_service_code='PSC 9876', generated_pragmatic_obligation=2) add_to_mock_objects( mock_matviews_qs, [mock_model_1, mock_model_2, mock_model_3, mock_model_4]) add_to_mock_objects(mock_psc, [mock_psc_1, mock_psc_2]) test_payload = { 'category': 'psc', 'subawards': False, 'page': 1, 'limit': 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { 'category': 'psc', 'limit': 50, 'page_metadata': { 'page': 1, 'next': None, 'previous': None, 'hasNext': False, 'hasPrevious': False }, 'results': [{ 'amount': 4, 'code': 'PSC 9876', 'id': None, 'name': 'PSC DESCRIPTION DOWN', }, { 'amount': 2, 'code': 'PSC 1234', 'id': None, 'name': 'PSC DESCRIPTION UP' }] } assert expected_response == spending_by_category_logic
def test_category_recipient_duns_subawards(recipient_test_data): test_payload = { "category": "recipient_duns", "subawards": True, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "recipient_duns", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [ { "amount": 15, "name": "MULTIPLE RECIPIENTS", "code": None, "recipient_id": None }, { "amount": 11, "name": "JOHN DOE", "code": "1234JD4321", "recipient_id": "f9006d7e-fa6c-fa1c-6bc5-964fe524a949-C", }, { "amount": 2, "name": "UNIVERSITY OF PAWNEE", "code": "00UOP00", "recipient_id": "f9006d7e-fa6c-fa1c-6bc5-964fe524a948-P", }, ], "messages": [get_time_period_message()], } assert expected_response == spending_by_category_logic
def test_category_cfda_awards(mock_matviews_qs, mock_cfda): mock_model_cfda = MockModel(program_title="CFDA TITLE 1234", program_number="CFDA1234", id=1) mock_model_1 = MockModel(cfda_number="CFDA1234", generated_pragmatic_obligation=1) mock_model_2 = MockModel(cfda_number="CFDA1234", generated_pragmatic_obligation=1) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) add_to_mock_objects(mock_cfda, [mock_model_cfda]) test_payload = { "category": "cfda", "subawards": False, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "cfda", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 2, "code": "CFDA1234", "name": "CFDA TITLE 1234", "id": 1 }], } assert expected_response == spending_by_category_logic
def test_category_country(mock_matviews_qs): mock_model_1 = MockModel(pop_country_code='US', generated_pragmatic_obligation=1) mock_model_2 = MockModel(pop_country_code='US', generated_pragmatic_obligation=1) mommy.make( 'references.RefCountryCode', country_name='UNITED STATES', country_code='US', ) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) test_payload = { 'category': 'country', 'subawards': False, 'page': 1, 'limit': 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { 'category': 'country', 'limit': 50, 'page_metadata': { 'page': 1, 'next': None, 'previous': None, 'hasNext': False, 'hasPrevious': False }, 'results': [{ 'amount': 2, 'code': 'US', 'name': 'UNITED STATES', 'id': None }] } assert expected_response == spending_by_category_logic
def test_category_cfda_awards(mock_matviews_qs, mock_cfda): mock_model_cfda = MockModel(program_title='CFDA TITLE 1234', program_number='CFDA1234', id=1) mock_model_1 = MockModel(cfda_number='CFDA1234', generated_pragmatic_obligation=1) mock_model_2 = MockModel(cfda_number='CFDA1234', generated_pragmatic_obligation=1) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) add_to_mock_objects(mock_cfda, [mock_model_cfda]) test_payload = { 'category': 'cfda', 'subawards': False, 'page': 1, 'limit': 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { 'category': 'cfda', 'limit': 50, 'page_metadata': { 'page': 1, 'next': None, 'previous': None, 'hasNext': False, 'hasPrevious': False }, 'results': [{ 'amount': 2, 'code': 'CFDA1234', 'name': 'CFDA TITLE 1234', 'id': 1 }] } assert expected_response == spending_by_category_logic
def test_category_state_territory(mock_matviews_qs): mock_model_1 = MockModel(pop_state_code='XY', generated_pragmatic_obligation=1) mock_model_2 = MockModel(pop_state_code='XY', generated_pragmatic_obligation=1) mommy.make( 'recipient.StateData', name='Test State', code='XY', ) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) test_payload = { 'category': 'state_territory', 'subawards': False, 'page': 1, 'limit': 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { 'category': 'state_territory', 'limit': 50, 'page_metadata': { 'page': 1, 'next': None, 'previous': None, 'hasNext': False, 'hasPrevious': False }, 'results': [{ 'amount': 2, 'code': 'XY', 'name': 'Test State', 'id': None }] } assert expected_response == spending_by_category_logic
def test_category_naics_awards(naics_test_data): test_payload = { "category": "naics", "subawards": False, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "naics", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [ { "amount": 4, "code": "NAICS 9876", "name": "SOURCE NAICS DESC 9876", "id": None }, { "amount": 2, "code": "NAICS 1234", "name": "SOURCE NAICS DESC 1234", "id": None }, ], "messages": [get_time_period_message()], } assert expected_response == spending_by_category_logic
def test_category_psc_awards(psc_test_data): test_payload = { "category": "psc", "subawards": False, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "psc", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [ { "amount": 4, "code": "9876", "id": None, "name": "PSC DESCRIPTION DOWN" }, { "amount": 2, "code": "1234", "id": None, "name": "PSC DESCRIPTION UP" }, ], "messages": [get_time_period_message()], } assert expected_response == spending_by_category_logic
def test_category_county_awards(geo_test_data): test_payload = { "category": "county", "subawards": False, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "county", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [ { "amount": 7, "code": "001", "name": "SOMEWHEREVILLE", "id": None }, { "amount": 3, "code": "004", "name": "COUNTYSVILLE", "id": None }, ], "messages": [get_time_period_message()], } assert expected_response == spending_by_category_logic
def test_category_country(mock_matviews_qs): mock_model_1 = MockModel(pop_country_code="US", generated_pragmatic_obligation=1) mock_model_2 = MockModel(pop_country_code="US", generated_pragmatic_obligation=1) mommy.make("references.RefCountryCode", country_name="UNITED STATES", country_code="US") add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) test_payload = { "category": "country", "subawards": False, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "country", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 2, "code": "US", "name": "UNITED STATES", "id": None }], } assert expected_response == spending_by_category_logic
def test_category_district_awards_multiple_districts(mock_matviews_qs): mock_model_1 = MockModel(pop_congressional_code="90", pop_state_code="XY", generated_pragmatic_obligation=1) mock_model_2 = MockModel(pop_congressional_code="90", pop_state_code="XY", generated_pragmatic_obligation=1) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) test_payload = { "category": "district", "subawards": False, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "district", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 2, "code": "90", "name": "XY-MULTIPLE DISTRICTS", "id": None }], } assert expected_response == spending_by_category_logic
def test_category_county_subawards(mock_matviews_qs): mock_model_1 = MockModel(pop_county_code="04", pop_county_name="COUNTYSVILLE", amount=1) mock_model_2 = MockModel(pop_county_code="04", pop_county_name="COUNTYSVILLE", amount=1) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) test_payload = { "category": "county", "subawards": True, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "county", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [{ "amount": 2, "code": "04", "name": "COUNTYSVILLE", "id": None }], } assert expected_response == spending_by_category_logic
def test_category_county_awards(mock_matviews_qs): mock_model_1 = MockModel(pop_county_code='04', pop_county_name='COUNTYSVILLE', generated_pragmatic_obligation=1) mock_model_2 = MockModel(pop_county_code='04', pop_county_name='COUNTYSVILLE', generated_pragmatic_obligation=1) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) test_payload = { 'category': 'county', 'subawards': False, 'page': 1, 'limit': 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { 'category': 'county', 'limit': 50, 'page_metadata': { 'page': 1, 'next': None, 'previous': None, 'hasNext': False, 'hasPrevious': False }, 'results': [{ 'amount': 2, 'code': '04', 'name': 'COUNTYSVILLE', 'id': None }] } assert expected_response == spending_by_category_logic
def test_category_district_subawards(geo_test_data): test_payload = { "category": "district", "subawards": True, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "district", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [ { "amount": 2, "code": "90", "name": "XY-MULTIPLE DISTRICTS", "id": None }, { "amount": 2, "code": "06", "name": "XY-06", "id": None }, ], "messages": [get_time_period_message()], } assert expected_response == spending_by_category_logic
def test_category_district_subawards(mock_matviews_qs): mock_model_1 = MockModel(pop_congressional_code='06', pop_state_code='XY', amount=1) mock_model_2 = MockModel(pop_congressional_code='06', pop_state_code='XY', amount=1) add_to_mock_objects(mock_matviews_qs, [mock_model_1, mock_model_2]) test_payload = { 'category': 'district', 'subawards': True, 'page': 1, 'limit': 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { 'category': 'district', 'limit': 50, 'page_metadata': { 'page': 1, 'next': None, 'previous': None, 'hasNext': False, 'hasPrevious': False }, 'results': [{ 'amount': 2, 'code': '06', 'name': 'XY-06', 'id': None }] } assert expected_response == spending_by_category_logic
def test_category_recipient_parent_duns_subawards(mock_matviews_qs, mock_recipients): mock_recipient_1 = MockModel(recipient_unique_id="00UOP00", legal_entity_id=1) mock_recipient_2 = MockModel(recipient_unique_id="1234JD4321", legal_entity_id=2) mock_model_1 = MockModel(recipient_name="University of Pawnee", parent_recipient_unique_id="00UOP00", amount=1) mock_model_2 = MockModel(recipient_name="University of Pawnee", parent_recipient_unique_id="00UOP00", amount=1) mock_model_3 = MockModel(recipient_name="John Doe", parent_recipient_unique_id="1234JD4321", amount=1) mock_model_4 = MockModel(recipient_name="John Doe", parent_recipient_unique_id="1234JD4321", amount=10) add_to_mock_objects( mock_matviews_qs, [mock_model_1, mock_model_2, mock_model_3, mock_model_4]) add_to_mock_objects(mock_recipients, [mock_recipient_1, mock_recipient_2]) test_payload = { "category": "recipient_parent_duns", "subawards": True, "page": 1, "limit": 50 } spending_by_category_logic = BusinessLogic(test_payload).results() expected_response = { "category": "recipient_parent_duns", "limit": 50, "page_metadata": { "page": 1, "next": None, "previous": None, "hasNext": False, "hasPrevious": False }, "results": [ { "amount": 11, "name": "John Doe", "code": "1234JD4321", "id": 2 }, { "amount": 2, "name": "University of Pawnee", "code": "00UOP00", "id": 1 }, ], } assert expected_response == spending_by_category_logic