Skip to content

Commit

Permalink
Add tests for assertResponseContains & assertResponseNotContains
Browse files Browse the repository at this point in the history
  • Loading branch information
goodtune committed Aug 18, 2016
1 parent d9a1ad3 commit 1b90469
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions test_project/test_app/tests.py
Expand Up @@ -266,6 +266,11 @@ def test_post_is_ajax(self):
extra={'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})
self.response_200(response)

def test_assertresponsecontains(self):
self.get('view-contains')
self.assertResponseContains('<p>Hello world</p>')
self.assertResponseNotContains('<p>Hello Frank</p>')


class TestPlusCBViewTests(CBVTestCase):

Expand Down
4 changes: 3 additions & 1 deletion test_project/test_app/urls.py
Expand Up @@ -6,7 +6,8 @@
from .views import (
data_1, data_5, needs_login, view_200, view_201, view_302,
view_400, view_401, view_403, view_404, view_405, view_410,
view_context_with, view_context_without, view_is_ajax, view_redirect,
view_contains, view_context_with, view_context_without,
view_is_ajax, view_redirect,
)

urlpatterns = patterns(
Expand All @@ -28,4 +29,5 @@
url(r'^view/context/with/$', view_context_with, name='view-context-with'),
url(r'^view/context/without/$', view_context_without, name='view-context-without'),
url(r'^view/isajax/$', view_is_ajax, name='view-is-ajax'),
url(r'^view/contains/$', view_contains, name='view-contains'),
)
4 changes: 4 additions & 0 deletions test_project/test_app/views.py
Expand Up @@ -79,6 +79,10 @@ def view_is_ajax(request):
return HttpResponse('', status=200 if request.is_ajax() else 404)


def view_contains(request):
return render(request, 'test.html', {})


# Class-based test views

class CBView(generic.View):
Expand Down

0 comments on commit 1b90469

Please sign in to comment.