Skip to content

Commit 1d6cfda

Browse files
author
Emmanouil Konstantinidis
committed
Setup Tests with Coverage
1 parent b2b1b87 commit 1d6cfda

File tree

9 files changed

+73
-6
lines changed

9 files changed

+73
-6
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.coverage
2+
covhtml/
3+
14
*.pyc
25
__pycache__/
36

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Django==1.8.7
22
djangorestframework==3.3.2
3+
coverage==4.0.3
34
flake8==2.5.1

rest_framework_docs/templates/rest_framework_docs/home.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Jump To <span class="caret"></span></a>
77
<ul class="dropdown-menu">
88
{% for group in endpoints_grouped %}
9-
<li><a href="#{{ group.grouper|lower }}-nav">{{ group.grouper }}</a></li>
9+
<li><a href="#{{ group.grouper|lower }}-group">{{ group.grouper }}</a></li>
1010
{% endfor %}
1111
</ul>
1212
</li>
@@ -20,7 +20,7 @@
2020
{% if endpoints_grouped %}
2121
{% for group in endpoints_grouped %}
2222

23-
<h1 id="{{ group.grouper|lower }}-nav">{{group.grouper}}</h1>
23+
<h1 id="{{ group.grouper|lower }}-group">{{group.grouper}}</h1>
2424

2525
<div class="panel-group" role="tablist">
2626

runtests.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import subprocess
55
import django
6+
from coverage import coverage
67
from django.conf import settings
78
from django.test.utils import get_runner
89

@@ -22,15 +23,28 @@ def flake8_main(args):
2223
return command
2324

2425

25-
def django_tests_main():
26+
def run_tests_coverage():
2627
if __name__ == "__main__":
2728
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
2829
django.setup()
2930
TestRunner = get_runner(settings)
3031
test_runner = TestRunner()
32+
33+
# Setup Coverage
34+
cov = coverage(source=["rest_framework_docs"], omit=["__init__.py"])
35+
cov.start()
36+
3137
failures = test_runner.run_tests(["tests"])
32-
sys.exit(bool(failures))
3338

34-
exit_on_failure(flake8_main(FLAKE8_ARGS))
39+
if bool(failures):
40+
cov.erase()
41+
sys.exit("Tests Failed. Coverage Cancelled.")
3542

36-
django_tests_main()
43+
# If success show coverage results
44+
cov.stop()
45+
cov.save()
46+
cov.report()
47+
# cov.html_report(directory='covhtml')
48+
49+
exit_on_failure(flake8_main(FLAKE8_ARGS))
50+
exit_on_failure(run_tests_coverage())

tests/serializers.py

Whitespace-only changes.

tests/settings.py

+12
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,17 @@
1515
}
1616

1717
INSTALLED_APPS = [
18+
# Django Apps
19+
'django.contrib.staticfiles',
20+
21+
# External Packages
1822
"rest_framework",
23+
"rest_framework_docs",
1924
]
25+
26+
ROOT_URLCONF = 'tests.urls'
27+
28+
# Static files (CSS, JavaScript, Images)
29+
# https://docs.djangoproject.com/en/1.8/howto/static-files/
30+
31+
STATIC_URL = '/static/'

tests/tests.py

+26
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1+
from django.core.urlresolvers import reverse
12
from django.test import TestCase
23

34

45
class SimpleTest(TestCase):
56

67
def test_details(self):
78
self.assertEqual(1, 1)
9+
10+
11+
class DRFDocsViewTests(TestCase):
12+
def setUp(self):
13+
super(DRFDocsViewTests, self).setUp()
14+
15+
def test_index_view_with_no_questions(self):
16+
"""
17+
Should load the drf focs view
18+
"""
19+
response = self.client.get(reverse('drfdocs'))
20+
21+
# print()
22+
# print()
23+
# print(response)
24+
# print(response["context"])
25+
# print(response.context)
26+
# print(dir(response))
27+
# print()
28+
# print()
29+
30+
self.assertEqual(response.status_code, 200)
31+
self.assertEqual(response.context["endpoints"], [])
32+
# self.assertContains(response, "No polls are available.")
33+
# self.assertQuerysetEqual(response.context['latest_question_list'], [])

tests/urls.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.conf.urls import include, url
2+
from django.contrib import admin
3+
4+
urlpatterns = [
5+
url(r'^admin/', include(admin.site.urls)),
6+
url(r'^docs/', include('rest_framework_docs.urls')),
7+
8+
# API
9+
# url(r'^accounts/', view=include('project.accounts.urls', namespace='accounts')),
10+
# url(r'^organisations/', view=include('project.organisations.urls', namespace='organisations')),
11+
]

tests/views.py

Whitespace-only changes.

0 commit comments

Comments
 (0)