Skip to content

Commit

Permalink
Merge pull request #315 from cfpb/dev
Browse files Browse the repository at this point in the history
Dev => Master
  • Loading branch information
sephcoster authored Jul 16, 2020
2 parents 196ddce + a3a99ae commit 79dd0a7
Show file tree
Hide file tree
Showing 128 changed files with 13,691 additions and 994 deletions.
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
presets: [
'react-app'
],
plugins: [
'@babel/plugin-proposal-class-properties'
]
}
3 changes: 2 additions & 1 deletion ccdb5_ui/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.staticfiles',
'ccdb5_ui'
'ccdb5_ui',
'flags',
)

MIDDLEWARE_CLASSES = (
Expand Down
2 changes: 1 addition & 1 deletion ccdb5_ui/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

try:
from django.urls import re_path
except ImportError:
except ImportError: # pragma: no cover
from django.conf.urls import url as re_path


Expand Down
21 changes: 17 additions & 4 deletions ccdb5_ui/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
from django.test import RequestFactory, SimpleTestCase
from unittest.mock import patch

from ccdb5_ui.views import CCDB5MainView
from django.test import RequestFactory, SimpleTestCase


class CCDB5MainViewTest(SimpleTestCase):
def setUp(self):
self.factory = RequestFactory()
self.view = CCDB5MainView.as_view()

def test_get_supported_user_agent(self):
@patch('ccdb5_ui.views.flag_enabled')
def test_get_supported_user_agent(self, mock_flag_enabled):
mock_flag_enabled.return_value = True

request = self.factory.get('/', HTTP_USER_AGENT="Foo")
response = self.view(request)
self.assertContains(response, "Search the Consumer Complaint Database")
mock_flag_enabled.assert_called_once_with('CCDB5_TRENDS')

@patch('ccdb5_ui.views.flag_enabled')
def test_get_unsupported_user_agent(self, mock_flag_enabled):
mock_flag_enabled.return_value = True

def test_get_unsupported_user_agent(self):
request = self.factory.get('/', HTTP_USER_AGENT="MSIE 8.0;")
response = self.view(request)
self.assertContains(response, "A more up-to-date browser is required")
mock_flag_enabled.assert_called_once_with('CCDB5_TRENDS')

@patch('ccdb5_ui.views.flag_enabled')
def test_get_no_user_agent(self, mock_flag_enabled):
mock_flag_enabled.return_value = True

def test_get_no_user_agent(self):
request = self.factory.get('/')
response = self.view(request)
self.assertContains(response, "Search the Consumer Complaint Database")
mock_flag_enabled.assert_called_once_with('CCDB5_TRENDS')
13 changes: 12 additions & 1 deletion ccdb5_ui/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.views.generic.base import TemplateView
from django.conf import settings
from flags.state import flag_enabled

try:
STANDALONE = settings.STANDALONE
except: # pragma: no cover
except Exception: # pragma: no cover
STANDALONE = False


Expand All @@ -19,6 +20,7 @@
'MSIE 7.0;',
]


class CCDB5MainView(TemplateView):
template_name = 'ccdb5_ui/ccdb-main.html'
base_template = BASE_TEMPLATE
Expand All @@ -41,3 +43,12 @@ def get_context_data(self, **kwargs):
context['ccdb5_base_template'] = self.base_template
context['unsupported_browser'] = unsupported
return context

def render_to_response(self, context, **response_kwargs):
response = super(CCDB5MainView, self).render_to_response(
context, **response_kwargs)

show_trends = flag_enabled('CCDB5_TRENDS')

response.set_cookie('showTrends', 'show' if show_trends else 'hide')
return response
Loading

0 comments on commit 79dd0a7

Please sign in to comment.