Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
frankwiles committed Jun 1, 2018
1 parent 56af6e3 commit 06e26ab
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
@@ -0,0 +1,5 @@
[run]
omit =
test_project/*
*/.virtualenvs/*
test_plus/compat.py
2 changes: 1 addition & 1 deletion pytest.ini
Expand Up @@ -2,4 +2,4 @@
DJANGO_SETTINGS_MODULE=test_project.settings
addopts = --reuse-db --cov
python_files = test*.py
norecursedirs = build dist docs *.egg-info
norecursedirs = build dist docs *.egg-info htmlcov test_plus
28 changes: 28 additions & 0 deletions test_project/test_app/tests.py
Expand Up @@ -5,6 +5,7 @@

from contextlib import contextmanager
from django.contrib.auth import get_user_model
from django.core.exceptions import ImproperlyConfigured

try:
from StringIO import StringIO
Expand Down Expand Up @@ -55,6 +56,10 @@ def test_make_user_factory(self):
u1 = self.make_user('factory')
self.assertEqual(u1.username, 'factory')

def test_invalid_perms_for_user(self):
with self.assertRaises(ImproperlyConfigured):
self.make_user(perms=['fake'])


class TestPlusViewTests(TestCase):

Expand Down Expand Up @@ -220,6 +225,13 @@ def test_response_201(self):
# Test without response option
self.response_201()

def test_response_204(self):
res = self.get('view-204')
self.response_204(res)

# Test without response option
self.response_204()

def test_response_301(self):
res = self.get('view-301')
self.response_301(res)
Expand Down Expand Up @@ -335,6 +347,10 @@ def test_assertnumqueries_data_5(self):
with self.assertNumQueriesLessThan(6):
self.get('view-data-5')

def test_invalid_request_method(self):
with self.assertRaises(LookupError):
self.request('foobar', 'some-url')

@unittest.expectedFailure
def test_assertnumqueries_failure(self):
with self.assertNumQueriesLessThan(1):
Expand Down Expand Up @@ -367,6 +383,14 @@ def test_no_response(self):
with self.assertRaises(NoPreviousResponse):
self.assertInContext('testvalue')

def test_no_response_context(self):
with self.assertRaises(NoPreviousResponse):
self.assertContext('testvalue', False)

def test_get_context_raises(self):
with self.assertRaises(NoPreviousResponse):
self.get_context('testvalue')

def test_get_is_ajax(self):
response = self.get('view-is-ajax',
extra={'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})
Expand Down Expand Up @@ -402,6 +426,10 @@ def test_post(self):
self.post(CBView, data=data)
self.response_200()

# Test without data
self.post(CBView)
self.response_200()

def test_get_check_200(self):
self.get_check_200('cbview')

Expand Down
9 changes: 5 additions & 4 deletions test_project/test_app/urls.py
Expand Up @@ -4,17 +4,18 @@
from django.conf.urls.defaults import url, include

from .views import (
FormErrors, data_1, data_5, needs_login, view_200, view_201, view_301,
view_302, view_400, view_401, view_403, view_404, view_405, view_410,
view_contains, view_context_with, view_context_without, view_headers,
view_is_ajax, view_json, view_redirect,
FormErrors, data_1, data_5, needs_login, view_200, view_201, view_204,
view_301, view_302, view_400, view_401, view_403, view_404, view_405,
view_410, view_contains, view_context_with, view_context_without,
view_headers, view_is_ajax, view_json, view_redirect,
CBLoginRequiredView, CBView,
)

urlpatterns = [
url(r'^accounts/', include('django.contrib.auth.urls')),
url(r'^view/200/$', view_200, name='view-200'),
url(r'^view/201/$', view_201, name='view-201'),
url(r'^view/204/$', view_204, name='view-204'),
url(r'^view/301/$', view_301, name='view-301'),
url(r'^view/302/$', view_302, name='view-302'),
url(r'^view/400/$', view_400, name='view-400'),
Expand Down
4 changes: 4 additions & 0 deletions test_project/test_app/views.py
Expand Up @@ -25,6 +25,10 @@ def view_201(request):
return HttpResponse('', status=201)


def view_204(request):
return HttpResponse('', status=204)


def view_301(request):
return HttpResponse('', status=301)

Expand Down

0 comments on commit 06e26ab

Please sign in to comment.