Commit 2607fa90 authored by Marc Tamlyn's avatar Marc Tamlyn
Browse files

Fixed #21774 -- Isolate all test urls from eachother.

This (nearly) completes the work to isolate all the test modules from
each other. This is now more important as importing models from another
module will case PendingDeprecationWarnings if those modules are not in
INSTALLED_APPS. The only remaining obvious dependencies are:

- d.c.auth depends on d.c.admin (because of the is_admin flag to some
  views), but this is not so important and d.c.admin is in
  always_installed_apps
- test_client_regress depends on test_client. Eventually these should
  become a single module, as the split serves no useful purpose.
parent ac8d0a48
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ from django.utils.http import urlsafe_base64_encode
    PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
)
class AuthTemplateTests(TestCase):
    urls = 'django.contrib.auth.tests.urls'

    def test_titles(self):
        rf = RequestFactory()
+5 −1
Original line number Diff line number Diff line
from django.conf.urls import patterns, url
from django.conf.urls import patterns, url, include
from django.contrib import admin
from django.contrib.auth import context_processors
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth.urls import urlpatterns
@@ -98,4 +99,7 @@ urlpatterns = urlpatterns + patterns('',
    (r'^auth_processor_messages/$', auth_processor_messages),
    (r'^custom_request_auth_login/$', custom_request_auth_login),
    url(r'^userpage/(.+)/$', userpage, name="userpage"),

    # This line is only required to render the password reset with is_admin=True
    (r'^admin/', include(admin.site.urls)),
)
+6 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ class AdminCustomUrlsTest(TestCase):
    * The ModelAdmin for Action customizes the add_view URL, it's
      '<app name>/<model name>/!add/'
    """
    urls = 'admin_custom_urls.urls'
    fixtures = ['users.json', 'actions.json']

    def setUp(self):
@@ -28,7 +29,7 @@ class AdminCustomUrlsTest(TestCase):
        """
        Ensure GET on the add_view works.
        """
        response = self.client.get('/custom_urls/admin/admin_custom_urls/action/!add/')
        response = self.client.get('/admin/admin_custom_urls/action/!add/')
        self.assertIsInstance(response, TemplateResponse)
        self.assertEqual(response.status_code, 200)

@@ -37,7 +38,7 @@ class AdminCustomUrlsTest(TestCase):
        Ensure GET on the add_view plus specifying a field value in the query
        string works.
        """
        response = self.client.get('/custom_urls/admin/admin_custom_urls/action/!add/', {'name': 'My Action'})
        response = self.client.get('/admin/admin_custom_urls/action/!add/', {'name': 'My Action'})
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'value="My Action"')

@@ -50,7 +51,7 @@ class AdminCustomUrlsTest(TestCase):
            "name": 'Action added through a popup',
            "description": "Description of added action",
        }
        response = self.client.post('/custom_urls/admin/admin_custom_urls/action/!add/', post_data)
        response = self.client.post('/admin/admin_custom_urls/action/!add/', post_data)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'dismissAddAnotherPopup')
        self.assertContains(response, 'Action added through a popup')
