summaryrefslogtreecommitdiff
path: root/tests/contenttypes_tests
diff options
context:
space:
mode:
authorJosh Smeaton <josh.smeaton@gmail.com>2015-02-23 11:53:57 +1100
committerJosh Smeaton <josh.smeaton@gmail.com>2015-03-05 10:10:32 +1100
commit39a7eed1bbf12020a077e4bec3d82e08f171a021 (patch)
tree225be14a94d57517d9de646569498eb45d0a4352 /tests/contenttypes_tests
parentd6969abf239d52f6dfed7384c6ceb7df7e618342 (diff)
Converted test fixtures to setUpTestData methods
Diffstat (limited to 'tests/contenttypes_tests')
-rw-r--r--tests/contenttypes_tests/fixtures/testdata.json68
-rw-r--r--tests/contenttypes_tests/tests.py30
2 files changed, 27 insertions, 71 deletions
diff --git a/tests/contenttypes_tests/fixtures/testdata.json b/tests/contenttypes_tests/fixtures/testdata.json
deleted file mode 100644
index 114b1e262f..0000000000
--- a/tests/contenttypes_tests/fixtures/testdata.json
+++ /dev/null
@@ -1,68 +0,0 @@
-[
- {
- "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": "contenttypes_tests.schemeincludedurl",
- "fields": {
- "url": "http://test_scheme_included_http/"
- }
- },
- {
- "pk": 2,
- "model": "contenttypes_tests.schemeincludedurl",
- "fields": {
- "url": "https://test_scheme_included_https/"
- }
- },
- {
- "pk": 3,
- "model": "contenttypes_tests.schemeincludedurl",
- "fields": {
- "url": "//test_default_scheme_kept/"
- }
- },
- {
- "pk": 1,
- "model": "sites.site",
- "fields": {
- "domain": "testserver",
- "name": "testserver"
- }
- }
-]
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py
index a791f8df3c..3ae4774033 100644
--- a/tests/contenttypes_tests/tests.py
+++ b/tests/contenttypes_tests/tests.py
@@ -1,12 +1,15 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+import datetime
+
from django.apps.registry import Apps, apps
from django.contrib.contenttypes import management
from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
from django.contrib.contenttypes.models import ContentType
+from django.contrib.sites.models import Site
from django.core import checks
from django.db import connections, models
from django.test import TestCase, override_settings
@@ -18,7 +21,29 @@ from .models import Article, Author, SchemeIncludedURL
@override_settings(ROOT_URLCONF='contenttypes_tests.urls')
class ContentTypesViewsTests(TestCase):
- fixtures = ['testdata.json']
+
+ @classmethod
+ def setUpTestData(cls):
+ # don't use the manager because we want to ensure the site exists
+ # with pk=1, regardless of whether or not it already exists.
+ cls.site1 = Site(pk=1, domain='testserver', name='testserver')
+ cls.site1.save()
+ cls.author1 = Author.objects.create(name='Boris')
+ cls.article1 = Article.objects.create(
+ title='Old Article', slug='old_article', author=cls.author1,
+ date_created=datetime.datetime(2001, 1, 1, 21, 22, 23)
+ )
+ cls.article2 = Article.objects.create(
+ title='Current Article', slug='current_article', author=cls.author1,
+ date_created=datetime.datetime(2007, 9, 17, 21, 22, 23)
+ )
+ cls.article3 = Article.objects.create(
+ title='Future Article', slug='future_article', author=cls.author1,
+ date_created=datetime.datetime(3000, 1, 1, 21, 22, 23)
+ )
+ cls.scheme1 = SchemeIncludedURL.objects.create(url='http://test_scheme_included_http/')
+ cls.scheme2 = SchemeIncludedURL.objects.create(url='https://test_scheme_included_https/')
+ cls.scheme3 = SchemeIncludedURL.objects.create(url='//test_default_scheme_kept/')
def test_shortcut_with_absolute_url(self):
"Can view a shortcut for an Author object that has a get_absolute_url method"
@@ -31,8 +56,7 @@ class ContentTypesViewsTests(TestCase):
def test_shortcut_with_absolute_url_including_scheme(self):
"""
Can view a shortcut when object's get_absolute_url returns a full URL
- the tested URLs are in fixtures/testdata.json :
- "http://...", "https://..." and "//..."
+ the tested URLs are: "http://...", "https://..." and "//..."
"""
for obj in SchemeIncludedURL.objects.all():
short_url = '/shortcut/%s/%s/' % (ContentType.objects.get_for_model(SchemeIncludedURL).id, obj.pk)