Ticket #7835: 7835.test_extra_apps.2.diff
File 7835.test_extra_apps.2.diff, 13.0 KB (added by , 16 years ago) |
---|
-
django/django/contrib/comments/tests/__init__.py
4 4 from django.contrib.contenttypes.models import ContentType 5 5 from django.contrib.sites.models import Site 6 6 from django.test import TestCase 7 from regressiontests.comment_tests.models import Article, Author7 from django.contrib.comments.tests.test_comments.models import Article, Author 8 8 9 9 # Shortcut 10 10 CT = ContentType.objects.get_for_model … … 13 13 class CommentTestCase(TestCase): 14 14 fixtures = ["comment_tests"] 15 15 urls = 'django.contrib.comments.urls' 16 installed_apps = ( 17 'django.contrib.sessions', 18 'django.contrib.sites', 19 'django.contrib.admin', 20 'django.contrib.auth', 21 'django.contrib.comments', 22 'django.contrib.contenttypes', 23 'django.contrib.comments.tests.test_comments' 24 ) 16 25 17 26 def createSomeComments(self): 18 27 # Two anonymous comments on two different objects … … 80 89 d.update(f.initial) 81 90 return d 82 91 83 from regressiontests.comment_tests.tests.app_api_tests import *84 from regressiontests.comment_tests.tests.model_tests import *85 from regressiontests.comment_tests.tests.comment_form_tests import *86 from regressiontests.comment_tests.tests.templatetag_tests import *87 from regressiontests.comment_tests.tests.comment_view_tests import *88 from regressiontests.comment_tests.tests.moderation_view_tests import *92 from django.contrib.comments.tests.app_api_tests import * 93 from django.contrib.comments.tests.model_tests import * 94 from django.contrib.comments.tests.comment_form_tests import * 95 from django.contrib.comments.tests.templatetag_tests import * 96 from django.contrib.comments.tests.comment_view_tests import * 97 from django.contrib.comments.tests.moderation_view_tests import * -
django/django/contrib/comments/tests/app_api_tests.py
2 2 from django.contrib import comments 3 3 from django.contrib.comments.models import Comment 4 4 from django.contrib.comments.forms import CommentForm 5 from regressiontests.comment_tests.tests import CommentTestCase5 from django.contrib.comments.tests import CommentTestCase 6 6 7 7 class CommentAppAPITests(CommentTestCase): 8 8 """Tests for the "comment app" API""" -
django/django/contrib/comments/tests/comment_form_tests.py
2 2 from django.conf import settings 3 3 from django.contrib.comments.models import Comment 4 4 from django.contrib.comments.forms import CommentForm 5 from regressiontests.comment_tests.models import Article6 from regressiontests.comment_tests.tests import CommentTestCase5 from django.contrib.comments.tests.test_comments.models import Article 6 from django.contrib.comments.tests import CommentTestCase 7 7 8 8 class CommentFormTests(CommentTestCase): 9 9 -
django/django/contrib/comments/tests/comment_view_tests.py
2 2 from django.contrib.auth.models import User 3 3 from django.contrib.comments import signals 4 4 from django.contrib.comments.models import Comment 5 from regressiontests.comment_tests.models import Article6 from regressiontests.comment_tests.tests import CommentTestCase5 from django.contrib.comments.tests.test_comments.models import Article 6 from django.contrib.comments.tests import CommentTestCase 7 7 8 8 class CommentViewTests(CommentTestCase): 9 9 -
django/django/contrib/comments/tests/model_tests.py
1 1 from django.contrib.comments.models import Comment 2 from regressiontests.comment_tests.models import Author, Article3 from regressiontests.comment_tests.tests import CommentTestCase2 from django.contrib.comments.tests.test_comments.models import Author, Article 3 from django.contrib.comments.tests import CommentTestCase 4 4 5 5 class CommentModelTests(CommentTestCase): 6 6 -
django/django/contrib/comments/tests/moderation_view_tests.py
1 1 from django.contrib.comments.models import Comment, CommentFlag 2 2 from django.contrib.auth.models import User, Permission 3 3 from django.contrib.contenttypes.models import ContentType 4 from regressiontests.comment_tests.tests import CommentTestCase4 from django.contrib.comments.tests import CommentTestCase 5 5 from django.contrib.comments import signals 6 6 7 7 class FlagViewTests(CommentTestCase): -
django/django/contrib/comments/tests/templatetag_tests.py
1 1 from django.contrib.comments.forms import CommentForm 2 2 from django.contrib.comments.models import Comment 3 3 from django.template import Template, Context 4 from regressiontests.comment_tests.models import Article, Author5 from regressiontests.comment_tests.tests import CommentTestCase4 from django.contrib.comments.tests.test_comments.models import Article, Author 5 from django.contrib.comments.tests import CommentTestCase 6 6 7 7 class CommentTemplateTagTests(CommentTestCase): 8 8 … … 16 16 self.assertEqual(out, "/post/") 17 17 18 18 def testGetCommentForm(self, tag=None): 19 t = "{% load comments %}" + (tag or "{% get_comment_form for comment_tests.article a.id as form %}")19 t = "{% load comments %}" + (tag or "{% get_comment_form for test_comments.article a.id as form %}") 20 20 ctx, out = self.render(t, a=Article.objects.get(pk=1)) 21 21 self.assertEqual(out, "") 22 22 self.assert_(isinstance(ctx["form"], CommentForm)) … … 22 22 self.assert_(isinstance(ctx["form"], CommentForm)) 23 23 24 24 def testGetCommentFormFromLiteral(self): 25 self.testGetCommentForm("{% get_comment_form for comment_tests.article 1 as form %}")25 self.testGetCommentForm("{% get_comment_form for test_comments.article 1 as form %}") 26 26 27 27 def testGetCommentFormFromObject(self): 28 28 self.testGetCommentForm("{% get_comment_form for a as form %}") … … 28 28 self.testGetCommentForm("{% get_comment_form for a as form %}") 29 29 30 30 def testRenderCommentForm(self, tag=None): 31 t = "{% load comments %}" + (tag or "{% render_comment_form for comment_tests.article a.id %}")31 t = "{% load comments %}" + (tag or "{% render_comment_form for test_comments.article a.id %}") 32 32 ctx, out = self.render(t, a=Article.objects.get(pk=1)) 33 33 self.assert_(out.strip().startswith("<form action=")) 34 34 self.assert_(out.strip().endswith("</form>")) … … 34 34 self.assert_(out.strip().endswith("</form>")) 35 35 36 36 def testRenderCommentFormFromLiteral(self): 37 self.testRenderCommentForm("{% render_comment_form for comment_tests.article 1 %}")37 self.testRenderCommentForm("{% render_comment_form for test_comments.article 1 %}") 38 38 39 39 def testRenderCommentFormFromObject(self): 40 40 self.testRenderCommentForm("{% render_comment_form for a %}") … … 41 41 42 42 def testGetCommentCount(self, tag=None): 43 43 self.createSomeComments() 44 t = "{% load comments %}" + (tag or "{% get_comment_count for comment_tests.article a.id as cc %}") + "{{ cc }}"44 t = "{% load comments %}" + (tag or "{% get_comment_count for test_comments.article a.id as cc %}") + "{{ cc }}" 45 45 ctx, out = self.render(t, a=Article.objects.get(pk=1)) 46 46 self.assertEqual(out, "2") 47 47 … … 46 46 self.assertEqual(out, "2") 47 47 48 48 def testGetCommentCountFromLiteral(self): 49 self.testGetCommentCount("{% get_comment_count for comment_tests.article 1 as cc %}")49 self.testGetCommentCount("{% get_comment_count for test_comments.article 1 as cc %}") 50 50 51 51 def testGetCommentCountFromObject(self): 52 52 self.testGetCommentCount("{% get_comment_count for a as cc %}") … … 53 53 54 54 def testGetCommentList(self, tag=None): 55 55 c1, c2, c3, c4 = self.createSomeComments() 56 t = "{% load comments %}" + (tag or "{% get_comment_list for comment_tests.author a.id as cl %}")56 t = "{% load comments %}" + (tag or "{% get_comment_list for test_comments.author a.id as cl %}") 57 57 ctx, out = self.render(t, a=Author.objects.get(pk=1)) 58 58 self.assertEqual(out, "") 59 59 self.assertEqual(list(ctx["cl"]), [c2]) … … 59 59 self.assertEqual(list(ctx["cl"]), [c2]) 60 60 61 61 def testGetCommentListFromLiteral(self): 62 self.testGetCommentList("{% get_comment_list for comment_tests.author 1 as cl %}")62 self.testGetCommentList("{% get_comment_list for test_comments.author 1 as cl %}") 63 63 64 64 def testGetCommentListFromObject(self): 65 65 self.testGetCommentList("{% get_comment_list for a as cl %}") -
django/django/test/testcases.py
8 8 from django.core.management import call_command 9 9 from django.core.urlresolvers import clear_url_caches 10 10 from django.db import transaction 11 from django.db.models.loading import load_app 11 12 from django.http import QueryDict 12 13 from django.test import _doctest as doctest 13 14 from django.test.client import Client … … 173 174 def _pre_setup(self): 174 175 """Performs any pre-test setup. This includes: 175 176 177 * If the Test Case class has a 'installed_apps' member, replace the 178 INSTALLED_APPS with it. 179 * If the Test Case class has a 'extra_apps' member, append it to 180 INSTALLED_APPS. 181 * Create tables and load models for test apps. 176 182 * Flushing the database. 177 183 * If the Test Case class has a 'fixtures' member, installing the 178 184 named fixtures. … … 180 186 ROOT_URLCONF with it. 181 187 * Clearing the mail test outbox. 182 188 """ 189 if hasattr(self, 'installed_apps'): 190 self._old_installed_apps = settings.INSTALLED_APPS 191 settings.INSTALLED_APPS = list(self.installed_apps) 192 if hasattr(self, 'extra_apps'): 193 if hasattr(self, '_old_installed_apps'): 194 # extra_apps and installed_apps can coexist 195 settings.INSTALLED_APPS += list(self.extra_apps) 196 else: 197 self._old_installed_apps = settings.INSTALLED_APPS 198 settings.INSTALLED_APPS += list(self.extra_apps) 199 if hasattr(self, '_old_installed_apps'): 200 for app_label in settings.INSTALLED_APPS: 201 load_app(app_label) 202 # Create the new tables in db 203 call_command('syncdb', verbosity=0, interactive=False) 183 204 call_command('flush', verbosity=0, interactive=False) 184 205 if hasattr(self, 'fixtures'): 185 206 # We have to use this slightly awkward syntax due to the fact … … 220 241 """ Performs any post-test things. This includes: 221 242 222 243 * Putting back the original ROOT_URLCONF if it was changed. 244 * Putting back the original INSTALLED_APPS if it was changed. 245 * Unload models and destroy tables for test apps. 223 246 """ 224 247 if hasattr(self, '_old_root_urlconf'): 225 248 settings.ROOT_URLCONF = self._old_root_urlconf … … 224 247 if hasattr(self, '_old_root_urlconf'): 225 248 settings.ROOT_URLCONF = self._old_root_urlconf 226 249 clear_url_caches() 250 if hasattr(self, '_old_installed_apps'): 251 settings.INSTALLED_APPS = self._old_installed_apps 252 #TODO: test apps should be unloaded from the app cache, and the extra tables destroyed. 227 253 228 254 def assertRedirects(self, response, expected_url, status_code=302, 229 255 target_status_code=200, host=None):