@@ -61,7 +62,7 @@ class AdminCustomUrlsTest(TestCase):
        """
        # Should get the change_view for model instance with PK 'add', not show
        # the add_view
        response = self.client.get('/custom_urls/admin/admin_custom_urls/action/add/')
        response = self.client.get('/admin/admin_custom_urls/action/add/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Change action')

@@ -84,6 +85,7 @@ class AdminCustomUrlsTest(TestCase):

@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class CustomRedirects(TestCase):
    urls = 'admin_custom_urls.urls'
    fixtures = ['users.json', 'actions.json']

    def setUp(self):
+3 −2
Original line number Diff line number Diff line
@@ -1542,6 +1542,7 @@ class ArgumentOrder(AdminScriptTestCase):

class StartProject(LiveServerTestCase, AdminScriptTestCase):

    urls = 'admin_scripts.urls'
    available_apps = [
        'admin_scripts',
        'django.contrib.auth',
@@ -1649,7 +1650,7 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):

    def test_custom_project_template_from_tarball_by_url(self):
        "Make sure the startproject management command is able to use a different project template from a tarball via a url"
        template_url = '%s/admin_scripts/custom_templates/project_template.tgz' % self.live_server_url
        template_url = '%s/custom_templates/project_template.tgz' % self.live_server_url

        args = ['startproject', '--template', template_url, 'urltestproject']
        testproject_dir = os.path.join(test_dir, 'urltestproject')
@@ -1662,7 +1663,7 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):

    def test_project_template_tarball_url(self):
        "Startproject management command handles project template tar/zip balls from non-canonical urls"
        template_url = '%s/admin_scripts/custom_templates/project_template.tgz/' % self.live_server_url
        template_url = '%s/custom_templates/project_template.tgz/' % self.live_server_url

        args = ['startproject', '--template', template_url, 'urltestproject']
        testproject_dir = os.path.join(test_dir, 'urltestproject')
+17 −13
Original line number Diff line number Diff line
@@ -184,13 +184,14 @@ class AdminFormfieldForDBFieldTests(TestCase):
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminFormfieldForDBFieldWithRequestTests(DjangoTestCase):
    fixtures = ["admin-widgets-users.xml"]
    urls = 'admin_widgets.urls'

    def testFilterChoicesByRequestUser(self):
        """
        Ensure the user can only see their own cars in the foreign key dropdown.
        """
        self.client.login(username="super", password="secret")
        response = self.client.get("/widget_admin/admin_widgets/cartire/add/")
        response = self.client.get("/admin_widgets/cartire/add/")
        self.assertNotContains(response, "BMW M3")
        self.assertContains(response, "Volkswagon Passat")

@@ -198,7 +199,7 @@ class AdminFormfieldForDBFieldWithRequestTests(DjangoTestCase):
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminForeignKeyWidgetChangeList(DjangoTestCase):
    fixtures = ["admin-widgets-users.xml"]
    admin_root = '/widget_admin'
    urls = 'admin_widgets.urls'

    def setUp(self):
        self.client.login(username="super", password="secret")
@@ -207,14 +208,14 @@ class AdminForeignKeyWidgetChangeList(DjangoTestCase):
        self.client.logout()

    def test_changelist_foreignkey(self):
        response = self.client.get('%s/admin_widgets/car/' % self.admin_root)
        self.assertContains(response, '%s/auth/user/add/' % self.admin_root)
        response = self.client.get('/admin_widgets/car/')
        self.assertContains(response, '/auth/user/add/')


@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminForeignKeyRawIdWidget(DjangoTestCase):
    fixtures = ["admin-widgets-users.xml"]
    admin_root = '/widget_admin'
    urls = 'admin_widgets.urls'

    def setUp(self):
        self.client.login(username="super", password="secret")
@@ -231,8 +232,7 @@ class AdminForeignKeyRawIdWidget(DjangoTestCase):
        }
        # Try posting with a non-existent pk in a raw id field: this
        # should result in an error message, not a server exception.
        response = self.client.post('%s/admin_widgets/event/add/' % self.admin_root,
            post_data)
        response = self.client.post('/admin_widgets/event/add/', post_data)
        self.assertContains(response,
            'Select a valid choice. That choice is not one of the available choices.')

@@ -240,7 +240,7 @@ class AdminForeignKeyRawIdWidget(DjangoTestCase):

        for test_str in ('Iñtërnâtiônàlizætiøn', "1234'", -1234):
            # This should result in an error message, not a server exception.
            response = self.client.post('%s/admin_widgets/event/add/' % self.admin_root,
            response = self.client.post('/admin_widgets/event/add/',
                {"main_band": test_str})

            self.assertContains(response,
@@ -392,6 +392,8 @@ class AdminFileWidgetTest(DjangoTestCase):


class ForeignKeyRawIdWidgetTest(DjangoTestCase):
    urls = 'admin_widgets.urls'

    def test_render(self):
        band = models.Band.objects.create(name='Linkin Park')
        band.album_set.create(
@@ -402,7 +404,7 @@ class ForeignKeyRawIdWidgetTest(DjangoTestCase):
        w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site)
        self.assertHTMLEqual(
            w.render('test', band.pk, attrs={}),
            '<input type="text" name="test" value="%(bandpk)s" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/band/?_to_field=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Linkin Park</strong>' % dict(admin_static_prefix(), bandpk=band.pk)
            '<input type="text" name="test" value="%(bandpk)s" class="vForeignKeyRawIdAdminField" /><a href="/admin_widgets/band/?_to_field=id" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Linkin Park</strong>' % dict(admin_static_prefix(), bandpk=band.pk)
        )

    def test_relations_to_non_primary_key(self):
@@ -417,7 +419,7 @@ class ForeignKeyRawIdWidgetTest(DjangoTestCase):
        w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site)
        self.assertHTMLEqual(
            w.render('test', core.parent_id, attrs={}),
            '<input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/inventory/?_to_field=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Apple</strong>' % admin_static_prefix()
            '<input type="text" name="test" value="86" class="vForeignKeyRawIdAdminField" /><a href="/admin_widgets/inventory/?_to_field=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Apple</strong>' % admin_static_prefix()
        )

    def test_fk_related_model_not_in_admin(self):
@@ -459,11 +461,13 @@ class ForeignKeyRawIdWidgetTest(DjangoTestCase):
        )
        self.assertHTMLEqual(
            w.render('test', child_of_hidden.parent_id, attrs={}),
            '<input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="/widget_admin/admin_widgets/inventory/?_to_field=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Hidden</strong>' % admin_static_prefix()
            '<input type="text" name="test" value="93" class="vForeignKeyRawIdAdminField" /><a href="/admin_widgets/inventory/?_to_field=barcode" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>&nbsp;<strong>Hidden</strong>' % admin_static_prefix()
        )


class ManyToManyRawIdWidgetTest(DjangoTestCase):
    urls = 'admin_widgets.urls'

    def test_render(self):
        band = models.Band.objects.create(name='Linkin Park')

@@ -475,12 +479,12 @@ class ManyToManyRawIdWidgetTest(DjangoTestCase):
        w = widgets.ManyToManyRawIdWidget(rel, widget_admin_site)
        self.assertHTMLEqual(
            w.render('test', [m1.pk, m2.pk], attrs={}),
            '<input type="text" name="test" value="%(m1pk)s,%(m2pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="/static/admin/img/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_static_prefix(), m1pk=m1.pk, m2pk=m2.pk)
            '<input type="text" name="test" value="%(m1pk)s,%(m2pk)s" class="vManyToManyRawIdAdminField" /><a href="/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="/static/admin/img/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_static_prefix(), m1pk=m1.pk, m2pk=m2.pk)
        )

        self.assertHTMLEqual(
            w.render('test', [m1.pk]),
            '<input type="text" name="test" value="%(m1pk)s" class="vManyToManyRawIdAdminField" /><a href="/widget_admin/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_static_prefix(), m1pk=m1.pk)
            '<input type="text" name="test" value="%(m1pk)s" class="vManyToManyRawIdAdminField" /><a href="/admin_widgets/member/" class="related-lookup" id="lookup_id_test" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%(ADMIN_STATIC_PREFIX)simg/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % dict(admin_static_prefix(), m1pk=m1.pk)
        )

    def test_m2m_related_model_not_in_admin(self):
Loading