Skip to content

Commit

Permalink
Fix issue where zip code was not filtering and add tests to cover all…
Browse files Browse the repository at this point in the history
… of the new fields
  • Loading branch information
amymok committed Jul 20, 2017
1 parent 96cd59e commit 1b69439
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion complaint_search/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SearchInputSerializer(serializers.Serializer):
child=serializers.CharField(max_length=200), required=False)
state = serializers.ListField(
child=serializers.ChoiceField(STATE_CHOICES), required=False)
zipcode = serializers.ListField(
zip_code = serializers.ListField(
child=serializers.CharField(min_length=5, max_length=5), required=False)
timely = serializers.ListField(
child=serializers.CharField(max_length=200), required=False)
Expand Down
84 changes: 84 additions & 0 deletions complaint_search/tests/test_views_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,30 @@ def test_search_with_state__valid(self, mock_essearch):
**{"state": ["CA", "FL", "VA"]})
self.assertEqual('OK', response.data)

@mock.patch('complaint_search.es_interface.search')
def test_search_with_zip_code__valid(self, mock_essearch):
url = reverse('complaint_search:search')
url += "?zip_code=94XXX&zip_code=24236&zip_code=23456"
mock_essearch.return_value = 'OK'
response = self.client.get(url)
self.assertEqual(status.HTTP_200_OK, response.status_code)
# -*- coding: utf-8 -*-
mock_essearch.assert_called_once_with(
**{"zip_code": ["94XXX", "24236", "23456"]})
self.assertEqual('OK', response.data)

@mock.patch('complaint_search.es_interface.search')
def test_search_with_timely__valid(self, mock_essearch):
url = reverse('complaint_search:search')
url += "?timely=YES&timely=NO"
mock_essearch.return_value = 'OK'
response = self.client.get(url)
self.assertEqual(status.HTTP_200_OK, response.status_code)
# -*- coding: utf-8 -*-
mock_essearch.assert_called_once_with(
**{"timely": ["YES", "NO"]})
self.assertEqual('OK', response.data)

@mock.patch('complaint_search.es_interface.search')
def test_search_with_consumer_disputed__valid(self, mock_essearch):
url = reverse('complaint_search:search')
Expand All @@ -334,6 +358,66 @@ def test_search_with_company_response__valid(self, mock_essearch):
**{"company_response": ["Closed", "No response"]})
self.assertEqual('OK', response.data)

@mock.patch('complaint_search.es_interface.search')
def test_search_with_company_public_response__valid(self, mock_essearch):
url = reverse('complaint_search:search')
url += "?company_public_response=Closed&company_public_response=No%20response"
mock_essearch.return_value = 'OK'
response = self.client.get(url)
self.assertEqual(status.HTTP_200_OK, response.status_code)
# -*- coding: utf-8 -*-
mock_essearch.assert_called_once_with(
**{"company_public_response": ["Closed", "No response"]})
self.assertEqual('OK', response.data)

@mock.patch('complaint_search.es_interface.search')
def test_search_with_consumer_consent_provided__valid(self, mock_essearch):
url = reverse('complaint_search:search')
url += "?consumer_consent_provided=Yes&consumer_consent_provided=No"
mock_essearch.return_value = 'OK'
response = self.client.get(url)
self.assertEqual(status.HTTP_200_OK, response.status_code)
# -*- coding: utf-8 -*-
mock_essearch.assert_called_once_with(
**{"consumer_consent_provided": ["Yes", "No"]})
self.assertEqual('OK', response.data)

@mock.patch('complaint_search.es_interface.search')
def test_search_with_has_narratives__valid(self, mock_essearch):
url = reverse('complaint_search:search')
url += "?has_narratives=Yes&has_narratives=No"
mock_essearch.return_value = 'OK'
response = self.client.get(url)
self.assertEqual(status.HTTP_200_OK, response.status_code)
# -*- coding: utf-8 -*-
mock_essearch.assert_called_once_with(
**{"has_narratives": ["Yes", "No"]})
self.assertEqual('OK', response.data)

@mock.patch('complaint_search.es_interface.search')
def test_search_with_submitted_via__valid(self, mock_essearch):
url = reverse('complaint_search:search')
url += "?submitted_via=Web&submitted_via=Phone"
mock_essearch.return_value = 'OK'
response = self.client.get(url)
self.assertEqual(status.HTTP_200_OK, response.status_code)
# -*- coding: utf-8 -*-
mock_essearch.assert_called_once_with(
**{"submitted_via": ["Web", "Phone"]})
self.assertEqual('OK', response.data)

@mock.patch('complaint_search.es_interface.search')
def test_search_with_tag__valid(self, mock_essearch):
url = reverse('complaint_search:search')
url += "?tag=Older%20American&tag=Servicemember"
mock_essearch.return_value = 'OK'
response = self.client.get(url)
self.assertEqual(status.HTTP_200_OK, response.status_code)
# -*- coding: utf-8 -*-
mock_essearch.assert_called_once_with(
**{"tag": ["Older American", "Servicemember"]})
self.assertEqual('OK', response.data)

@mock.patch('complaint_search.es_interface.search')
def test_search__transport_error_with_status_code(self, mock_essearch):
mock_essearch.side_effect = TransportError(status.HTTP_404_NOT_FOUND, "Error")
Expand Down

0 comments on commit 1b69439

Please sign in to comment.