Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

Commit

Permalink
add demo url so demo view can actually be used
Browse files Browse the repository at this point in the history
  • Loading branch information
higs4281 committed Sep 2, 2016
1 parent 0813bac commit 9fa7516
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 31 deletions.
2 changes: 1 addition & 1 deletion complaint/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_get_context_data_exist(self):


class URLTest(TestCase):
url_names = ['ccdb_landing', 'ccdb_data_use', 'ccdb_process']
url_names = ['ccdb_submit', 'ccdb_data_use', 'ccdb_process']

def test_complaint_urls(self):
for url_name in self.url_names:
Expand Down
2 changes: 1 addition & 1 deletion complaint/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from complaint.views import SubmitView, DataUseView, ProcessView

urlpatterns = [
url(r'^$', SubmitView.as_view(), name='ccdb_landing'),
url(r'^$', SubmitView.as_view(), name='ccdb_submit'),
url(r'^data-use/', DataUseView.as_view(), name='ccdb_data_use'),
url(r'^process/', ProcessView.as_view(), name='ccdb_process'),
]
3 changes: 3 additions & 0 deletions complaint/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
else: # pragma: no cover
BASE_TEMPLATE = "front/base_update.html"


class SubmitView(TemplateView):
template_name = "submit-a-complaint.html"

Expand All @@ -24,6 +25,7 @@ def get_context_data(self, **kwargs):
context['base_template'] = BASE_TEMPLATE
return context


class DataUseView(TemplateView):
template_name = "data-use.html"

Expand All @@ -32,6 +34,7 @@ def get_context_data(self, **kwargs):
context['base_template'] = BASE_TEMPLATE
return context


class ProcessView(TemplateView):
template_name = "process.html"

Expand Down
39 changes: 12 additions & 27 deletions complaintdatabase/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@

from requests.exceptions import ConnectionError
from django.test import RequestFactory, TestCase
from django.core.urlresolvers import reverse
from django.test import Client
from datetime import datetime
from StringIO import StringIO
from .views import (LandingView, DocsView, get_narratives_json,
format_narratives, get_stats, get_count_info,
is_data_not_updated)

MOCK_404 = ConnectionError(Mock(return_value={'status': 404}), 'not found')
client = Client()


class LandingViewTest(TestCase):
Expand All @@ -28,6 +31,15 @@ def test_get_context_data_exist(self):
self.assertTrue('total_complaints' in response.context_data.keys())
self.assertTrue('timely_responses' in response.context_data.keys())

def test_demo_json(self):
"""Test demo version of landing page"""
response = client.get(reverse("complaintdatabase:ccdb-demo",
kwargs={'demo_json': 'demo.json'}))
self.assertEqual(response.status_code, 200)
self.assertTrue('base_template' in response.context_data.keys())
self.assertTrue('narratives' in response.context_data.keys())
self.assertTrue('stats' in response.context_data.keys())


class NarrativeJsonTest(TestCase):

Expand Down Expand Up @@ -317,33 +329,6 @@ def test_data_not_updated_friday_narratives_down(self, mock_get_now):
self.assertFalse(data_down)
self.assertTrue(narratives_down)

# @patch('complaintdatabase.views.get_now')
# def test_data_not_updated_saturday_down(self, mock_get_now):
# mock_get_now.return_value = datetime(2015, 12, 26, 19, 20, 10, 975427)
# input_json = {'stats': {'last_updated': "2015-12-18",
# 'last_updated_narratives': "2015-12-18"}}
# data_down, narratives_down = is_data_not_updated(input_json)
# self.assertTrue(data_down)
# self.assertFalse(narratives_down)

# @patch('complaintdatabase.views.get_now')
# def test_data_not_updated_saturday_up(self, mock_get_now):
# mock_get_now.return_value = datetime(2015, 12, 26, 19, 20, 10, 975427)
# input_json = {'stats': {'last_updated': "2015-12-21",
# 'last_updated_narratives': "2015-12-21"}}
# data_down, narratives_down = is_data_not_updated(input_json)
# self.assertFalse(data_down)
# self.assertFalse(narratives_down)

# @patch('complaintdatabase.views.get_now')
# def test_data_not_updated_saturday_narratives_down(self, mock_get_now):
# mock_get_now.return_value = datetime(2015, 12, 26, 19, 20, 10, 975427)
# input_json = {'stats': {'last_updated': "2015-12-21",
# 'last_updated_narratives': "2015-12-18"}}
# data_down, narratives_down = is_data_not_updated(input_json)
# self.assertFalse(data_down)
# self.assertTrue(narratives_down)

@patch('complaintdatabase.views.get_now')
def test_data_not_updated_saturday_down(self, mock_get_now):
mock_get_now.return_value = datetime(2015, 12, 27, 19, 20, 10, 975427)
Expand Down
15 changes: 14 additions & 1 deletion complaintdatabase/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
from django.conf import settings
from django.conf.urls import url
from complaintdatabase.views import LandingView

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

urlpatterns = [
url(r'^$', LandingView.as_view()),
url(r'^$', LandingView.as_view(),
name='ccdb-landing-page')
]

if STANDALONE:
urlpatterns += [
url(r'^demo/(?P<demo_json>[^/]+)/$', LandingView.as_view(),
name='ccdb-demo')
]
14 changes: 13 additions & 1 deletion complaintdatabase/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@


class LandingView(TemplateView):
"""
Main page view.
To run as a standalone demo with local data, put your demo json
in the 'demo.json' file at the project root and use this standalone url:
'http://127.0.0.1:8000/complaintdatabase/demo/demo.json/'
You can use a different file name; just specify it in the last URL field.
"""

template_name = "landing-page.html"

def get_context_data(self, **kwargs):
context = super(LandingView, self).get_context_data(**kwargs)
context['base_template'] = BASE_TEMPLATE
res_json = get_narratives_json()
if 'demo_json' in kwargs:
res_json = get_narratives_json(demo_json=kwargs['demo_json'])
else:
res_json = get_narratives_json()
context['narratives'] = format_narratives(res_json)
context['stats'] = get_stats(res_json)
(context['total_complaints'],
Expand Down
Loading

0 comments on commit 9fa7516

Please sign in to comment.