Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase test coverage #266

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ install:
- pip install -r requirements/tests.txt
- npm install less
- npm install coffee-script
- npm install -g jshint
before_script:
- psql -U postgres -c "CREATE USER tracpro WITH PASSWORD 'nyaruka';"
- psql -U postgres -c "ALTER ROLE tracpro WITH SUPERUSER;"
- psql -U tracpro postgres -c "CREATE DATABASE tracpro;"
- pipconflictchecker
- python manage.py makemigrations --dry-run | grep 'No changes detected' || (echo 'There are changes which require migrations.' && exit 1)
script:
- coverage run manage.py test
- coverage report --fail-under=75
- flake8 .
- make docs
- make -k
notifications:
hipchat: 259913064a0a577b61d874d51dfbc2@Edutrac
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
PROJECT_NAME = tracpro
STATIC_LIBS_DIR = ./$(PROJECT_NAME)/static/libs

default: lint test
default: lint test docs

test:
# Run all tests and report coverage
test: testpy testcoverage

testpy:
# Run all tests and gather coverage data (use testcoverage to report it)
# Requires coverage
coverage erase
coverage run manage.py test
coverage run manage.py test --noinput --keepdb

# This is a separate rule so we can run with 'make -k' and still get a coverage report
# even if the tests fail.
testcoverage:
coverage report -m --fail-under 80

lint-py:
Expand All @@ -18,7 +24,7 @@ lint-py:
lint-js:
# Check JS for any problems
# Requires jshint
find -name "*.js" -not -path "${STATIC_LIBS_DIR}*" -print0 | xargs -0 jshint
find -name "*.js" -not \( -path "${STATIC_LIBS_DIR}*" -o -path '*CACHE*' -o -path '*.min.js' -o -path './docs/*' -o -path './node_modules/*' \) -print0 | xargs -0 jshint --verbose

lint: lint-py lint-js

Expand Down Expand Up @@ -89,6 +95,7 @@ docs:
cd docs && make html

.PHONY: default test lint lint-py lint-js generate-secret makemessages \
pushmessages pullmessages compilemessages docs
pushmessages pullmessages compilemessages docs \
testpy testcoverage

.PRECIOUS: conf/%.pub.ssh
30 changes: 30 additions & 0 deletions tracpro/baseline/tests/test_charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,33 @@ def test_chart_data__universal(self):
{'y': 84.0}, # 14 + 28 + 42
{'y': 126.0}, # 21 + 42 + 63
])

def test_chart_data__with_user_goal(self):
user_goal = 666
self.filter_form.data['goal'] = user_goal
series, categories, summary_data = self.get_data(region=None, include_subregions=True)

# There should be 3 dates to match each follow-up pollrun.
self.assertEqual(categories, [
"2015-01-02",
"2015-01-03",
"2015-01-04",
])

self.assertEqual(summary_data['Dates'], 'January 01, 2015 - January 04, 2015')
self.assertIsNone(summary_data['Baseline response rate (%)'])
self.assertEqual(summary_data['Baseline value (# cats)'], user_goal)
self.assertEqual(summary_data['Follow up mean (# cats)'], 84.0)
self.assertEqual(summary_data['Follow up standard deviation'], 34.3)
self.assertEqual(summary_data['Follow up response rate (%)'], 100)

# Series length should match that of follow-up.
# 10 + 20 + 30 = 60
self.assertEqual(series['Baseline'], [user_goal, user_goal, user_goal])

# Follow-up should be sum of contact answers per pollrun.
self.assertEqual(series['Follow up'], [
{'y': 42.0}, # 7 + 14 + 21
{'y': 84.0}, # 14 + 28 + 42
{'y': 126.0}, # 21 + 42 + 63
])
11 changes: 11 additions & 0 deletions tracpro/polls/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ def test_list(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['object_list']), 1)

def test_read(self):
url = reverse('polls.poll_read', kwargs={'pk': self.poll1.pk})
# log in as admin
self.login(self.admin)

response = self.url_get('unicef', url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['object'].pk, self.poll1.pk)
self.assertEqual(self.poll1.name, response.context['title'])
self.assertEqual(2, len(response.context['question_data']))


class ResponseCRUDLTest(TracProDataTest):

Expand Down
Loading