~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/generic_views/test_base.py

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2014-09-17 14:15:11 UTC
  • mfrom: (1.3.17) (6.2.18 experimental)
  • Revision ID: package-import@ubuntu.com-20140917141511-icneokthe9ww5sk4
Tags: 1.7-2
* Release to unstable.
* Add a migrate-south sample script to help users apply their South
  migrations. Thanks to Brian May.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from __future__ import absolute_import
 
1
from __future__ import unicode_literals
2
2
 
3
3
import time
 
4
import unittest
4
5
 
5
6
from django.core.exceptions import ImproperlyConfigured
6
7
from django.http import HttpResponse
7
8
from django.test import TestCase, RequestFactory
8
 
from django.utils import unittest
9
9
from django.views.generic import View, TemplateView, RedirectView
10
10
 
11
11
from . import views
12
12
 
 
13
 
13
14
class SimpleView(View):
14
15
    """
15
16
    A simple view with a docstring.
76
77
        Test that a view can't be accidentally instantiated before deployment
77
78
        """
78
79
        try:
79
 
            view = SimpleView(key='value').as_view()
 
80
            SimpleView(key='value').as_view()
80
81
            self.fail('Should not be able to instantiate a view')
81
82
        except AttributeError:
82
83
            pass
86
87
        Test that a view can't be accidentally instantiated before deployment
87
88
        """
88
89
        try:
89
 
            view = SimpleView.as_view('value')
 
90
            SimpleView.as_view('value')
90
91
            self.fail('Should not be able to use non-keyword arguments instantiating a view')
91
92
        except TypeError:
92
93
            pass
227
228
            self.assertNotIn(attribute, dir(bare_view))
228
229
            self.assertIn(attribute, dir(view))
229
230
 
 
231
    def test_direct_instantiation(self):
 
232
        """
 
233
        It should be possible to use the view by directly instantiating it
 
234
        without going through .as_view() (#21564).
 
235
        """
 
236
        view = PostOnlyView()
 
237
        response = view.dispatch(self.rf.head('/'))
 
238
        self.assertEqual(response.status_code, 405)
 
239
 
230
240
 
231
241
class TemplateViewTest(TestCase):
232
242
    urls = 'generic_views.urls'
420
430
        response = RedirectView.as_view(url='/bar/')(self.rf.request(PATH_INFO='/foo/'))
421
431
        self.assertEqual(response.status_code, 301)
422
432
 
 
433
    def test_direct_instantiation(self):
 
434
        """
 
435
        It should be possible to use the view without going through .as_view()
 
436
        (#21564).
 
437
        """
 
438
        view = RedirectView()
 
439
        response = view.dispatch(self.rf.head('/foo/'))
 
440
        self.assertEqual(response.status_code, 410)
 
441
 
423
442
 
424
443
class GetContextDataTest(unittest.TestCase):
425
444