Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1852 from jasonamyers/cleanup/PEP8

Cleanup/pep8 tests
  • Loading branch information...
commit 7288e1b02b2504b1694fe14df2d81e6a354c5610 2 parents 91078f5 + 4f151da
@alex alex authored
Showing with 1,631 additions and 290 deletions.
  1. +2 −1  django/forms/widgets.py
  2. +1 −1  setup.cfg
  3. +15 −0 tests/admin_changelist/models.py
  4. +2 −0  tests/admin_custom_urls/models.py
  5. +2 −0  tests/admin_docs/views.py
  6. +1 −0  tests/admin_filters/models.py
  7. +3 −0  tests/admin_inlines/admin.py
  8. +21 −0 tests/admin_inlines/models.py
  9. +13 −11 tests/admin_inlines/tests.py
  10. +4 −0 tests/admin_ordering/models.py
  11. +1 −0  tests/admin_ordering/tests.py
  12. +9 −0 tests/admin_scripts/tests.py
  13. +5 −0 tests/admin_util/models.py
  14. +3 −3 tests/admin_util/tests.py
  15. +3 −0  tests/admin_validation/tests.py
  16. +22 −0 tests/admin_views/admin.py
  17. +22 −0 tests/admin_views/models.py
  18. +15 −20 tests/admin_views/tests.py
  19. +1 −0  tests/admin_views/views.py
  20. +14 −0 tests/admin_widgets/models.py
  21. +15 −1 tests/admin_widgets/tests.py
  22. +3 −0  tests/aggregation/models.py
  23. +5 −1 tests/aggregation_regress/models.py
  24. +10 −8 tests/backends/tests.py
  25. +2 −0  tests/basic/models.py
  26. +32 −16 tests/basic/tests.py
  27. +2 −0  tests/bug639/models.py
  28. +5 −0 tests/bulk_create/models.py
  29. +1 −0  tests/cache/closeable_cache.py
  30. +1 −0  tests/cache/liberal_backend.py
  31. +1 −0  tests/cache/models.py
  32. +6 −0 tests/cache/tests.py
  33. +2 −0  tests/check/models.py
  34. +1 −0  tests/check/tests.py
  35. +1 −0  tests/choices/models.py
  36. +1 −0  tests/commands_sql/tests.py
  37. +1 −0  tests/conditional_processing/tests.py
  38. +4 −0 tests/conditional_processing/views.py
  39. +2 −0  tests/contenttypes_tests/models.py
  40. +1 −0  tests/contenttypes_tests/tests.py
  41. +5 −0 tests/csrf_tests/tests.py
  42. +1 −0  tests/custom_columns/models.py
  43. +1 −0  tests/custom_columns_regress/models.py
  44. +1 −0  tests/custom_columns_regress/tests.py
  45. +10 −0 tests/custom_managers/models.py
  46. +3 −0  tests/custom_managers_regress/models.py
  47. +1 −0  tests/custom_pk/fields.py
  48. +3 −1 tests/custom_pk/models.py
  49. +1 −0  tests/datatypes/models.py
  50. +2 −0  tests/dates/models.py
  51. +2 −0  tests/datetimes/models.py
  52. +1 −0  tests/db_typecasts/tests.py
  53. +2 −1  tests/decorators/tests.py
  54. +4 −0 tests/defer/models.py
  55. +14 −0 tests/defer_regress/models.py
  56. +1 −0  tests/defer_regress/tests.py
  57. +6 −0 tests/delete/models.py
  58. +2 −1  tests/delete/tests.py
  59. +28 −0 tests/delete_regress/models.py
  60. +2 −1  tests/delete_regress/tests.py
  61. +5 −3 tests/dispatch/tests/test_dispatcher.py
  62. +4 −0 tests/dispatch/tests/test_saferef.py
  63. +5 −0 tests/distinct_on_fields/models.py
  64. +2 −1  tests/distinct_on_fields/tests.py
  65. +1 −0  tests/expressions/models.py
  66. +1 −0  tests/expressions_regress/models.py
  67. +35 −35 tests/expressions_regress/tests.py
  68. +2 −0  tests/extra_regress/models.py
  69. +2 −0  tests/field_subclassing/fields.py
  70. +2 −0  tests/field_subclassing/models.py
  71. +1 −0  tests/file_storage/models.py
  72. +5 −0 tests/file_storage/tests.py
  73. +2 −1  tests/file_uploads/tests.py
  74. +3 −1 tests/file_uploads/uploadhandler.py
  75. +10 −0 tests/file_uploads/views.py
  76. +8 −0 tests/fixtures/models.py
  77. +1 −0  tests/fixtures_model_package/models/__init__.py
  78. +1 −0  tests/fixtures_regress/models.py
  79. +4 −0 tests/force_insert_update/models.py
  80. +11 −0 tests/foreign_object/models.py
  81. +2 −0  tests/foreign_object/tests.py
  82. +4 −1 tests/forms_tests/models.py
  83. +1 −0  tests/forms_tests/tests/test_error_messages.py
  84. +3 −0  tests/forms_tests/tests/test_extra.py
  85. +5 −1 tests/forms_tests/tests/test_formsets.py
  86. +2 −0  tests/forms_tests/tests/test_input_formats.py
  87. +3 −1 tests/forms_tests/tests/test_widgets.py
  88. +1 −0  tests/forms_tests/tests/tests.py
  89. +1 −0  tests/generic_inline_admin/admin.py
  90. +2 −0  tests/generic_inline_admin/models.py
  91. +3 −0  tests/generic_inline_admin/tests.py
  92. +2 −0  tests/generic_relations/tests.py
  93. +25 −0 tests/generic_relations_regress/models.py
  94. +4 −0 tests/generic_views/models.py
  95. +1 −0  tests/generic_views/test_base.py
  96. +2 −1  tests/generic_views/test_dates.py
  97. +19 −0 tests/generic_views/views.py
  98. +2 −0  tests/get_object_or_404/models.py
  99. +2 −0  tests/get_or_create_regress/models.py
  100. +5 −0 tests/handlers/views.py
  101. +5 −0 tests/httpwrappers/tests.py
  102. +2 −0  tests/i18n/forms.py
  103. +1 −0  tests/i18n/models.py
  104. +12 −6 tests/i18n/test_extraction.py
  105. +3 −0  tests/i18n/tests.py
  106. +4 −0 tests/inline_formsets/models.py
  107. +6 −0 tests/inspectdb/models.py
  108. +2 −1  tests/inspectdb/tests.py
  109. +4 −0 tests/known_related_objects/models.py
  110. +1 −0  tests/known_related_objects/tests.py
  111. +2 −0  tests/logging_tests/tests.py
  112. +5 −0 tests/lookup/models.py
  113. +2 −0  tests/m2m_and_m2o/models.py
  114. +2 −1  tests/m2m_and_m2o/tests.py
  115. +2 −0  tests/m2m_intermediary/models.py
  116. +9 −0 tests/m2m_regress/models.py
  117. +3 −0  tests/m2m_signals/models.py
  118. +6 −0 tests/m2m_through/models.py
  119. +9 −0 tests/m2m_through_regress/models.py
  120. +1 −0  tests/m2o_recursive/models.py
  121. +1 −0  tests/m2o_recursive/tests.py
  122. +1 −0  tests/many_to_many/models.py
  123. +1 −0  tests/many_to_one/models.py
  124. +1 −0  tests/many_to_one_null/models.py
  125. +10 −1 tests/many_to_one_regress/models.py
  126. +1 −0  tests/max_lengths/models.py
  127. +1 −0  tests/max_lengths/tests.py
  128. +7 −5 tests/middleware/tests.py
  129. +2 −0  tests/middleware_exceptions/tests.py
  130. +6 −0 tests/middleware_exceptions/views.py
  131. +8 −0 tests/model_fields/tests.py
  132. +28 −0 tests/model_forms/models.py
  133. +8 −3 tests/model_forms/tests.py
  134. +12 −0 tests/model_forms_regress/models.py
  135. +6 −1 tests/model_forms_regress/tests.py
  136. +26 −0 tests/model_formsets/models.py
  137. +6 −0 tests/model_formsets_regress/models.py
  138. +1 −0  tests/model_formsets_regress/tests.py
  139. +22 −0 tests/model_inheritance/models.py
  140. +37 −0 tests/model_inheritance_regress/models.py
  141. +1 −0  tests/model_inheritance_same_model_name/models.py
  142. +2 −0  tests/model_inheritance_select_related/models.py
  143. +1 −0  tests/model_validation/models.py
  144. +3 −0  tests/modeladmin/models.py
  145. +6 −0 tests/multiple_database/models.py
  146. +117 −99 tests/multiple_database/tests.py
  147. +1 −0  tests/mutually_referential/models.py
  148. +2 −0  tests/nested_foreign_keys/models.py
  149. +7 −0 tests/null_fk/models.py
  150. +4 −0 tests/null_fk_ordering/models.py
  151. +5 −0 tests/null_queries/models.py
  152. +7 −2 tests/one_to_one/models.py
  153. +1 −0  tests/one_to_one/tests.py
  154. +2 −0  tests/order_with_respect_to/models.py
  155. +1 −0  tests/ordering/models.py
  156. +5 −0 tests/prefetch_related/models.py
  157. +2 −0  tests/proxy_model_inheritance/models.py
  158. +26 −0 tests/proxy_models/models.py
  159. +91 −0 tests/queries/models.py
  160. +31 −9 tests/queries/tests.py
  161. +6 −0 tests/queryset_pickle/models.py
  162. +4 −0 tests/raw_query/models.py
  163. +1 −0  tests/responses/tests.py
  164. +2 −0  tests/reverse_lookup/models.py
  165. +2 −0  tests/reverse_single_related/models.py
  166. +10 −0 tests/select_related/models.py
  167. +2 −0  tests/select_related_onetoone/models.py
  168. +28 −0 tests/select_related_regress/models.py
  169. +8 −4 tests/serializers/tests.py
  170. +63 −0 tests/serializers_regress/models.py
  171. +24 −0 tests/serializers_regress/tests.py
  172. +1 −0  tests/servers/tests.py
  173. +1 −0  tests/settings_tests/tests.py
  174. +1 −0  tests/signals/models.py
  175. +2 −0  tests/signals/tests.py
  176. +1 −0  tests/signals_regress/models.py
  177. +1 −0  tests/signing/tests.py
  178. +6 −0 tests/sites_framework/models.py
  179. +1 −0  tests/staticfiles_tests/storage.py
  180. +1 −0  tests/str/models.py
  181. +5 −0 tests/string_lookup/models.py
  182. +1 −0  tests/syndication/tests.py
  183. +4 −0 tests/tablespaces/models.py
  184. +2 −0  tests/tablespaces/tests.py
  185. +9 −4 tests/template_tests/filters.py
  186. +2 −0  tests/template_tests/templatetags/bad_tag.py
  187. +49 −0 tests/template_tests/templatetags/custom.py
  188. +1 −0  tests/template_tests/templatetags/subpackage/echo.py
  189. +1 −0  tests/template_tests/test_callables.py
  190. +7 −6 tests/template_tests/test_loaders.py
  191. +2 −1  tests/template_tests/test_nodelist.py
  192. +3 −2 tests/template_tests/test_response.py
  193. +1 −0  tests/template_tests/test_smartif.py
  194. +22 −9 tests/template_tests/tests.py
  195. +5 −0 tests/template_tests/views.py
  196. +3 −1 tests/test_client/tests.py
  197. +22 −0 tests/test_client/views.py
  198. +1 −0  tests/test_client_regress/session.py
  199. +22 −6 tests/test_client_regress/tests.py
  200. +18 −0 tests/test_client_regress/views.py
  201. +1 −0  tests/test_runner/models.py
  202. +1 −0  tests/test_runner_deprecation_app/tests.py
  203. +1 −0  tests/test_utils/models.py
  204. +2 −0  tests/timezones/admin.py
  205. +5 −0 tests/timezones/forms.py
  206. +6 −0 tests/timezones/models.py
  207. +11 −5 tests/transactions/tests.py
  208. +2 −0  tests/transactions_regress/models.py
  209. +4 −1 tests/transactions_regress/tests.py
  210. +12 −1 tests/unmanaged_models/models.py
  211. +4 −0 tests/update/models.py
  212. +1 −0  tests/update_only_fields/models.py
  213. +1 −0  tests/urlpatterns_reverse/erroneous_views_module.py
  214. +5 −0 tests/urlpatterns_reverse/middleware.py
  215. +11 −1 tests/urlpatterns_reverse/tests.py
  216. +1 −0  tests/urlpatterns_reverse/urlconf_inner.py
  217. +10 −0 tests/urlpatterns_reverse/views.py
  218. +1 −0  tests/user_commands/management/commands/leave_locale_alone_false.py
  219. +1 −0  tests/user_commands/management/commands/leave_locale_alone_true.py
  220. +1 −0  tests/utils_tests/test_baseconv.py
  221. +1 −0  tests/utils_tests/test_checksums.py
  222. +1 −0  tests/utils_tests/test_datetime_safe.py
  223. +1 −0  tests/utils_tests/test_decorators.py
  224. +1 −0  tests/utils_tests/test_ipv6.py
  225. +3 −0  tests/utils_tests/test_jslex.py
  226. +5 −0 tests/utils_tests/test_module_loading.py
  227. +1 −0  tests/utils_tests/test_simplelazyobject.py
  228. +1 −0  tests/utils_tests/test_text.py
  229. +5 −4 tests/utils_tests/test_tzinfo.py
  230. +13 −0 tests/validation/models.py
  231. +1 −0  tests/validation/test_unique.py
  232. +2 −1  tests/validation/tests.py
  233. +6 −4 tests/validators/tests.py
  234. +1 −0  tests/version/tests.py
  235. +1 −0  tests/view_tests/__init__.py
  236. +5 −0 tests/view_tests/models.py
  237. +1 −0  tests/view_tests/templatetags/debugtags.py
  238. +2 −1  tests/view_tests/tests/test_debug.py
  239. +1 −0  tests/view_tests/tests/test_shortcuts.py
  240. +32 −0 tests/view_tests/views.py
  241. +1 −0  tests/wsgi/urls.py
