def test_no_banner_when_data_invalid(self): data_json = { 'wrong_key': 5 } responses.add(responses.GET, self.test_url, json=data_json) response = ComplaintLandingView.as_view()(self.request) self.assertNoBanner(response)
def test_no_banner_when_data_not_json(self, mock_view): data_json = "not json" response = Response(data_json) mock_view.return_value = response response = ComplaintLandingView.as_view()(self.request) self.assertTrue(mock_view.call_count == 1) self.assertNoBanner(response)
def test_no_banner_when_data_invalid(self, mock_view): data_json = {'wrong_key': 5} response = Response(data_json) mock_view.return_value = response response = ComplaintLandingView.as_view()(self.request) self.assertTrue(mock_view.call_count == 1) self.assertNoBanner(response)
def test_elasticsearch_down(self, mock_view): response = Response({}) response.status = 404 mock_view.return_value = response response = ComplaintLandingView.as_view()(self.request) self.assertTrue(mock_view.call_count == 1) self.assertNoBanner(response)
def test_no_banner_when_data_fetch_fails(self): responses.add( responses.GET, self.test_url, body=RequestException("test") ) response = ComplaintLandingView.as_view()(self.request) self.assertNoBanner(response)
def test_data_up_to_date(self): data_json = { '_meta': { 'last_indexed': self.two_days_ago(), 'last_updated': self.two_days_ago(), }, } responses.add(responses.GET, self.test_url, json=data_json) response = ComplaintLandingView.as_view()(self.request) self.assertNoBanner(response)
def test_data_up_to_date(self): data_json = { 'stats': { 'last_updated': self.two_days_ago(), 'last_updated_narratives': self.two_days_ago(), }, } responses.add(responses.GET, self.test_url, json=data_json) response = ComplaintLandingView.as_view()(self.request) self.assertNoBanner(response)
def test_narratives_out_of_date(self): data_json = { 'stats': { 'last_updated': self.two_days_ago(), 'last_updated_narratives': '2010-01-01', }, } responses.add(responses.GET, self.test_url, json=data_json) response = ComplaintLandingView.as_view()(self.request) self.assertContains(response, 'show-narratives-notification')
def test_narratives_out_of_date(self): data_json = { '_meta': { 'last_indexed': self.two_days_ago(), 'last_updated': '2010-01-01', }, } responses.add(responses.GET, self.test_url, json=data_json) response = ComplaintLandingView.as_view()(self.request) self.assertContains(response, 'show-narratives-notification')
def test_data_up_to_date(self, mock_view): data_json = { '_meta': { 'last_indexed': self.two_days_ago(), 'last_updated': self.two_days_ago(), }, } response = Response(data_json) mock_view.return_value = response response = ComplaintLandingView.as_view()(self.request) self.assertTrue(mock_view.call_count == 1) self.assertNoBanner(response)
def test_narratives_out_of_date(self, mock_view): data_json = { '_meta': { 'last_indexed': self.two_days_ago(), 'last_updated': '2010-01-01', }, } response = Response(data_json) mock_view.return_value = response response.status = 200 response = ComplaintLandingView.as_view()(self.request) self.assertTrue(mock_view.call_count == 1) self.assertContains(response, 'show-narratives-notification')
def test_no_banner_when_data_not_json(self): responses.add(responses.GET, self.test_url, body="not json") response = ComplaintLandingView.as_view()(self.request) self.assertNoBanner(response)
def test_no_banner_when_data_fetch_fails(self, mock_view): mock_view.return_value = Response('bleh') mock_view.side_effect = ValueError("test value error") response = ComplaintLandingView.as_view()(self.request) self.assertTrue(mock_view.call_count == 1) self.assertNoBanner(response)
def test_no_banner_when_key_error(self, mock_view): mock_view.return_value = Response('bleh') mock_view.side_effect = KeyError("test key error") response = ComplaintLandingView.as_view()(self.request) self.assertTrue(mock_view.call_count == 1) self.assertNoBanner(response)
def test_no_stats_source(self): response = ComplaintLandingView.as_view()(self.request) self.assertNoBanner(response)
], namespace='transcripts')), url(r'^paying-for-college/', include_if_app_enabled('comparisontool', 'comparisontool.urls')), url( r'^paying-for-college2/', include_if_app_enabled('paying_for_college', 'paying_for_college.config.urls')), url(r'^credit-cards/agreements/', include('agreements.urls')), url( r'^consumer-tools/retirement/', include_if_app_enabled('retirement_api', 'retirement_api.urls', namespace='retirement_api')), url(r'^data-research/consumer-complaints/$', ComplaintLandingView.as_view(), name='complaint-landing'), # CCDB5-API flagged_url( 'CCDB5_RELEASE', r'^data-research/consumer-complaints/search/api/v1/', include_if_app_enabled('complaint_search', 'complaint_search.urls')), # If 'CCDB5_RELEASE' is True, include CCDB5 urls. flagged_url('CCDB5_RELEASE', r'^data-research/consumer-complaints/search/', include_if_app_enabled('ccdb5_ui', 'ccdb5_ui.config.urls')), url(r'^oah-api/rates/', include_if_app_enabled('ratechecker', 'ratechecker.urls')), url(r'^oah-api/county/', include_if_app_enabled('countylimits', 'countylimits.urls')), url(r'^find-a-housing-counselor/$', HousingCounselorView.as_view(),
url(r'^paying-for-college/', include_if_app_enabled('comparisontool', 'comparisontool.urls')), url(r'^paying-for-college2/', include_if_app_enabled( 'paying_for_college', 'paying_for_college.config.urls')), url(r'^credit-cards/agreements/', include('agreements.urls')), url(r'^consumer-tools/retirement/', include_if_app_enabled( 'retirement_api', 'retirement_api.urls', namespace='retirement_api' )), url(r'^data-research/consumer-complaints/$', ComplaintLandingView.as_view(), name='complaint-landing'), # CCDB5-API flagged_url('CCDB5_RELEASE', r'^data-research/consumer-complaints/search/api/v1/', include_if_app_enabled('complaint_search', 'complaint_search.urls') ), # If 'CCDB5_RELEASE' is True, include CCDB5 urls. flagged_url('CCDB5_RELEASE', r'^data-research/consumer-complaints/search/', include_if_app_enabled( 'ccdb5_ui', 'ccdb5_ui.config.urls' )),