summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2013-03-14 20:28:24 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-03-14 20:30:23 +0100
commit3f2befc93163e0666dcc4f745288b98306de4b8e (patch)
treeecca16348da0fab7c87bba937090aef498c9ff2f /tests
parent2f121dfe635b3f497fe1fe03bc8eb97cdf5083b3 (diff)
Deprecated django.views.defaults.shortcut.
Diffstat (limited to 'tests')
-rw-r--r--tests/contenttypes_tests/__init__.py0
-rw-r--r--tests/contenttypes_tests/fixtures/testdata.json47
-rw-r--r--tests/contenttypes_tests/models.py24
-rw-r--r--tests/contenttypes_tests/tests.py47
-rw-r--r--tests/contenttypes_tests/urls.py7
-rw-r--r--tests/view_tests/tests/defaults.py37
-rw-r--r--tests/view_tests/urls.py1
7 files changed, 125 insertions, 38 deletions
diff --git a/tests/contenttypes_tests/__init__.py b/tests/contenttypes_tests/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/contenttypes_tests/__init__.py
diff --git a/tests/contenttypes_tests/fixtures/testdata.json b/tests/contenttypes_tests/fixtures/testdata.json
new file mode 100644
index 0000000000..52510bfe90
--- /dev/null
+++ b/tests/contenttypes_tests/fixtures/testdata.json
@@ -0,0 +1,47 @@
+[
+ {
+ "pk": 1,
+ "model": "contenttypes_tests.author",
+ "fields": {
+ "name": "Boris"
+ }
+ },
+ {
+ "pk": 1,
+ "model": "contenttypes_tests.article",
+ "fields": {
+ "author": 1,
+ "title": "Old Article",
+ "slug": "old_article",
+ "date_created": "2001-01-01 21:22:23"
+ }
+ },
+ {
+ "pk": 2,
+ "model": "contenttypes_tests.article",
+ "fields": {
+ "author": 1,
+ "title": "Current Article",
+ "slug": "current_article",
+ "date_created": "2007-09-17 21:22:23"
+ }
+ },
+ {
+ "pk": 3,
+ "model": "contenttypes_tests.article",
+ "fields": {
+ "author": 1,
+ "title": "Future Article",
+ "slug": "future_article",
+ "date_created": "3000-01-01 21:22:23"
+ }
+ },
+ {
+ "pk": 1,
+ "model": "sites.site",
+ "fields": {
+ "domain": "testserver",
+ "name": "testserver"
+ }
+ }
+]
diff --git a/tests/contenttypes_tests/models.py b/tests/contenttypes_tests/models.py
new file mode 100644
index 0000000000..3c6685687a
--- /dev/null
+++ b/tests/contenttypes_tests/models.py
@@ -0,0 +1,24 @@
+from __future__ import absolute_import, unicode_literals
+
+from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+
+@python_2_unicode_compatible
+class Author(models.Model):
+ name = models.CharField(max_length=100)
+
+ def __str__(self):
+ return self.name
+
+ def get_absolute_url(self):
+ return '/views/authors/%s/' % self.id
+
+@python_2_unicode_compatible
+class Article(models.Model):
+ title = models.CharField(max_length=100)
+ slug = models.SlugField()
+ author = models.ForeignKey(Author)
+ date_created = models.DateTimeField()
+
+ def __str__(self):
+ return self.title
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py
new file mode 100644
index 0000000000..b39e118ec6
--- /dev/null
+++ b/tests/contenttypes_tests/tests.py
@@ -0,0 +1,47 @@
+from __future__ import absolute_import, unicode_literals
+
+from django.contrib.contenttypes.models import ContentType
+from django.test import TestCase
+
+from .models import Author, Article
+
+class ContentTypesViewsTests(TestCase):
+ fixtures = ['testdata.json']
+ urls = 'contenttypes_tests.urls'
+
+ def test_shortcut_with_absolute_url(self):
+ "Can view a shortcut for an Author object that has a get_absolute_url method"
+ for obj in Author.objects.all():
+ short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, obj.pk)
+ response = self.client.get(short_url)
+ self.assertRedirects(response, 'http://testserver%s' % obj.get_absolute_url(),
+ status_code=302, target_status_code=404)
+
+ def test_shortcut_no_absolute_url(self):
+ "Shortcuts for an object that has no get_absolute_url method raises 404"
+ for obj in Article.objects.all():
+ short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Article).id, obj.pk)
+ response = self.client.get(short_url)
+ self.assertEqual(response.status_code, 404)
+
+ def test_wrong_type_pk(self):
+ short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, 'nobody/expects')
+ response = self.client.get(short_url)
+ self.assertEqual(response.status_code, 404)
+
+ def test_shortcut_bad_pk(self):
+ short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, '42424242')
+ response = self.client.get(short_url)
+ self.assertEqual(response.status_code, 404)
+
+ def test_nonint_content_type(self):
+ an_author = Author.objects.all()[0]
+ short_url = '/shortcut/%s/%s/' % ('spam', an_author.pk)
+ response = self.client.get(short_url)
+ self.assertEqual(response.status_code, 404)
+
+ def test_bad_content_type(self):
+ an_author = Author.objects.all()[0]
+ short_url = '/shortcut/%s/%s/' % (42424242, an_author.pk)
+ response = self.client.get(short_url)
+ self.assertEqual(response.status_code, 404)
diff --git a/tests/contenttypes_tests/urls.py b/tests/contenttypes_tests/urls.py
new file mode 100644
index 0000000000..2cfc90b024
--- /dev/null
+++ b/tests/contenttypes_tests/urls.py
@@ -0,0 +1,7 @@
+from __future__ import absolute_import, unicode_literals
+
+from django.conf.urls import patterns
+
+urlpatterns = patterns('',
+ (r'^shortcut/(\d+)/(.*)/$', 'django.contrib.contenttypes.views.shortcut'),
+)
diff --git a/tests/view_tests/tests/defaults.py b/tests/view_tests/tests/defaults.py
index 3ca7f79136..5efd338d34 100644
--- a/tests/view_tests/tests/defaults.py
+++ b/tests/view_tests/tests/defaults.py
@@ -13,43 +13,6 @@ class DefaultsTests(TestCase):
non_existing_urls = ['/views/non_existing_url/', # this is in urls.py
'/views/other_non_existing_url/'] # this NOT in urls.py
- def test_shortcut_with_absolute_url(self):
- "Can view a shortcut for an Author object that has a get_absolute_url method"
- for obj in Author.objects.all():
- short_url = '/views/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, obj.pk)
- response = self.client.get(short_url)
- self.assertRedirects(response, 'http://testserver%s' % obj.get_absolute_url(),
- status_code=302, target_status_code=404)
-
- def test_shortcut_no_absolute_url(self):
- "Shortcuts for an object that has no get_absolute_url method raises 404"
- for obj in Article.objects.all():
- short_url = '/views/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Article).id, obj.pk)
- response = self.client.get(short_url)
- self.assertEqual(response.status_code, 404)
-
- def test_wrong_type_pk(self):
- short_url = '/views/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, 'nobody/expects')
- response = self.client.get(short_url)
- self.assertEqual(response.status_code, 404)
-
- def test_shortcut_bad_pk(self):
- short_url = '/views/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, '42424242')
- response = self.client.get(short_url)
- self.assertEqual(response.status_code, 404)
-
- def test_nonint_content_type(self):
- an_author = Author.objects.all()[0]
- short_url = '/views/shortcut/%s/%s/' % ('spam', an_author.pk)
- response = self.client.get(short_url)
- self.assertEqual(response.status_code, 404)
-
- def test_bad_content_type(self):
- an_author = Author.objects.all()[0]
- short_url = '/views/shortcut/%s/%s/' % (42424242, an_author.pk)
- response = self.client.get(short_url)
- self.assertEqual(response.status_code, 404)
-
def test_page_not_found(self):
"A 404 status is returned by the page_not_found view"
for url in self.non_existing_urls:
diff --git a/tests/view_tests/urls.py b/tests/view_tests/urls.py
index 8a3b492cec..52e2eb474e 100644
--- a/tests/view_tests/urls.py
+++ b/tests/view_tests/urls.py
@@ -42,7 +42,6 @@ urlpatterns = patterns('',
(r'^$', views.index_page),
# Default views
- (r'^shortcut/(\d+)/(.*)/$', 'django.views.defaults.shortcut'),
(r'^non_existing_url/', 'django.views.defaults.page_not_found'),
(r'^server_error/', 'django.views.defaults.server_error'),