View
3  django/forms/widgets.py
@@ -387,7 +387,8 @@ def render(self, name, value, attrs=None):
def value_from_datadict(self, data, files, name):
upload = super(ClearableFileInput, self).value_from_datadict(data, files, name)
if not self.is_required and CheckboxInput().value_from_datadict(
- data, files, self.clear_checkbox_name(name)):
+ data, files, self.clear_checkbox_name(name)):
+
if upload:
# If the user contradicts themselves (uploads a new file AND
# checks the "clear" checkbox), we return a unique marker
View
2  setup.cfg
@@ -4,7 +4,7 @@ install-script = scripts/rpm-install.sh
[flake8]
exclude=./django/utils/dictconfig.py,./django/contrib/comments/*,./django/utils/unittest.py,./tests/comment_tests/*,./django/test/_doctest.py,./django/utils/six.py,./django/conf/app_template/*
-ignore=E124,E125,E127,E128,E226,E251,E302,E501,W601
+ignore=E124,E125,E127,E128,E226,E251,E501,W601
[metadata]
license-file = LICENSE
View
15 tests/admin_changelist/models.py
@@ -1,26 +1,32 @@
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
+
class Event(models.Model):
# Oracle can have problems with a column named "date"
date = models.DateField(db_column="event_date")
+
class Parent(models.Model):
name = models.CharField(max_length=128)
+
class Child(models.Model):
parent = models.ForeignKey(Parent, editable=False, null=True)
name = models.CharField(max_length=30, blank=True)
age = models.IntegerField(null=True, blank=True)
+
class Genre(models.Model):
name = models.CharField(max_length=20)
+
class Band(models.Model):
name = models.CharField(max_length=20)
nr_of_members = models.PositiveIntegerField()
genres = models.ManyToManyField(Genre)
+
@python_2_unicode_compatible
class Musician(models.Model):
name = models.CharField(max_length=30)
@@ -28,6 +34,7 @@ class Musician(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Group(models.Model):
name = models.CharField(max_length=30)
@@ -36,26 +43,32 @@ class Group(models.Model):
def __str__(self):
return self.name
+
class Membership(models.Model):
music = models.ForeignKey(Musician)
group = models.ForeignKey(Group)
role = models.CharField(max_length=15)
+
class Quartet(Group):
pass
+
class ChordsMusician(Musician):
pass
+
class ChordsBand(models.Model):
name = models.CharField(max_length=30)
members = models.ManyToManyField(ChordsMusician, through='Invitation')
+
class Invitation(models.Model):
player = models.ForeignKey(ChordsMusician)
band = models.ForeignKey(ChordsBand)
instrument = models.CharField(max_length=15)
+
class Swallow(models.Model):
origin = models.CharField(max_length=255)
load = models.FloatField()
@@ -77,6 +90,7 @@ class OrderedObjectManager(models.Manager):
def get_queryset(self):
return super(OrderedObjectManager, self).get_queryset().order_by('number')
+
class OrderedObject(models.Model):
"""
Model with Manager that defines a default order.
@@ -88,5 +102,6 @@ class OrderedObject(models.Model):
objects = OrderedObjectManager()
+
class CustomIdUser(models.Model):
uuid = models.AutoField(primary_key=True)
View
2  tests/admin_custom_urls/models.py
@@ -54,6 +54,7 @@ def wrapper(*args, **kwargs):
class Person(models.Model):
name = models.CharField(max_length=20)
+
class PersonAdmin(admin.ModelAdmin):
def response_post_save_add(self, request, obj):
@@ -68,6 +69,7 @@ def response_post_save_change(self, request, obj):
class Car(models.Model):
name = models.CharField(max_length=20)
+
class CarAdmin(admin.ModelAdmin):
def response_add(self, request, obj, post_url_continue=None):
View
2  tests/admin_docs/views.py
@@ -5,9 +5,11 @@
xview_dec = decorator_from_middleware(XViewMiddleware)
+
def xview(request):
return HttpResponse()
+
class XViewClass(View):
def get(self, request):
return HttpResponse()
View
1  tests/admin_filters/models.py
@@ -27,6 +27,7 @@ class Department(models.Model):
def __str__(self):
return self.description
+
@python_2_unicode_compatible
class Employee(models.Model):
department = models.ForeignKey(Department, to_field="code")
View
3  tests/admin_inlines/admin.py
@@ -153,6 +153,7 @@ class ChildModel1Inline(admin.TabularInline):
class ChildModel2Inline(admin.StackedInline):
model = ChildModel2
+
# admin for #19425 and #18388
class BinaryTreeAdmin(admin.TabularInline):
model = BinaryTree
@@ -169,10 +170,12 @@ def get_max_num(self, request, obj=None, **kwargs):
return max_num - obj.binarytree_set.count()
return max_num
+
# admin for #19524
class SightingInline(admin.TabularInline):
model = Sighting
+
# admin and form for #18263
class SomeChildModelForm(forms.ModelForm):
View
21 tests/admin_inlines/models.py
@@ -89,6 +89,7 @@ class Inner2(models.Model):
dummy = models.IntegerField()
holder = models.ForeignKey(Holder2)
+
class Holder3(models.Model):
dummy = models.IntegerField()
@@ -99,38 +100,47 @@ class Inner3(models.Model):
# Models for ticket #8190
+
class Holder4(models.Model):
dummy = models.IntegerField()
+
class Inner4Stacked(models.Model):
dummy = models.IntegerField(help_text="Awesome stacked help text is awesome.")
holder = models.ForeignKey(Holder4)
+
class Inner4Tabular(models.Model):
dummy = models.IntegerField(help_text="Awesome tabular help text is awesome.")
holder = models.ForeignKey(Holder4)
# Models for #12749
+
class Person(models.Model):
firstname = models.CharField(max_length=15)
+
class OutfitItem(models.Model):
name = models.CharField(max_length=15)
+
class Fashionista(models.Model):
person = models.OneToOneField(Person, primary_key=True)
weaknesses = models.ManyToManyField(OutfitItem, through='ShoppingWeakness', blank=True)
+
class ShoppingWeakness(models.Model):
fashionista = models.ForeignKey(Fashionista)
item = models.ForeignKey(OutfitItem)
# Models for #13510
+
class TitleCollection(models.Model):
pass
+
class Title(models.Model):
collection = models.ForeignKey(TitleCollection, blank=True, null=True)
title1 = models.CharField(max_length=100)
@@ -138,19 +148,24 @@ class Title(models.Model):
# Models for #15424
+
class Poll(models.Model):
name = models.CharField(max_length=40)
+
class Question(models.Model):
poll = models.ForeignKey(Poll)
+
class Novel(models.Model):
name = models.CharField(max_length=40)
+
class Chapter(models.Model):
name = models.CharField(max_length=40)
novel = models.ForeignKey(Novel)
+
class FootNote(models.Model):
"""
Model added for ticket 19838
@@ -160,6 +175,7 @@ class FootNote(models.Model):
# Models for #16838
+
class CapoFamiglia(models.Model):
name = models.CharField(max_length=100)
@@ -211,12 +227,15 @@ class BinaryTree(models.Model):
# Models for #19524
+
class LifeForm(models.Model):
pass
+
class ExtraTerrestrial(LifeForm):
name = models.CharField(max_length=100)
+
class Sighting(models.Model):
et = models.ForeignKey(ExtraTerrestrial)
place = models.CharField(max_length=100)
@@ -234,9 +253,11 @@ class SomeChildModel(models.Model):
# Other models
+
class ProfileCollection(models.Model):
pass
+
class Profile(models.Model):
collection = models.ForeignKey(ProfileCollection, blank=True, null=True)
first_name = models.CharField(max_length=100)
View
24 tests/admin_inlines/tests.py
@@ -279,6 +279,7 @@ def test_all_inline_media(self):
self.assertContains(response, 'my_awesome_admin_scripts.js')
self.assertContains(response, 'my_awesome_inline_scripts.js')
+
class TestInlineAdminForm(TestCase):
urls = "admin_inlines.urls"
@@ -465,9 +466,9 @@ def test_inline_change_fk_add_perm(self):
self.assertContains(response, 'Add another Inner2')
# 3 extra forms only, not the existing instance form
self.assertContains(response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" '
- 'value="3" name="inner2_set-TOTAL_FORMS" />', html=True)
+ 'value="3" name="inner2_set-TOTAL_FORMS" />', html=True)
self.assertNotContains(response, '<input type="hidden" id="id_inner2_set-0-id" '
- 'value="%i" name="inner2_set-0-id" />' % self.inner2_id, html=True)
+ 'value="%i" name="inner2_set-0-id" />' % self.inner2_id, html=True)
def test_inline_change_fk_change_perm(self):
permission = Permission.objects.get(codename='change_inner2', content_type=self.inner_ct)
@@ -477,12 +478,12 @@ def test_inline_change_fk_change_perm(self):
self.assertContains(response, '<h2>Inner2s</h2>')
# Just the one form for existing instances
self.assertContains(response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" '
- 'value="1" name="inner2_set-TOTAL_FORMS" />', html=True)
+ 'value="1" name="inner2_set-TOTAL_FORMS" />', html=True)
self.assertContains(response, '<input type="hidden" id="id_inner2_set-0-id" '
- 'value="%i" name="inner2_set-0-id" />' % self.inner2_id, html=True)
+ 'value="%i" name="inner2_set-0-id" />' % self.inner2_id, html=True)
# max-num 0 means we can't add new ones
self.assertContains(response, '<input type="hidden" id="id_inner2_set-MAX_NUM_FORMS" '
- 'value="0" name="inner2_set-MAX_NUM_FORMS" />', html=True)
+ 'value="0" name="inner2_set-MAX_NUM_FORMS" />', html=True)
def test_inline_change_fk_add_change_perm(self):
permission = Permission.objects.get(codename='add_inner2', content_type=self.inner_ct)
@@ -494,9 +495,9 @@ def test_inline_change_fk_add_change_perm(self):
self.assertContains(response, '<h2>Inner2s</h2>')
# One form for existing instance and three extra for new
self.assertContains(response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" '
- 'value="4" name="inner2_set-TOTAL_FORMS" />', html=True)
+ 'value="4" name="inner2_set-TOTAL_FORMS" />', html=True)
self.assertContains(response, '<input type="hidden" id="id_inner2_set-0-id" '
- 'value="%i" name="inner2_set-0-id" />' % self.inner2_id, html=True)
+ 'value="%i" name="inner2_set-0-id" />' % self.inner2_id, html=True)
def test_inline_change_fk_change_del_perm(self):
permission = Permission.objects.get(codename='change_inner2', content_type=self.inner_ct)
@@ -508,9 +509,9 @@ def test_inline_change_fk_change_del_perm(self):
self.assertContains(response, '<h2>Inner2s</h2>')
# One form for existing instance only, no new
self.assertContains(response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" '
- 'value="1" name="inner2_set-TOTAL_FORMS" />', html=True)
+ 'value="1" name="inner2_set-TOTAL_FORMS" />', html=True)
self.assertContains(response, '<input type="hidden" id="id_inner2_set-0-id" '
- 'value="%i" name="inner2_set-0-id" />' % self.inner2_id, html=True)
+ 'value="%i" name="inner2_set-0-id" />' % self.inner2_id, html=True)
self.assertContains(response, 'id="id_inner2_set-0-DELETE"')
def test_inline_change_fk_all_perms(self):
@@ -525,9 +526,9 @@ def test_inline_change_fk_all_perms(self):
self.assertContains(response, '<h2>Inner2s</h2>')
# One form for existing instance only, three for new
self.assertContains(response, '<input type="hidden" id="id_inner2_set-TOTAL_FORMS" '
- 'value="4" name="inner2_set-TOTAL_FORMS" />', html=True)
+ 'value="4" name="inner2_set-TOTAL_FORMS" />', html=True)
self.assertContains(response, '<input type="hidden" id="id_inner2_set-0-id" '
- 'value="%i" name="inner2_set-0-id" />' % self.inner2_id, html=True)
+ 'value="%i" name="inner2_set-0-id" />' % self.inner2_id, html=True)
self.assertContains(response, 'id="id_inner2_set-0-DELETE"')
@@ -698,5 +699,6 @@ def test_alternating_rows(self):
class SeleniumChromeTests(SeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
+
class SeleniumIETests(SeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
View
4 tests/admin_ordering/models.py
@@ -11,6 +11,7 @@ class Band(models.Model):
class Meta:
ordering = ('name',)
+
class Song(models.Model):
band = models.ForeignKey(Band)
name = models.CharField(max_length=100)
@@ -20,13 +21,16 @@ class Song(models.Model):
class Meta:
ordering = ('name',)
+
class SongInlineDefaultOrdering(admin.StackedInline):
model = Song
+
class SongInlineNewOrdering(admin.StackedInline):
model = Song
ordering = ('duration', )
+
class DynOrderingBandAdmin(admin.ModelAdmin):
def get_ordering(self, request):
View
1  tests/admin_ordering/tests.py
@@ -12,6 +12,7 @@
class MockRequest(object):
pass
+
class MockSuperUser(object):
def has_perm(self, perm):
return True
View
9 tests/admin_scripts/tests.py
@@ -289,6 +289,7 @@ def test_custom_command_with_environment(self):
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:NoArgsCommand")
+
class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):
"""A series of tests for django-admin.py when using a settings.py file that
contains the test application specified using a full path.
@@ -355,6 +356,7 @@ def test_custom_command_with_environment(self):
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:NoArgsCommand")
+
class DjangoAdminMinimalSettings(AdminScriptTestCase):
"""A series of tests for django-admin.py when using a settings.py file that
doesn't contain the test application.
@@ -421,6 +423,7 @@ def test_custom_command_with_environment(self):
self.assertNoOutput(out)
self.assertOutput(err, "Unknown command: 'noargs_command'")
+
class DjangoAdminAlternateSettings(AdminScriptTestCase):
"""A series of tests for django-admin.py when using a settings file
with a name other than 'settings.py'.
@@ -796,6 +799,7 @@ def test_custom_command_with_environment(self):
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:NoArgsCommand")
+
class ManageMinimalSettings(AdminScriptTestCase):
"""A series of tests for manage.py when using a settings.py file that
doesn't contain the test application.
@@ -862,6 +866,7 @@ def test_custom_command_with_environment(self):
self.assertNoOutput(out)
self.assertOutput(err, "Unknown command: 'noargs_command'")
+
class ManageAlternateSettings(AdminScriptTestCase):
"""A series of tests for manage.py when using a settings file
with a name other than 'settings.py'.
@@ -1121,6 +1126,7 @@ def __init__(self, *args, **kwargs):
def run_tests(self, test_labels, extra_tests=None, **kwargs):
pass
+
class ManageTestCommand(AdminScriptTestCase):
def setUp(self):
from django.core.management.commands.test import Command as TestCommand
@@ -1214,6 +1220,7 @@ def test_runner_ambiguous(self):
self.cmd.handle(addrport="deadbeef:7654")
self.assertServerSettings('deadbeef', '7654')
+
class ManageRunserverEmptyAllowedHosts(AdminScriptTestCase):
def setUp(self):
self.write_settings('settings.py', sdict={
@@ -1464,6 +1471,7 @@ def test_label_command_multiple_label(self):
self.assertOutput(out, str_prefix("EXECUTE:LabelCommand label=testlabel, options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', %(_)s'1')]"))
self.assertOutput(out, str_prefix("EXECUTE:LabelCommand label=anotherlabel, options=[('no_color', False), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', %(_)s'1')]"))
+
class ArgumentOrder(AdminScriptTestCase):
"""Tests for 2-stage argument parsing scheme.
@@ -1751,6 +1759,7 @@ def test_all(self):
self.assertNoOutput(err)
self.assertOutput(out, "### STATIC_URL = None")
+
class Dumpdata(AdminScriptTestCase):
"""Tests for dumpdata management command."""
View
5 tests/admin_util/models.py
@@ -19,6 +19,7 @@ def test_from_model_with_override(self):
return "nothing"
test_from_model_with_override.short_description = "not What you Expect"
+
@python_2_unicode_compatible
class Count(models.Model):
num = models.PositiveSmallIntegerField()
@@ -27,12 +28,15 @@ class Count(models.Model):
def __str__(self):
return six.text_type(self.num)
+
class Event(models.Model):
date = models.DateTimeField(auto_now_add=True)
+
class Location(models.Model):
event = models.OneToOneField(Event, verbose_name='awesome event')
+
class Guest(models.Model):
event = models.OneToOneField(Event)
name = models.CharField(max_length=255)
@@ -40,5 +44,6 @@ class Guest(models.Model):
class Meta:
verbose_name = "awesome guest"
+
class EventGuide(models.Model):
event = models.ForeignKey(Event, on_delete=models.DO_NOTHING)
View
6 tests/admin_util/tests.py
@@ -80,6 +80,7 @@ def test_on_delete_do_nothing(self):
# One for Location, one for Guest, and no query for EventGuide
n.collect(objs)
+
class UtilTests(SimpleTestCase):
def test_values_from_lookup_field(self):
"""
@@ -228,9 +229,8 @@ def test_from_model(self, obj):
)
self.assertEqual(
label_for_field("test_from_model", Article,
- model_admin = MockModelAdmin,
- return_attr = True
- ),
+ model_admin=MockModelAdmin,
+ return_attr=True),
("not Really the Model", MockModelAdmin.test_from_model)
)
View
3  tests/admin_validation/tests.py
@@ -12,10 +12,12 @@
class SongForm(forms.ModelForm):
pass
+
class ValidFields(admin.ModelAdmin):
form = SongForm
fields = ['title']
+
class ValidFormFieldsets(admin.ModelAdmin):
def get_form(self, request, obj=None, **kwargs):
class ExtraFieldForm(SongForm):
@@ -28,6 +30,7 @@ class ExtraFieldForm(SongForm):
}),
)
+
class ValidationTestCase(TestCase):
def test_readonly_and_editable(self):
View
22 tests/admin_views/admin.py
@@ -58,6 +58,7 @@ class ArticleInline(admin.TabularInline):
})
)
+
class ChapterInline(admin.TabularInline):
model = Chapter
@@ -578,10 +579,12 @@ class AdminOrderedFieldAdmin(admin.ModelAdmin):
ordering = ('order',)
list_display = ('stuff', 'order')
+
class AdminOrderedModelMethodAdmin(admin.ModelAdmin):
ordering = ('order',)
list_display = ('stuff', 'some_order')
+
class AdminOrderedAdminMethodAdmin(admin.ModelAdmin):
def some_admin_order(self, obj):
return obj.order
@@ -589,13 +592,17 @@ def some_admin_order(self, obj):
ordering = ('order',)
list_display = ('stuff', 'some_admin_order')
+
def admin_ordered_callable(obj):
return obj.order
admin_ordered_callable.admin_order_field = 'order'
+
+
class AdminOrderedCallableAdmin(admin.ModelAdmin):
ordering = ('order',)
list_display = ('stuff', admin_ordered_callable)
+
class ReportAdmin(admin.ModelAdmin):
def extra(self, request):
return HttpResponse()
@@ -612,6 +619,7 @@ def get_urls(self):
class CustomTemplateBooleanFieldListFilter(BooleanFieldListFilter):
template = 'custom_filter_template.html'
+
class CustomTemplateFilterColorAdmin(admin.ModelAdmin):
list_filter = (('warm', CustomTemplateBooleanFieldListFilter),)
@@ -628,12 +636,14 @@ class RelatedPrepopulatedInline1(admin.StackedInline):
prepopulated_fields = {'slug1': ['name', 'pubdate'],
'slug2': ['status', 'name']}
+
class RelatedPrepopulatedInline2(admin.TabularInline):
model = RelatedPrepopulated
extra = 1
prepopulated_fields = {'slug1': ['name', 'pubdate'],
'slug2': ['status', 'name']}
+
class MainPrepopulatedAdmin(admin.ModelAdmin):
inlines = [RelatedPrepopulatedInline1, RelatedPrepopulatedInline2]
fieldsets = (
@@ -712,14 +722,17 @@ class FormWithoutHiddenField(forms.ModelForm):
first = forms.CharField()
second = forms.CharField()
+
class FormWithoutVisibleField(forms.ModelForm):
first = forms.CharField(widget=forms.HiddenInput)
second = forms.CharField(widget=forms.HiddenInput)
+
class FormWithVisibleAndHiddenField(forms.ModelForm):
first = forms.CharField(widget=forms.HiddenInput)
second = forms.CharField()
+
class EmptyModelVisibleAdmin(admin.ModelAdmin):
form = FormWithoutHiddenField
fieldsets = (
@@ -728,39 +741,48 @@ class EmptyModelVisibleAdmin(admin.ModelAdmin):
}),
)
+
class EmptyModelHiddenAdmin(admin.ModelAdmin):
form = FormWithoutVisibleField
fieldsets = EmptyModelVisibleAdmin.fieldsets
+
class EmptyModelMixinAdmin(admin.ModelAdmin):
form = FormWithVisibleAndHiddenField
fieldsets = EmptyModelVisibleAdmin.fieldsets
+
class CityInlineAdmin(admin.TabularInline):
model = City
view_on_site = False
+
class StateAdmin(admin.ModelAdmin):
inlines = [CityInlineAdmin]
+
class RestaurantInlineAdmin(admin.TabularInline):
model = Restaurant
view_on_site = True
+
class CityAdmin(admin.ModelAdmin):
inlines = [RestaurantInlineAdmin]
view_on_site = True
+
class WorkerAdmin(admin.ModelAdmin):
def view_on_site(self, obj):
return '/worker/%s/%s/' % (obj.surname, obj.name)
+
class WorkerInlineAdmin(admin.TabularInline):
model = Worker
def view_on_site(self, obj):
return '/worker_inline/%s/%s/' % (obj.surname, obj.name)
+
class RestaurantAdmin(admin.ModelAdmin):
inlines = [WorkerInlineAdmin]
view_on_site = False
View
22 tests/admin_views/models.py
@@ -120,11 +120,13 @@ class Color(models.Model):
def __str__(self):
return self.value
+
# we replicate Color to register with another ModelAdmin
class Color2(Color):
class Meta:
proxy = True
+
@python_2_unicode_compatible
class Thing(models.Model):
title = models.CharField(max_length=20)
@@ -613,10 +615,12 @@ class PrePopulatedPostLargeSlug(models.Model):
published = models.BooleanField(default=False)
slug = models.SlugField(max_length=1000)
+
class AdminOrderedField(models.Model):
order = models.IntegerField()
stuff = models.CharField(max_length=200)
+
class AdminOrderedModelMethod(models.Model):
order = models.IntegerField()
stuff = models.CharField(max_length=200)
@@ -625,14 +629,17 @@ def some_order(self):
return self.order
some_order.admin_order_field = 'order'
+
class AdminOrderedAdminMethod(models.Model):
order = models.IntegerField()
stuff = models.CharField(max_length=200)
+
class AdminOrderedCallable(models.Model):
order = models.IntegerField()
stuff = models.CharField(max_length=200)
+
@python_2_unicode_compatible
class Report(models.Model):
title = models.CharField(max_length=100)
@@ -651,6 +658,7 @@ class MainPrepopulated(models.Model):
slug1 = models.SlugField(blank=True)
slug2 = models.SlugField(blank=True)
+
class RelatedPrepopulated(models.Model):
parent = models.ForeignKey(MainPrepopulated)
name = models.CharField(max_length=75)
@@ -671,6 +679,7 @@ class UnorderedObject(models.Model):
name = models.CharField(max_length=255)
bool = models.BooleanField(default=True)
+
class UndeletableObject(models.Model):
"""
Model whose show_delete in admin change_view has been disabled
@@ -678,30 +687,36 @@ class UndeletableObject(models.Model):
"""
name = models.CharField(max_length=255)
+
class UnchangeableObject(models.Model):
"""
Model whose change_view is disabled in admin
Refs #20640.
"""
+
class UserMessenger(models.Model):
"""
Dummy class for testing message_user functions on ModelAdmin
"""
+
class Simple(models.Model):
"""
Simple model with nothing on it for use in testing
"""
+
class Choice(models.Model):
choice = models.IntegerField(blank=True, null=True,
choices=((1, 'Yes'), (0, 'No'), (None, 'No opinion')))
+
class _Manager(models.Manager):
def get_queryset(self):
return super(_Manager, self).get_queryset().filter(pk__gt=1)
+
class FilteredManager(models.Model):
def __str__(self):
return "PK=%d" % self.pk
@@ -709,26 +724,33 @@ def __str__(self):
pk_gt_1 = _Manager()
objects = models.Manager()
+
class EmptyModelVisible(models.Model):
""" See ticket #11277. """
+
class EmptyModelHidden(models.Model):
""" See ticket #11277. """
+
class EmptyModelMixin(models.Model):
""" See ticket #11277. """
+
class State(models.Model):
name = models.CharField(max_length=100)
+
class City(models.Model):
state = models.ForeignKey(State)
name = models.CharField(max_length=100)
+
class Restaurant(models.Model):
city = models.ForeignKey(City)
name = models.CharField(max_length=100)
+
class Worker(models.Model):
work_at = models.ForeignKey(Restaurant)
name = models.CharField(max_length=50)
View
35 tests/admin_views/tests.py
@@ -84,8 +84,8 @@ def assertContentBefore(self, response, text1, text2, failing_msg=None):
"""
self.assertEqual(response.status_code, 200)
self.assertTrue(response.content.index(force_bytes(text1)) < response.content.index(force_bytes(text2)),
- failing_msg
- )
+ failing_msg)
+
class AdminViewBasicTest(AdminViewBasicTestCase):
def testTrailingSlashRequired(self):
@@ -94,8 +94,8 @@ def testTrailingSlashRequired(self):
"""
response = self.client.get('/test_admin/%s/admin_views/article/add' % self.urlbit)
self.assertRedirects(response,
- '/test_admin/%s/admin_views/article/add/' % self.urlbit, status_code=301
- )
+ '/test_admin/%s/admin_views/article/add/' % self.urlbit,
+ status_code=301)
def testBasicAddGet(self):
"""
@@ -109,8 +109,7 @@ def testAddWithGETArgs(self):
response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit, {'name': 'My Section'})
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'value="My Section"',
- msg_prefix="Couldn't find an input with the right value in the response"
- )
+ msg_prefix="Couldn't find an input with the right value in the response")
def testBasicEditGet(self):
"""
@@ -394,11 +393,9 @@ def testLimitedFilter(self):
response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit)
self.assertEqual(response.status_code, 200)
self.assertContains(response, '<div id="changelist-filter">',
- msg_prefix="Expected filter not found in changelist view"
- )
+ msg_prefix="Expected filter not found in changelist view")
self.assertNotContains(response, '<a href="?color__id__exact=3">Blue</a>',
- msg_prefix="Changelist filter not correctly limited by limit_choices_to"
- )
+ msg_prefix="Changelist filter not correctly limited by limit_choices_to")
def testRelationSpanningFilters(self):
response = self.client.get('/test_admin/%s/admin_views/chapterxtra1/' %
@@ -1557,7 +1554,7 @@ def test_recentactions_without_content_type(self):
response = self.client.get('/test_admin/admin/')
counted_presence_after = response.content.count(force_bytes(should_contain))
self.assertEqual(counted_presence_before - 1,
- counted_presence_after)
+ counted_presence_after)
def test_logentry_get_admin_url(self):
"LogEntry.get_admin_url returns a URL to edit the entry's object or None for non-existent (possibly deleted) models"
@@ -1612,13 +1609,13 @@ def test_shortcut_view_with_escaping(self):
def test_change_view_history_link(self):
"""Object history button link should work and contain the pk value quoted."""
url = reverse('admin:%s_modelwithstringprimarykey_change' %
- ModelWithStringPrimaryKey._meta.app_label,
- args=(quote(self.pk),))
+ ModelWithStringPrimaryKey._meta.app_label,
+ args=(quote(self.pk),))
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
expected_link = reverse('admin:%s_modelwithstringprimarykey_history' %
- ModelWithStringPrimaryKey._meta.app_label,
- args=(quote(self.pk),))
+ ModelWithStringPrimaryKey._meta.app_label,
+ args=(quote(self.pk),))
self.assertContains(response, '<a href="%s" class="historylink"' % expected_link)
@@ -2553,8 +2550,7 @@ def test_model_without_action_still_has_jquery(self):
response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/')
self.assertEqual(response.context["action_form"], None)
self.assertContains(response, 'jquery.min.js',
- msg_prefix="jQuery missing from admin pages for model with no admin actions"
- )
+ msg_prefix="jQuery missing from admin pages for model with no admin actions")
def test_action_column_class(self):
"Tests that the checkbox column class is present in the response"
@@ -3631,8 +3627,7 @@ def test_readonly_get(self):
self.assertContains(response, "InlineMultiline<br />test<br />string")
self.assertContains(response,
- formats.localize(datetime.date.today() - datetime.timedelta(days=7))
- )
+ formats.localize(datetime.date.today() - datetime.timedelta(days=7)))
self.assertContains(response, '<div class="form-row field-coolness">')
self.assertContains(response, '<div class="form-row field-awesomeness_level">')
@@ -3829,7 +3824,7 @@ def test_password_mismatch(self):
adminform = response.context['adminform']
self.assertTrue('password' not in adminform.form.errors)
self.assertEqual(adminform.form.errors['password2'],
- ["The two password fields didn't match."])
+ ["The two password fields didn't match."])
def test_user_fk_popup(self):
"""Quick user addition in a FK popup shouldn't invoke view for further user customization"""
View
1  tests/admin_views/views.py
@@ -1,6 +1,7 @@
from django.contrib.admin.views.decorators import staff_member_required
from django.http import HttpResponse
+
@staff_member_required
def secure_view(request):
return HttpResponse('%s' % request.POST)
View
14 tests/admin_widgets/models.py
@@ -8,6 +8,7 @@
class MyFileField(models.FileField):
pass
+
@python_2_unicode_compatible
class Member(models.Model):
name = models.CharField(max_length=100)
@@ -18,6 +19,7 @@ class Member(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Band(models.Model):
name = models.CharField(max_length=100)
@@ -27,6 +29,7 @@ class Band(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Album(models.Model):
band = models.ForeignKey(Band)
@@ -37,10 +40,12 @@ class Album(models.Model):
def __str__(self):
return self.name
+
class HiddenInventoryManager(models.Manager):
def get_queryset(self):
return super(HiddenInventoryManager, self).get_queryset().filter(hidden=False)
+
@python_2_unicode_compatible
class Inventory(models.Model):
barcode = models.PositiveIntegerField(unique=True)
@@ -55,6 +60,7 @@ class Inventory(models.Model):
def __str__(self):
return self.name
+
class Event(models.Model):
main_band = models.ForeignKey(Band, limit_choices_to=models.Q(pk__gt=0), related_name='events_main_band_at')
supporting_bands = models.ManyToManyField(Band, null=True, blank=True, related_name='events_supporting_band_at')
@@ -64,6 +70,7 @@ class Event(models.Model):
link = models.URLField(blank=True)
min_age = models.IntegerField(blank=True, null=True)
+
@python_2_unicode_compatible
class Car(models.Model):
owner = models.ForeignKey(User)
@@ -73,15 +80,18 @@ class Car(models.Model):
def __str__(self):
return "%s %s" % (self.make, self.model)
+
class CarTire(models.Model):
"""
A single car tire. This to test that a user can only select their own cars.
"""
car = models.ForeignKey(Car)
+
class Honeycomb(models.Model):
location = models.CharField(max_length=20)
+
class Bee(models.Model):
"""
A model with a FK to a model that won't be registered with the admin
@@ -90,6 +100,7 @@ class Bee(models.Model):
"""
honeycomb = models.ForeignKey(Honeycomb)
+
class Individual(models.Model):
"""
A model with a FK to itself. It won't be registered with the admin, so the
@@ -99,9 +110,11 @@ class Individual(models.Model):
name = models.CharField(max_length=20)
parent = models.ForeignKey('self', null=True)
+
class Company(models.Model):
name = models.CharField(max_length=20)
+
class Advisor(models.Model):
"""
A model with a m2m to a model that won't be registered with the admin
@@ -122,6 +135,7 @@ def __str__(self):
class Meta:
ordering = ('name',)
+
@python_2_unicode_compatible
class School(models.Model):
name = models.CharField(max_length=255)
View
16 tests/admin_widgets/tests.py
@@ -30,6 +30,7 @@
'ADMIN_STATIC_PREFIX': "%sadmin/" % settings.STATIC_URL,
}
+
class AdminFormfieldForDBFieldTests(TestCase):
"""
Tests for correct behavior of ModelAdmin.formfield_for_dbfield
@@ -274,6 +275,7 @@ def test_stacked_render(self):
'<select multiple="multiple" name="test" class="selectfilterstacked">\n</select><script type="text/javascript">addEvent(window, "load", function(e) {SelectFilter.init("id_test", "test", 1, "%(ADMIN_STATIC_PREFIX)s"); });</script>\n' % admin_static_prefix()
)
+
class AdminDateWidgetTest(DjangoTestCase):
def test_attrs(self):
"""
@@ -292,6 +294,7 @@ def test_attrs(self):
'<input value="2007-12-01" type="text" class="myDateField" name="test" size="20" />',
)
+
class AdminTimeWidgetTest(DjangoTestCase):
def test_attrs(self):
"""
@@ -310,6 +313,7 @@ def test_attrs(self):
'<input value="09:30:00" type="text" class="myTimeField" name="test" size="20" />',
)
+
class AdminSplitDateTimeWidgetTest(DjangoTestCase):
def test_render(self):
w = widgets.AdminSplitDateTime()
@@ -500,6 +504,7 @@ def test_m2m_related_model_not_in_admin(self):
'<input type="text" name="company_widget2" value="%(c1pk)s" />' % {'c1pk': c1.pk}
)
+
class RelatedFieldWidgetWrapperTests(DjangoTestCase):
def test_no_can_add_related(self):
rel = models.Individual._meta.get_field('parent').rel
@@ -636,6 +641,7 @@ def test_calendar_no_selected_class(self):
class DateTimePickerSeleniumChromeTests(DateTimePickerSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
+
class DateTimePickerSeleniumIETests(DateTimePickerSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@@ -701,9 +707,11 @@ def test_date_time_picker_shortcuts(self):
self.assertGreater(member.birthdate, now - error_margin)
self.assertLess(member.birthdate, now + error_margin)
+
class DateTimePickerShortcutsSeleniumChromeTests(DateTimePickerShortcutsSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
+
class DateTimePickerShortcutsSeleniumIETests(DateTimePickerShortcutsSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@@ -729,7 +737,7 @@ def setUp(self):
super(HorizontalVerticalFilterSeleniumFirefoxTests, self).setUp()
def assertActiveButtons(self, mode, field_name, choose, remove,
- choose_all=None, remove_all=None):
+ choose_all=None, remove_all=None):
choose_link = '#id_%s_add_link' % field_name
choose_all_link = '#id_%s_add_all_link' % field_name
remove_link = '#id_%s_remove_link' % field_name
@@ -943,9 +951,11 @@ def test_filter(self):
self.assertEqual(list(self.school.alumni.all()),
[self.jason, self.peter])
+
class HorizontalVerticalFilterSeleniumChromeTests(HorizontalVerticalFilterSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
+
class HorizontalVerticalFilterSeleniumIETests(HorizontalVerticalFilterSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@@ -1040,9 +1050,11 @@ def test_many_to_many(self):
self.selenium.find_element_by_id('id_supporting_bands').get_attribute('value'),
'42,98')
+
class AdminRawIdWidgetSeleniumChromeTests(AdminRawIdWidgetSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
+
class AdminRawIdWidgetSeleniumIETests(AdminRawIdWidgetSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@@ -1087,8 +1099,10 @@ def test_foreign_key_using_to_field(self):
self.assertEqual(len(profiles), 1)
self.assertEqual(profiles[0].user.username, username_value)
+
class RelatedFieldWidgetSeleniumChromeTests(RelatedFieldWidgetSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
+
class RelatedFieldWidgetSeleniumIETests(RelatedFieldWidgetSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
View
3  tests/aggregation/models.py
@@ -12,6 +12,7 @@ class Author(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Publisher(models.Model):
name = models.CharField(max_length=255)
@@ -20,6 +21,7 @@ class Publisher(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Book(models.Model):
isbn = models.CharField(max_length=9)
@@ -35,6 +37,7 @@ class Book(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Store(models.Model):
name = models.CharField(max_length=255)
View
6 tests/aggregation_regress/models.py
@@ -61,6 +61,7 @@ class Store(models.Model):
def __str__(self):
return self.name
+
class Entries(models.Model):
EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
Entry = models.CharField(unique=True, max_length=50)
@@ -69,7 +70,7 @@ class Entries(models.Model):
class Clues(models.Model):
ID = models.AutoField(primary_key=True)
- EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column = 'Entry ID')
+ EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column='Entry ID')
Clue = models.CharField(max_length=150)
@@ -88,13 +89,16 @@ class HardbackBook(Book):
def __str__(self):
return "%s (hardback): %s" % (self.name, self.weight)
+
# Models for ticket #21150
class Alfa(models.Model):
name = models.CharField(max_length=10, null=True)
+
class Bravo(models.Model):
pass
+
class Charlie(models.Model):
alfa = models.ForeignKey(Alfa, null=True)
bravo = models.ForeignKey(Bravo, null=True)
View
18 tests/backends/tests.py
@@ -432,6 +432,7 @@ def test_sqlite_parameter_escaping(self):
# response should be an non-zero integer
self.assertTrue(int(response))
+
@override_settings(DEBUG=True)
class EscapingChecksDebug(EscapingChecks):
pass
@@ -509,12 +510,12 @@ def create_squares(self, args, paramstyle, multiple):
def test_cursor_executemany(self):
#4896: Test cursor.executemany
- args = [(i, i**2) for i in range(-5, 6)]
+ args = [(i, i ** 2) for i in range(-5, 6)]
self.create_squares_with_executemany(args)
self.assertEqual(models.Square.objects.count(), 11)
for i in range(-5, 6):
square = models.Square.objects.get(root=i)
- self.assertEqual(square.square, i**2)
+ self.assertEqual(square.square, i ** 2)
def test_cursor_executemany_with_empty_params_list(self):
#4765: executemany with params=[] does nothing
@@ -524,11 +525,11 @@ def test_cursor_executemany_with_empty_params_list(self):
def test_cursor_executemany_with_iterator(self):
#10320: executemany accepts iterators
- args = iter((i, i**2) for i in range(-3, 2))
+ args = iter((i, i ** 2) for i in range(-3, 2))
self.create_squares_with_executemany(args)
self.assertEqual(models.Square.objects.count(), 5)
- args = iter((i, i**2) for i in range(3, 7))
+ args = iter((i, i ** 2) for i in range(3, 7))
with override_settings(DEBUG=True):
# same test for DebugCursorWrapper
self.create_squares_with_executemany(args)
@@ -544,20 +545,20 @@ def test_cursor_execute_with_pyformat(self):
@skipUnlessDBFeature('supports_paramstyle_pyformat')
def test_cursor_executemany_with_pyformat(self):
#10070: Support pyformat style passing of paramters
- args = [{'root': i, 'square': i**2} for i in range(-5, 6)]
+ args = [{'root': i, 'square': i ** 2} for i in range(-5, 6)]
self.create_squares(args, 'pyformat', multiple=True)
self.assertEqual(models.Square.objects.count(), 11)
for i in range(-5, 6):
square = models.Square.objects.get(root=i)
- self.assertEqual(square.square, i**2)
+ self.assertEqual(square.square, i ** 2)
@skipUnlessDBFeature('supports_paramstyle_pyformat')
def test_cursor_executemany_with_pyformat_iterator(self):
- args = iter({'root': i, 'square': i**2} for i in range(-3, 2))
+ args = iter({'root': i, 'square': i ** 2} for i in range(-3, 2))
self.create_squares(args, 'pyformat', multiple=True)
self.assertEqual(models.Square.objects.count(), 5)
- args = iter({'root': i, 'square': i**2} for i in range(3, 7))
+ args = iter({'root': i, 'square': i ** 2} for i in range(3, 7))
with override_settings(DEBUG=True):
# same test for DebugCursorWrapper
self.create_squares(args, 'pyformat', multiple=True)
@@ -987,6 +988,7 @@ def equal(value, max_d, places, result):
equal('0.1234567890', 12, 0,
'0')
+
@unittest.skipUnless(
connection.vendor == 'postgresql',
"This test applies only to PostgreSQL")
View
2  tests/basic/models.py
@@ -19,11 +19,13 @@ class Meta:
def __str__(self):
return self.headline
+
class ArticleSelectOnSave(Article):
class Meta:
proxy = True
select_on_save = True
+
@python_2_unicode_compatible
class SelfRef(models.Model):
selfref = models.ForeignKey('self', null=True, blank=True,
View
48 tests/basic/tests.py
@@ -87,7 +87,8 @@ def test_lookup(self):
# Django raises an Article.DoesNotExist exception for get() if the
# parameters don't match any object.
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
ObjectDoesNotExist,
"Article matching query does not exist.",
Article.objects.get,
@@ -102,7 +103,8 @@ def test_lookup(self):
pub_date__month=8,
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
ObjectDoesNotExist,
"Article matching query does not exist.",
Article.objects.get,
@@ -135,21 +137,24 @@ def test_lookup(self):
# Django raises an Article.MultipleObjectsReturned exception if the
# lookup matches more than one object
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned 2!",
Article.objects.get,
headline__startswith='Area',
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned 2!",
Article.objects.get,
pub_date__year=2005,
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned 2!",
Article.objects.get,
@@ -165,14 +170,16 @@ def test_multiple_objects_max_num_fetched(self):
Article(headline='Area %s' % i, pub_date=datetime(2005, 7, 28))
for i in range(MAX_GET_RESULTS)
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned %d!" % MAX_GET_RESULTS,
Article.objects.get,
headline__startswith='Area',
)
Article.objects.create(headline='Area %s' % MAX_GET_RESULTS, pub_date=datetime(2005, 7, 28))
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
MultipleObjectsReturned,
"get\(\) returned more than one Article -- it returned more than %d!" % MAX_GET_RESULTS,
Article.objects.get,
@@ -219,7 +226,8 @@ def test_object_creation(self):
self.assertEqual(a4.headline, 'Fourth article')
# Don't use invalid keyword arguments.
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
TypeError,
"'foo' is an invalid keyword argument for this function",
Article,
@@ -315,7 +323,8 @@ def test_object_creation(self):
Article.objects.dates,
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
FieldDoesNotExist,
"Article has no field named 'invalid_field'",
Article.objects.dates,
@@ -323,7 +332,8 @@ def test_object_creation(self):
"year",
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
AssertionError,
"'kind' must be one of 'year', 'month' or 'day'.",
Article.objects.dates,
@@ -331,7 +341,8 @@ def test_object_creation(self):
"bad_kind",
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
AssertionError,
"'order' must be either 'ASC' or 'DESC'.",
Article.objects.dates,
@@ -419,14 +430,16 @@ def test_object_creation(self):
"<Article: Updated article 8>"])
# Also, once you have sliced you can't filter, re-order or combine
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
AssertionError,
"Cannot filter a query once a slice has been taken.",
Article.objects.all()[0:5].filter,
id=a.id,
)
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
AssertionError,
"Cannot reorder a query once a slice has been taken.",
Article.objects.all()[0:5].order_by,
@@ -461,7 +474,8 @@ def test_object_creation(self):
# An Article instance doesn't have access to the "objects" attribute.
# That's only available on the class.
- six.assertRaisesRegex(self,
+ six.assertRaisesRegex(
+ self,
AttributeError,
"Manager isn't accessible via Article instances",
getattr,
@@ -605,8 +619,8 @@ def test_extra_method_select_argument_with_dashes_and_values(self):
)
dicts = Article.objects.filter(
- pub_date__year=2008).extra(select={'dashed-value': '1'}
- ).values('headline', 'dashed-value')
+ pub_date__year=2008).extra(
+ select={'dashed-value': '1'}).values('headline', 'dashed-value')
self.assertEqual([sorted(d.items()) for d in dicts],
[[('dashed-value', 1), ('headline', 'Article 11')], [('dashed-value', 1), ('headline', 'Article 12')]])
@@ -723,6 +737,7 @@ def test_hash(self):
# hash)
hash(Article())
+
class ConcurrentSaveTests(TransactionTestCase):
available_apps = ['basic']
@@ -808,6 +823,7 @@ def test_manager_methods(self):
sorted(self.QUERYSET_PROXY_METHODS),
)
+
class SelectOnSaveTests(TestCase):
def test_select_on_save(self):
a1 = Article.objects.create(pub_date=datetime.now())
View
2  tests/bug639/models.py
@@ -8,6 +8,7 @@
temp_storage_dir = tempfile.mkdtemp()
temp_storage = FileSystemStorage(temp_storage_dir)
+
class Photo(models.Model):
title = models.CharField(max_length=30)
image = models.FileField(storage=temp_storage, upload_to='tests')
@@ -22,6 +23,7 @@ def save(self, force_insert=False, force_update=False):
super(Photo, self).save(force_insert, force_update)
self._savecount += 1
+
class PhotoForm(ModelForm):
class Meta:
model = Photo
View
5 tests/bulk_create/models.py
@@ -5,21 +5,26 @@ class Country(models.Model):
name = models.CharField(max_length=255)
iso_two_letter = models.CharField(max_length=2)
+
class Place(models.Model):
name = models.CharField(max_length=100)
class Meta:
abstract = True
+
class Restaurant(Place):
pass
+
class Pizzeria(Restaurant):
pass
+
class State(models.Model):
two_letter_code = models.CharField(max_length=2, primary_key=True)
+
class TwoFields(models.Model):
f1 = models.IntegerField(unique=True)
f2 = models.IntegerField(unique=True)
View
1  tests/cache/closeable_cache.py
@@ -7,5 +7,6 @@ class CloseHookMixin(object):
def close(self, **kwargs):
self.closed = True
+
class CacheClass(CloseHookMixin, LocMemCache):
pass
View
1  tests/cache/liberal_backend.py
@@ -5,5 +5,6 @@ class LiberalKeyValidationMixin(object):
def validate_key(self, key):
pass
+
class CacheClass(LiberalKeyValidationMixin, LocMemCache):
pass
View
1  tests/cache/models.py
@@ -7,6 +7,7 @@ def expensive_calculation():
expensive_calculation.num_runs += 1
return timezone.now()
+
class Poll(models.Model):
question = models.CharField(max_length=200)
answer = models.CharField(max_length=200)
View
6 tests/cache/tests.py
@@ -40,10 +40,12 @@
from .models import Poll, expensive_calculation
+
# functions/classes for complex data type tests
def f():
return 42
+
class C:
def m(n):
return 24
@@ -823,6 +825,7 @@ def test_cache_write_unpickable_object(self):
self.assertEqual(get_cache_data.content, content.encode('utf-8'))
self.assertEqual(get_cache_data.cookies, response.cookies)
+
def custom_key_func(key, key_prefix, version):
"A customized cache key function"
return 'CUSTOM-' + '-'.join([key_prefix, str(version), key])
@@ -1004,6 +1007,7 @@ def test_incr_decr_timeout(self):
self.cache.decr(key)
self.assertEqual(expire, self.cache._expire_info[_key])
+
# memcached backend isn't guaranteed to be available.
# To check the memcached backend, the test settings file will
# need to contain at least one cache backend setting that points at
@@ -1581,6 +1585,7 @@ def test_middleware_doesnt_cache_streaming_response(self):
get_cache_data = FetchFromCacheMiddleware().process_request(request)
self.assertIsNone(get_cache_data)
+
@override_settings(
CACHES={
'default': {