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

Commit

Permalink
Merge branch 'master' into update_deps
Browse files Browse the repository at this point in the history
  • Loading branch information
anselmbradford committed Mar 13, 2018
2 parents b3bcad7 + c021e63 commit 9de95f2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 136 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
language: python
python:
- '2.7'
nodejs: 6
nodejs: 8
sudo: false
env:
- DEPLOY_ENV=DEV
- DJANGO_SETTINGS_MODULE=ccdb.settings
global:
- DEPLOY_ENV=DEV
- DJANGO_SETTINGS_MODULE=ccdb.settings
install:
- pip install -r requirements.txt
- pip install -r test_requirements.txt
Expand Down
2 changes: 2 additions & 0 deletions ccdb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'wagtail.wagtailcore',
'flags',
'complaint_common',
'complaint',
'complaintdatabase',
Expand Down
14 changes: 14 additions & 0 deletions complaintdatabase/templates/landing-page.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{% extends 'base_responsive.html' %}
{% load staticfiles %}
{% load humanize %}
{% load feature_flags %}

{% block title %}Consumer Complaint Database{% endblock %}

{% block content %}
{% flag_enabled 'CCDB5_RELEASE' as CCDB5_RELEASE %}
<div id="ccdb-landing">
<!--
If the data has not been updated, add class 'show-data-notification' to cf-notification
Expand Down Expand Up @@ -42,14 +44,22 @@ <h1 class="hero_heading">Consumer Complaint Database</h1>
<img class="isocon" src="{% static 'complaint_common/img/read.png' %}">
<p>Consumers have let us know they want to share their complaint descriptions so others can learn from their experience.</p>
<div class="btn-holder">
{% if CCDB5_RELEASE %}
<p><a href="/data-research/consumer-complaints/search/?has_narrative=true" target="_blank" class="btn">Read consumer narratives</a></p>
{% else %}
<p><a href="https://data.consumerfinance.gov/d/nsyy-je5y" target="_blank" class="btn">Read consumer narratives</a></p>
{% endif %}
</div>
</div>
<div class="content-l_col content-l_col-1-3">
<img class="isocon" src="{% static 'complaint_common/img/view.png' %}">
<p>View, sort, and filter data right in your browser.</p>
<div class="btn-holder">
{% if CCDB5_RELEASE %}
<p><a href="/data-research/consumer-complaints/search/" target="_blank" class="btn">View complaint data</a></p>
{% else %}
<p><a href="https://data.consumerfinance.gov/d/s6ew-h6mp" target="_blank" class="btn">View complaint data</a></p>
{% endif %}
</div>
</div>
<div class="content-l_col content-l_col-1-3">
Expand Down Expand Up @@ -149,7 +159,11 @@ <h2 id="download-the-data">Download the data</h2>
</a>
</li>
<li class="list_item">
{% if CCDB5_RELEASE %}
<a class="list_link" href="/data-research/consumer-complaints/search/">
{% else %}
<a class="list_link" href="https://data.consumerfinance.gov/d/s6ew-h6mp">
{% endif %}
Filter the full data set
</a>
</li>
Expand Down
52 changes: 4 additions & 48 deletions complaintdatabase/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

from requests.exceptions import ConnectionError

from .views import (LandingView, DocsView, get_narratives_json,
format_narratives, get_stats, is_data_not_updated)
from .views import (LandingView, DocsView, get_narratives_json, get_stats,
is_data_not_updated)


MOCK_404 = ConnectionError(Mock(return_value={'status': 404}), 'not found')
client = Client()
Expand All @@ -30,18 +31,15 @@ def test_get_context_data_exist(self):
response = LandingView.as_view()(request)
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())

