Ticket #7835: 7835.test_extra_apps.2.diff

File 7835.test_extra_apps.2.diff, 13.0 KB (added by Julien Phalip, 16 years ago)

patch+test+doc

  • django/django/contrib/comments/tests/__init__.py

     
    44from django.contrib.contenttypes.models import ContentType
    55from django.contrib.sites.models import Site
    66from django.test import TestCase
    7 from regressiontests.comment_tests.models import Article, Author
     7from django.contrib.comments.tests.test_comments.models import Article, Author
    88
    99# Shortcut
    1010CT = ContentType.objects.get_for_model
     
    1313class CommentTestCase(TestCase):
    1414    fixtures = ["comment_tests"]
    1515    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        )
    1625
    1726    def createSomeComments(self):
    1827        # Two anonymous comments on two different objects
     
    8089        d.update(f.initial)
    8190        return d
    8291
    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 *
     92from django.contrib.comments.tests.app_api_tests import *
     93from django.contrib.comments.tests.model_tests import *
     94from django.contrib.comments.tests.comment_form_tests import *
     95from django.contrib.comments.tests.templatetag_tests import *
     96from django.contrib.comments.tests.comment_view_tests import *
     97from django.contrib.comments.tests.moderation_view_tests import *
  • django/django/contrib/comments/tests/app_api_tests.py

     
    22from django.contrib import comments
    33from django.contrib.comments.models import Comment
    44from django.contrib.comments.forms import CommentForm
    5 from regressiontests.comment_tests.tests import CommentTestCase
     5from django.contrib.comments.tests import CommentTestCase
    66
    77class CommentAppAPITests(CommentTestCase):
    88    """Tests for the "comment app" API"""
  • django/django/contrib/comments/tests/comment_form_tests.py

     
    22from django.conf import settings
    33from django.contrib.comments.models import Comment
    44from django.contrib.comments.forms import CommentForm
    5 from regressiontests.comment_tests.models import Article
    6 from regressiontests.comment_tests.tests import CommentTestCase
     5from django.contrib.comments.tests.test_comments.models import Article
     6from django.contrib.comments.tests import CommentTestCase
    77
    88class CommentFormTests(CommentTestCase):
    99
  • django/django/contrib/comments/tests/comment_view_tests.py

     
    22from django.contrib.auth.models import User
    33from django.contrib.comments import signals
    44from django.contrib.comments.models import Comment
    5 from regressiontests.comment_tests.models import Article
    6 from regressiontests.comment_tests.tests import CommentTestCase
     5from django.contrib.comments.tests.test_comments.models import Article
     6from django.contrib.comments.tests import CommentTestCase
    77
    88class CommentViewTests(CommentTestCase):
    99
  • django/django/contrib/comments/tests/model_tests.py

     
    11from django.contrib.comments.models import Comment
    2 from regressiontests.comment_tests.models import Author, Article
    3 from regressiontests.comment_tests.tests import CommentTestCase
     2from django.contrib.comments.tests.test_comments.models import Author, Article
     3from django.contrib.comments.tests import CommentTestCase
    44
    55class CommentModelTests(CommentTestCase):
    66
  • django/django/contrib/comments/tests/moderation_view_tests.py

     
    11from django.contrib.comments.models import Comment, CommentFlag
    22from django.contrib.auth.models import User, Permission
    33from django.contrib.contenttypes.models import ContentType
    4 from regressiontests.comment_tests.tests import CommentTestCase
     4from django.contrib.comments.tests import CommentTestCase
    55from django.contrib.comments import signals
    66
    77class FlagViewTests(CommentTestCase):
  • django/django/contrib/comments/tests/templatetag_tests.py

     
    11from django.contrib.comments.forms import CommentForm
    22from django.contrib.comments.models import Comment
    33from django.template import Template, Context
    4 from regressiontests.comment_tests.models import Article, Author
    5 from regressiontests.comment_tests.tests import CommentTestCase
     4from django.contrib.comments.tests.test_comments.models import Article, Author
     5from django.contrib.comments.tests import CommentTestCase
    66
    77class CommentTemplateTagTests(CommentTestCase):
    88
     
    1616        self.assertEqual(out, "/post/")
    1717
    1818    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 %}")
    2020        ctx, out = self.render(t, a=Article.objects.get(pk=1))
    2121        self.assertEqual(out, "")
    2222        self.assert_(isinstance(ctx["form"], CommentForm))
     
    2222        self.assert_(isinstance(ctx["form"], CommentForm))
    2323
    2424    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 %}")
    2626
    2727    def testGetCommentFormFromObject(self):
    2828        self.testGetCommentForm("{% get_comment_form for a as form %}")
     
    2828        self.testGetCommentForm("{% get_comment_form for a as form %}")
    2929
    3030    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 %}")
    3232        ctx, out = self.render(t, a=Article.objects.get(pk=1))
    3333        self.assert_(out.strip().startswith("<form action="))
    3434        self.assert_(out.strip().endswith("</form>"))
     
    3434        self.assert_(out.strip().endswith("</form>"))
    3535
    3636    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 %}")
    3838
    3939    def testRenderCommentFormFromObject(self):
    4040        self.testRenderCommentForm("{% render_comment_form for a %}")
     
    4141
    4242    def testGetCommentCount(self, tag=None):
    4343        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 }}"
    4545        ctx, out = self.render(t, a=Article.objects.get(pk=1))
    4646        self.assertEqual(out, "2")
    4747
     
    4646        self.assertEqual(out, "2")
    4747
    4848    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 %}")
    5050
    5151    def testGetCommentCountFromObject(self):
    5252        self.testGetCommentCount("{% get_comment_count for a as cc %}")
     
    5353
    5454    def testGetCommentList(self, tag=None):
    5555        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 %}")
    5757        ctx, out = self.render(t, a=Author.objects.get(pk=1))
    5858        self.assertEqual(out, "")
    5959        self.assertEqual(list(ctx["cl"]), [c2])
     
    5959        self.assertEqual(list(ctx["cl"]), [c2])
    6060
    6161    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 %}")
    6363
    6464    def testGetCommentListFromObject(self):
    6565        self.testGetCommentList("{% get_comment_list for a as cl %}")
  • django/django/test/testcases.py

     
    88from django.core.management import call_command
    99from django.core.urlresolvers import clear_url_caches
    1010from django.db import transaction
     11from django.db.models.loading import load_app
    1112from django.http import QueryDict
    1213from django.test import _doctest as doctest
    1314from django.test.client import Client
     
    173174    def _pre_setup(self):
    174175        """Performs any pre-test setup. This includes:
    175176
     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.
    176182            * Flushing the database.
    177183            * If the Test Case class has a 'fixtures' member, installing the
    178184              named fixtures.
     
    180186              ROOT_URLCONF with it.
    181187            * Clearing the mail test outbox.
    182188        """
     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)
    183204        call_command('flush', verbosity=0, interactive=False)
    184205        if hasattr(self, 'fixtures'):
    185206            # We have to use this slightly awkward syntax due to the fact
     
    220241        """ Performs any post-test things. This includes:
    221242
    222243            * 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.
    223246        """
    224247        if hasattr(self, '_old_root_urlconf'):
    225248            settings.ROOT_URLCONF = self._old_root_urlconf
     
    224247        if hasattr(self, '_old_root_urlconf'):
    225248            settings.ROOT_URLCONF = self._old_root_urlconf
    226249            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.
    227253
    228254    def assertRedirects(self, response, expected_url, status_code=302,
    229255                        target_status_code=200, host=None):
Back to Top