Added unit tests around BaseDownloadView. Introduced setup_view() test utility.

This commit is contained in:
Benoît Bryon 2013-11-05 07:29:58 +01:00
parent def3e97a39
commit 0371f84f26
2 changed files with 31 additions and 0 deletions

View file

@ -1,2 +1,18 @@
# -*- coding: utf-8 -*-
"""Unit tests."""
def setup_view(view, request, *args, **kwargs):
"""Mimic as_view() returned callable, but returns view instance.
``args`` and ``kwargs`` are the same you would pass to
:func:`~django.core.urlresolvers.reverse`.
This is an early implementation of
https://code.djangoproject.com/ticket/20456
"""
view.request = request
view.args = args
view.kwargs = kwargs
return view

View file

@ -162,3 +162,18 @@ class DownloadMixinTestCase(unittest.TestCase):
mixin.get_file.assert_called_once_with()
self.assertEqual(mixin.was_modified_since.call_count, 0)
mixin.download_response.assert_called_once_with()
class BaseDownloadViewTestCase(unittest.TestCase):
"Tests around :class:`django_downloadviews.views.base.BaseDownloadView`."
def test_get(self):
"""BaseDownloadView.get() calls render_to_response()."""
request = django.test.RequestFactory().get('/dummy-url')
args = ['dummy-arg']
kwargs = {'dummy': 'kwarg'}
view = setup_view(base.BaseDownloadView(), request, *args, **kwargs)
view.render_to_response = mock.Mock(
return_value=mock.sentinel.response)
response = view.get(request, *args, **kwargs)
self.assertIs(response, mock.sentinel.response)
view.render_to_response.assert_called_once_with()