@skipIf(not getattr(settings, 'STANDALONE', 'False'),
"not running standlone")
@skipIf(True, "not running with feature flags")
def test_demo_json(self):
"""Test demo version of landing page"""
response = client.get(reverse("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())


Expand Down Expand Up @@ -87,48 +85,6 @@ def test_incorrect_text_get_narratives_json(self, mock_get):
self.assertTrue(mock_get.call_count == 1)


class FormatNarrativesTest(TestCase):
def test_format_narratives(self):
input_json = {
'bank_accounts': {'date_received': '2015-04-08T20:32:15',
'tags': ['Older American', 'Servicemember']},
'credit_cards': {'date_received': '2015-04-08T20:32:16',
'tags': ['Older American', 'Servicemember']},
'credit_reporting': {'date_received': '2015-04-08T20:32:17',
'tags': ['Older American', 'Servicemember']},
'debt_collection': {'date_received': '2015-04-08T20:32:18',
'tags': ['Older American', 'Servicemember']},
'money_transfers': {'date_received': '2015-04-08T20:32:19',
'tags': ['Older American', 'Servicemember']},
'mortgages': {'date_received': '2015-04-08T21:32:15',
'tags': ['Older American', 'Servicemember']},
'other_financial_services': {'date_received':
'2015-04-09T20:32:15'},
'payday_loans': {'date_received': '2015-04-10T20:32:15'},
'prepaid_cards': {'date_received': '2015-04-11T20:32:15'},
'student_loans': {'date_received': '2015-04-12T20:32:15'},
'other_consumer_loans': {'date_received': '2015-04-13T20:32:15'}
}
sorted_titles = ['Bank account', 'Credit card',
'Credit reporting', 'Debt collection',
'Money transfer or virtual currency', 'Mortgage',
'Other financial service', 'Payday loan',
'Prepaid card', 'Student loan',
'Vehicle / consumer loan']
res = format_narratives(input_json)
self.assertEqual(len(res), 11)
res_titles = sorted([entry['title'] for entry in res])
self.assertEqual(res_titles, sorted_titles)
for date in [entry['date'] for entry in res]:
self.assertEqual(type(date), datetime)

def test_invalid_json_format_narratives(self):
with patch('sys.stdout', new=StringIO()) as fakeOutput:
res = format_narratives({})
self.assertEqual(res, [])
self.assertIn('KeyError', fakeOutput.getvalue().strip())


class GetStatsTest(TestCase):
def test_get_stats(self):
input_json = {'stats': {'test': 1}}
Expand Down
85 changes: 0 additions & 85 deletions complaintdatabase/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def get_context_data(self, **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['data_down'],
context['narratives_down']) = is_data_not_updated(res_json)
Expand Down Expand Up @@ -89,90 +88,6 @@ def get_narratives_json(demo_json=None):
return res_json


def format_narratives(res_json):
"""Set up label and css values for page."""
narratives = []

# Additional data needed to output the narratives on the page
# title, css, and icon are required
# optional 'tooltip' determines text that displays on section button hover
# 'tooltip' defaults to title
narrative_types = [
{'key': 'bank_accounts',
'title': 'Bank account',
'css': 'bank-account',
'icon': 'bank-account'},
{'key': 'credit_cards',
'title': 'Credit card',
'css': 'credit-card',
'icon': 'credit-card'},
{'key': 'credit_reporting',
'title': 'Credit reporting',
'css': 'credit-reporting',
'icon': 'loan'},
{'key': 'debt_collection',
'title': 'Debt collection',
'css': 'debt-collection',
'icon': 'debt-collection'},
{'key': 'money_transfers',
'title': 'Money transfer or virtual currency',
'css': 'money-transfer',
'icon': 'money-transfer',
'tooltip': 'Money transfer/virtual currency'},
{'key': 'mortgages',
'title': 'Mortgage',
'css': 'mortgage',
'icon': 'owning-home'},
{'key': 'other_financial_services',
'title': 'Other financial service',
'css': 'other',
'icon': 'money'},
{'key': 'payday_loans',
'title': 'Payday loan',
'css': 'payday-loan',
'icon': 'payday-loan'},
{'key': 'prepaid_cards',
'title': 'Prepaid card',
'css': 'prepaid-card',
'icon': 'prepaid-cards'},
{'key': 'student_loans',
'title': 'Student loan',
'css': 'student-loan',
'icon': 'paying-college'},
{'key': 'other_consumer_loans',
'title': 'Vehicle / consumer loan',
'css': 'consumer-loan',
'icon': 'buying-car'}
]

try:

for index, item in enumerate(narrative_types):
# get json data for this type
narrative = res_json[item['key']]

# extend it with the additional title/css/icon/tooltip data
narrative.update(item)

# format date
narrative['date'] = datetime.strptime(narrative['date_received'],
"%Y-%m-%dT%H:%M:%S")

# add data for next item
narrative['next'] = narrative_types[(index + 1) %
len(narrative_types)]

narratives.append(narrative)

except KeyError as e:
print("format_narratives:KeyError")
print("There is problem accessing with the given key, "
"which probably means the json has missing data")
print(e)

return narratives


def get_stats(res_json):
res_stat = {}
try:
Expand Down

0 comments on commit 9de95f2

Please sign in to comment.