def test_should_return_empty_list_for_last_name_not_matched(self, mock_search): mock_search.return_value = MockQuery(None) request = testing.DummyRequest(params={'last_name': 'page'}) response = colleagues_by_last_name(request) self.assertEqual(response, [])
def test_should_return_400_for_missing_last_name_arg(self): request = testing.DummyRequest() request.context = testing.DummyResource() response = colleagues_by_last_name(request) self.assertEqual(response.status_code, 400) self.assertEqual(json.loads(response.body), {'error': 'Query string field is missing: last_name'})
def test_last_names_should_begin_with_query_string(self, mock_search): mock_search.return_value = MockQuery(self.colleague) request = testing.DummyRequest(params={'last_name': 'page'}) exp = Colleague.last_name.like("Page%") response = colleagues_by_last_name(request) self.assertTrue(mock_search.called_with(Colleague)) self.assertTrue(exp.compare(mock_search.return_value._query_filter.query_params()))
def test_should_return_list_of_colleagues_by_last_name(self, mock_search, colleague_urls): request = testing.DummyRequest(params={'last_name': 'Page'}) request.context = testing.DummyResource() mock_search.return_value = MockQuery(self.colleague) colleague_urls.return_value = [self.url_1, self.url_2] response = colleagues_by_last_name(request) self.assertEqual(response, [{ 'format_name': self.colleague.format_name, 'work_phone': self.colleague.work_phone, 'organization': self.colleague.institution, 'first_name': self.colleague.first_name, 'last_name': self.colleague.last_name, 'email': self.colleague.email, 'fax': self.colleague.fax, 'webpages': { 'lab_url': self.url_2.obj_url, 'research_summary_url': self.url_1.obj_url } }])