def test_view_with_search(self, staff_client, program_data): """ Tests that ReviewFinancialAidView returns the expected results with search """ fin_aid_status = FinancialAidStatus.AUTO_APPROVED profiles = ProfileFactory.create_batch( 4, first_name=factory.Iterator(['match_name', 'x', 'y', 'z']), last_name=factory.Iterator(['x', 'y', 'z', 'match_name']), ) FinancialAidFactory.create_batch( 4, tier_program=program_data.tier_programs["0k"], status=fin_aid_status, user=factory.Iterator([p.user for p in profiles]) ) name_query = 'match_name' url = self.review_url(program_data.program.id, status=fin_aid_status, search_param=name_query) resp = staff_client.get(url) assert resp.status_code == status.HTTP_200_OK financial_aid_objects = resp.context_data["financial_aid_objects"] # Two users should match the search term - one for first_name, one for last_name assert len(financial_aid_objects) == 2 assert all( name_query in (fin_aid.user.profile.first_name, fin_aid.user.profile.last_name) for fin_aid in financial_aid_objects )
def test_view_with_search(self, staff_client, program_data): """ Tests that ReviewFinancialAidView returns the expected results with search """ fin_aid_status = FinancialAidStatus.AUTO_APPROVED profiles = ProfileFactory.create_batch( 4, first_name=factory.Iterator(['match_name', 'x', 'y', 'z']), last_name=factory.Iterator(['x', 'y', 'z', 'match_name']), ) FinancialAidFactory.create_batch( 4, tier_program=program_data.tier_programs["0k"], status=fin_aid_status, user=factory.Iterator([p.user for p in profiles]) ) name_query = 'match_name' url = self.review_url(program_data.program.id, status=fin_aid_status, search_param=name_query) resp = staff_client.get(url) assert resp.status_code == status.HTTP_200_OK financial_aid_objects = resp.context_data["financial_aid_objects"] # Two users should match the search term - one for first_name, one for last_name assert len(financial_aid_objects) == 2 assert all( fin_aid.user.profile.first_name == name_query or fin_aid.user.profile.last_name == name_query for fin_aid in financial_aid_objects )
def test_filter_and_sorting(self, staff_client, program_data, fin_aid_status, sort_param): """ Tests ReviewFinancialAidView correctly applies sort and filter parameters, or uses defaults for those parameters """ FinancialAidFactory.create_batch( 10, tier_program=program_data.tier_programs["0k"], status=factory.Iterator([ ReviewFinancialAidView.default_status, FinancialAidStatus.AUTO_APPROVED ]) ) url = self.review_url(program_data.program.id, status=fin_aid_status, sort_param=sort_param) resp = staff_client.get(url) assert resp.status_code == status.HTTP_200_OK financial_aid_objects = resp.context_data["financial_aid_objects"] # View should filter FinancialAid objects by the provided status or a default status expected_status = fin_aid_status or ReviewFinancialAidView.default_status assert all(fin_aid.status == expected_status for fin_aid in financial_aid_objects) # View should sort by the given parameter, or sort by ascending last name by default should_reverse_sort = sort_param == '-last_name' assert ( list(financial_aid_objects) == sorted(financial_aid_objects, key=lambda f: f.user.last_name, reverse=should_reverse_sort) )
def test_filter_and_sorting(self, staff_client, program_data, fin_aid_status, sort_param): """ Tests ReviewFinancialAidView correctly applies sort and filter parameters, or uses defaults for those parameters """ FinancialAidFactory.create_batch( 10, tier_program=program_data.tier_programs["0k"], status=factory.Iterator([ ReviewFinancialAidView.default_status, FinancialAidStatus.AUTO_APPROVED ]) ) url = self.review_url(program_data.program.id, status=fin_aid_status, sort_param=sort_param) resp = staff_client.get(url) assert resp.status_code == status.HTTP_200_OK financial_aid_objects = resp.context_data["financial_aid_objects"] # View should filter FinancialAid objects by the provided status or a default status expected_status = fin_aid_status or ReviewFinancialAidView.default_status assert all(fin_aid.status == expected_status for fin_aid in financial_aid_objects) # View should sort by the given parameter, or sort by ascending last name by default should_reverse_sort = sort_param == '-last_name' assert ( list(financial_aid_objects) == sorted(financial_aid_objects, key=lambda f: f.user.last_name, reverse=should_reverse_sort) )