Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #20048, #20060 -- Modified tests for contrib apps sensitive to …

…custom User models.

Thanks to matiasb for the report of #20060 and the draft patch for #20048.
  • Loading branch information...
commit 930af661abdb4eb7322f1ab06f21df9ed04af43d 1 parent f7d945e
@freakboy3742 freakboy3742 authored
View
2  django/contrib/flatpages/tests/csrf.py
@@ -1,6 +1,7 @@
import os
from django.conf import settings
from django.contrib.auth.models import User
+from django.contrib.auth.tests.utils import skipIfCustomUser
from django.test import TestCase, Client
from django.test.utils import override_settings
@@ -38,6 +39,7 @@ def test_view_non_existent_flatpage(self):
response = self.client.get('/flatpage_root/no_such_flatpage/')
self.assertEqual(response.status_code, 404)
+ @skipIfCustomUser
def test_view_authenticated_flatpage(self):
"A flatpage served through a view can require authentication"
response = self.client.get('/flatpage_root/sekrit/')
View
3  django/contrib/flatpages/tests/middleware.py
@@ -1,6 +1,7 @@
import os
from django.conf import settings
from django.contrib.auth.models import User
+from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.flatpages.models import FlatPage
from django.test import TestCase
from django.test.utils import override_settings
@@ -36,6 +37,7 @@ def test_view_non_existent_flatpage(self):
response = self.client.get('/flatpage_root/no_such_flatpage/')
self.assertEqual(response.status_code, 404)
+ @skipIfCustomUser
def test_view_authenticated_flatpage(self):
"A flatpage served through a view can require authentication"
response = self.client.get('/flatpage_root/sekrit/')
@@ -57,6 +59,7 @@ def test_fallback_non_existent_flatpage(self):
response = self.client.get('/no_such_flatpage/')
self.assertEqual(response.status_code, 404)
+ @skipIfCustomUser
def test_fallback_authenticated_flatpage(self):
"A flatpage served by the middleware can require authentication"
response = self.client.get('/sekrit/')
View
12 django/contrib/flatpages/tests/templatetags.py
@@ -1,6 +1,7 @@
import os
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User
+from django.contrib.auth.tests.utils import skipIfCustomUser
from django.template import Template, Context, TemplateSyntaxError
from django.test import TestCase
from django.test.utils import override_settings
@@ -24,9 +25,6 @@ class FlatpageTemplateTagTests(TestCase):
fixtures = ['sample_flatpages']
urls = 'django.contrib.flatpages.tests.urls'
- def setUp(self):
- self.me = User.objects.create_user('testuser', 'test@example.com', 's3krit')
-
def test_get_flatpages_tag(self):
"The flatpage template tag retrives unregistered prefixed flatpages by default"
out = Template(
@@ -51,8 +49,10 @@ def test_get_flatpages_tag_for_anon_user(self):
}))
self.assertEqual(out, "A Flatpage,A Nested Flatpage,")
+ @skipIfCustomUser
def test_get_flatpages_tag_for_user(self):
"The flatpage template tag retrives all flatpages for an authenticated user"
+ me = User.objects.create_user('testuser', 'test@example.com', 's3krit')
out = Template(
"{% load flatpages %}"
"{% get_flatpages for me as flatpages %}"
@@ -60,7 +60,7 @@ def test_get_flatpages_tag_for_user(self):
"{{ page.title }},"
"{% endfor %}"
).render(Context({
- 'me': self.me
+ 'me': me
}))
self.assertEqual(out, "A Flatpage,A Nested Flatpage,Sekrit Nested Flatpage,Sekrit Flatpage,")
@@ -88,8 +88,10 @@ def test_get_flatpages_with_prefix_for_anon_user(self):
}))
self.assertEqual(out, "A Nested Flatpage,")
+ @skipIfCustomUser
def test_get_flatpages_with_prefix_for_user(self):
"The flatpage template tag retrive prefixed flatpages for an authenticated user"
+ me = User.objects.create_user('testuser', 'test@example.com', 's3krit')
out = Template(
"{% load flatpages %}"
"{% get_flatpages '/location/' for me as location_flatpages %}"
@@ -97,7 +99,7 @@ def test_get_flatpages_with_prefix_for_user(self):
"{{ page.title }},"
"{% endfor %}"
).render(Context({
- 'me': self.me
+ 'me': me
}))
self.assertEqual(out, "A Nested Flatpage,Sekrit Nested Flatpage,")
View
2  django/contrib/flatpages/tests/views.py
@@ -1,6 +1,7 @@
import os
from django.conf import settings
from django.contrib.auth.models import User
+from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.flatpages.models import FlatPage
from django.test import TestCase
from django.test.utils import override_settings
@@ -36,6 +37,7 @@ def test_view_non_existent_flatpage(self):
response = self.client.get('/flatpage_root/no_such_flatpage/')
self.assertEqual(response.status_code, 404)
+ @skipIfCustomUser
def test_view_authenticated_flatpage(self):
"A flatpage served through a view can require authentication"
response = self.client.get('/flatpage_root/sekrit/')
View
2  django/contrib/formtools/tests/wizard/cookiestorage.py
@@ -5,10 +5,12 @@
from django.core.exceptions import SuspiciousOperation
from django.http import HttpResponse
+from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.formtools.wizard.storage.cookie import CookieStorage
from django.contrib.formtools.tests.wizard.storage import get_request, TestStorage
+@skipIfCustomUser
class TestCookieStorage(TestStorage, TestCase):
def get_storage(self):
return CookieStorage
View
37 django/contrib/formtools/tests/wizard/forms.py
@@ -2,6 +2,7 @@
from django import forms, http
from django.conf import settings
+from django.db import models
from django.test import TestCase
from django.template.response import TemplateResponse
from django.utils.importlib import import_module
@@ -29,26 +30,40 @@ def get_request(*args, **kwargs):
request.session = engine.SessionStore(None)
return request
+
class Step1(forms.Form):
name = forms.CharField()
+
class Step2(forms.Form):
name = forms.CharField()
+
class Step3(forms.Form):
data = forms.CharField()
+
class CustomKwargsStep1(Step1):
def __init__(self, test=None, *args, **kwargs):
self.test = test
return super(CustomKwargsStep1, self).__init__(*args, **kwargs)
-class UserForm(forms.ModelForm):
+
+class TestModel(models.Model):
+ name = models.CharField(max_length=100)
+
class Meta:
- model = User
+ app_label = 'formtools'
+
+
+class TestModelForm(forms.ModelForm):
+ class Meta:
+ model = TestModel
+
+
+TestModelFormSet = forms.models.modelformset_factory(TestModel, form=TestModelForm, extra=2)
-UserFormSet = forms.models.modelformset_factory(User, form=UserForm, extra=2)
class TestWizard(WizardView):
storage_name = 'django.contrib.formtools.wizard.storage.session.SessionStorage'
@@ -149,8 +164,8 @@ def test_form_initial(self):
def test_form_instance(self):
request = get_request()
- the_instance = User()
- testform = TestWizard.as_view([('start', UserForm), ('step2', Step2)],
+ the_instance = TestModel()
+ testform = TestWizard.as_view([('start', TestModelForm), ('step2', Step2)],
instance_dict={'start': the_instance})
response, instance = testform(request)
@@ -163,12 +178,12 @@ def test_form_instance(self):
def test_formset_instance(self):
request = get_request()
- the_instance1, created = User.objects.get_or_create(
- username='testuser1')
- the_instance2, created = User.objects.get_or_create(
- username='testuser2')
- testform = TestWizard.as_view([('start', UserFormSet), ('step2', Step2)],
- instance_dict={'start': User.objects.filter(username='testuser1')})
+ the_instance1, created = TestModel.objects.get_or_create(
+ name='test object 1')
+ the_instance2, created = TestModel.objects.get_or_create(
+ name='test object 2')
+ testform = TestWizard.as_view([('start', TestModelFormSet), ('step2', Step2)],
+ instance_dict={'start': TestModel.objects.filter(name='test object 1')})
response, instance = testform(request)
self.assertEqual(list(instance.get_form_instance('start')), [the_instance1])
View
5 django/contrib/formtools/tests/wizard/namedwizardtests/tests.py
@@ -5,6 +5,7 @@
from django.test import TestCase
from django.contrib.auth.models import User
+from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.formtools.wizard.views import (NamedUrlSessionWizardView,
NamedUrlCookieWizardView)
@@ -276,6 +277,7 @@ def test_form_reset(self):
self.assertEqual(response.context['wizard']['steps'].current, 'form1')
+@skipIfCustomUser
class NamedSessionWizardTests(NamedWizardTests, TestCase):
wizard_urlname = 'nwiz_session'
wizard_step_1_data = {
@@ -307,6 +309,7 @@ class NamedSessionWizardTests(NamedWizardTests, TestCase):
)
+@skipIfCustomUser
class NamedCookieWizardTests(NamedWizardTests, TestCase):
wizard_urlname = 'nwiz_cookie'
wizard_step_1_data = {
@@ -367,11 +370,13 @@ def dispatch(self, request, *args, **kwargs):
return response, self
+@skipIfCustomUser
class NamedSessionFormTests(NamedFormTests, TestCase):
formwizard_class = TestNamedUrlSessionWizardView
wizard_urlname = 'nwiz_session'
+@skipIfCustomUser
class NamedCookieFormTests(NamedFormTests, TestCase):
formwizard_class = TestNamedUrlCookieWizardView
wizard_urlname = 'nwiz_cookie'
View
2  django/contrib/formtools/tests/wizard/sessionstorage.py
@@ -1,9 +1,11 @@
from django.test import TestCase
+from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.formtools.tests.wizard.storage import TestStorage
from django.contrib.formtools.wizard.storage.session import SessionStorage
+@skipIfCustomUser
class TestSessionStorage(TestStorage, TestCase):
def get_storage(self):
return SessionStorage
View
18 django/contrib/formtools/tests/wizard/wizardtests/tests.py
@@ -7,11 +7,19 @@
from django.test.client import RequestFactory
from django.conf import settings
from django.contrib.auth.models import User
+from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.formtools.wizard.views import CookieWizardView
-from django.contrib.formtools.tests.wizard.forms import UserForm, UserFormSet
from django.utils._os import upath
+class UserForm(forms.ModelForm):
+ class Meta:
+ model = User
+
+
+UserFormSet = forms.models.modelformset_factory(User, form=UserForm, extra=2)
+
+
class WizardTests(object):
urls = 'django.contrib.formtools.tests.wizard.wizardtests.urls'
@@ -75,7 +83,7 @@ def test_template_context(self):
# ticket #19025: `form` should be included in context
form = response.context_data['wizard']['form']
- self.assertEqual(response.context_data['form'], form)
+ self.assertEqual(response.context_data['form'], form)
def test_form_finish(self):
response = self.client.get(self.wizard_url)
@@ -196,6 +204,7 @@ def test_form_refresh(self):
self.assertEqual(response.status_code, 200)
+@skipIfCustomUser
class SessionWizardTests(WizardTests, TestCase):
wizard_url = '/wiz_session/'
wizard_step_1_data = {
@@ -226,6 +235,8 @@ class SessionWizardTests(WizardTests, TestCase):
}
)
+
+@skipIfCustomUser
class CookieWizardTests(WizardTests, TestCase):
wizard_url = '/wiz_cookie/'
wizard_step_1_data = {
@@ -256,6 +267,8 @@ class CookieWizardTests(WizardTests, TestCase):
}
)
+
+@skipIfCustomUser
class WizardTestKwargs(TestCase):
wizard_url = '/wiz_other_template/'
wizard_step_1_data = {
@@ -347,6 +360,7 @@ def get_context_data(self, **kwargs):
self.assertEqual(response.context_data['another_key'], 'another_value')
+@skipIfCustomUser
class WizardFormKwargsOverrideTests(TestCase):
def setUp(self):
super(WizardFormKwargsOverrideTests, self).setUp()
View
19 django/contrib/sitemaps/tests/base.py
@@ -1,9 +1,24 @@
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.cache import cache
+from django.db import models
from django.test import TestCase
+class TestModel(models.Model):
+ "A test model for "
+ name = models.CharField(max_length=100)
+
+ class Meta:
+ app_label = 'sitemaps'
+
+ def __unicode__(self):
+ return self.name
+
+ def get_absolute_url(self):
+ return '/testmodel/%s/' % self.id
+
+
class SitemapTestsBase(TestCase):
protocol = 'http'
domain = 'example.com' if Site._meta.installed else 'testserver'
@@ -13,8 +28,8 @@ def setUp(self):
self.base_url = '%s://%s' % (self.protocol, self.domain)
self.old_Site_meta_installed = Site._meta.installed
cache.clear()
- # Create a user that will double as sitemap content
- User.objects.create_user('testuser', 'test@example.com', 's3krit')
+ # Create an object for sitemap content.
+ TestModel.objects.create(name='Test Object')
def tearDown(self):
Site._meta.installed = self.old_Site_meta_installed
View
8 django/contrib/sitemaps/tests/generic.py
@@ -1,9 +1,9 @@
from __future__ import unicode_literals
-from django.contrib.auth.models import User
from django.test.utils import override_settings
-from .base import SitemapTestsBase
+from .base import TestModel, SitemapTestsBase
+
@override_settings(ABSOLUTE_URL_OVERRIDES={})
class GenericViewsSitemapTests(SitemapTestsBase):
@@ -12,8 +12,8 @@ def test_generic_sitemap(self):
"A minimal generic sitemap can be rendered"
response = self.client.get('/generic/sitemap.xml')
expected = ''
- for username in User.objects.values_list("username", flat=True):
- expected += "<url><loc>%s/users/%s/</loc></url>" % (self.base_url, username)
+ for pk in TestModel.objects.values_list("id", flat=True):
+ expected += "<url><loc>%s/testmodel/%s/</loc></url>" % (self.base_url, pk)
expected_content = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
%s
View
11 django/contrib/sitemaps/tests/http.py
@@ -4,7 +4,6 @@
from datetime import date
from django.conf import settings
-from django.contrib.auth.models import User
from django.contrib.sitemaps import Sitemap, GenericSitemap
from django.contrib.sites.models import Site
from django.core.exceptions import ImproperlyConfigured
@@ -14,7 +13,7 @@
from django.utils._os import upath
from django.utils.translation import activate, deactivate
-from .base import SitemapTestsBase
+from .base import TestModel, SitemapTestsBase
class HTTPSitemapTests(SitemapTestsBase):
@@ -128,10 +127,10 @@ def test_sitemap_item(self):
Check to make sure that the raw item is included with each
Sitemap.get_url() url result.
"""
- user_sitemap = GenericSitemap({'queryset': User.objects.all()})
- def is_user(url):
- return isinstance(url['item'], User)
- item_in_url_info = all(map(is_user, user_sitemap.get_urls()))
+ test_sitemap = GenericSitemap({'queryset': TestModel.objects.all()})
+ def is_testmodel(url):
+ return isinstance(url['item'], TestModel)
+ item_in_url_info = all(map(is_testmodel, test_sitemap.get_urls()))
self.assertTrue(item_in_url_info)
def test_cached_sitemap_index(self):
View
5 django/contrib/sitemaps/tests/urls/http.py
@@ -4,6 +4,9 @@
from django.contrib.auth.models import User
from django.views.decorators.cache import cache_page
+from django.contrib.sitemaps.tests.base import TestModel
+
+
class SimpleSitemap(Sitemap):
changefreq = "never"
priority = 0.5
@@ -18,7 +21,7 @@ def items(self):
}
generic_sitemaps = {
- 'generic': GenericSitemap({'queryset': User.objects.all()}),
+ 'generic': GenericSitemap({'queryset': TestModel.objects.all()}),
}
flatpage_sitemaps = {
Please sign in to comment.
Something went wrong with that request. Please try again.