summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-12-02 13:57:27 -0500
committerTim Graham <timograham@gmail.com>2016-12-02 14:46:52 -0500
commit7ed456063b89aa39b72b89067f05c56ba6f9c487 (patch)
tree3f9c41cc3c71871394215568a797aecd5fb533ad /tests
parent6abd6c598ea23e0a962c87b0075aa2f79f9ead36 (diff)
Updated LimitChoicesToTests to use setUpTestData and cosmetic edits.
Diffstat (limited to 'tests')
-rw-r--r--tests/model_forms/tests.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index f4216ca51b..84aa04b40f 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -2813,43 +2813,42 @@ class StumpJokeWithCustomFieldForm(forms.ModelForm):
class Meta:
model = StumpJoke
- fields = () # We don't need any fields from the model
+ fields = ()
-class LimitChoicesToTest(TestCase):
+class LimitChoicesToTests(TestCase):
"""
Tests the functionality of ``limit_choices_to``.
"""
- def setUp(self):
- self.threepwood = Character.objects.create(
+ @classmethod
+ def setUpTestData(cls):
+ cls.threepwood = Character.objects.create(
username='threepwood',
last_action=datetime.datetime.today() + datetime.timedelta(days=1),
)
- self.marley = Character.objects.create(
+ cls.marley = Character.objects.create(
username='marley',
last_action=datetime.datetime.today() - datetime.timedelta(days=1),
)
def test_limit_choices_to_callable_for_fk_rel(self):
"""
- A ForeignKey relation can use ``limit_choices_to`` as a callable, re #2554.
+ A ForeignKey can use limit_choices_to as a callable (#2554).
"""
stumpjokeform = StumpJokeForm()
- self.assertIn(self.threepwood, stumpjokeform.fields['most_recently_fooled'].queryset)
- self.assertNotIn(self.marley, stumpjokeform.fields['most_recently_fooled'].queryset)
+ self.assertSequenceEqual(stumpjokeform.fields['most_recently_fooled'].queryset, [self.threepwood])
def test_limit_choices_to_callable_for_m2m_rel(self):
"""
- A ManyToMany relation can use ``limit_choices_to`` as a callable, re #2554.
+ A ManyToManyField can use limit_choices_to as a callable (#2554).
"""
stumpjokeform = StumpJokeForm()
- self.assertIn(self.threepwood, stumpjokeform.fields['has_fooled_today'].queryset)
- self.assertNotIn(self.marley, stumpjokeform.fields['has_fooled_today'].queryset)
+ self.assertSequenceEqual(stumpjokeform.fields['most_recently_fooled'].queryset, [self.threepwood])
def test_custom_field_with_queryset_but_no_limit_choices_to(self):
"""
- Regression test for #23795: Make sure a custom field with a `queryset`
- attribute but no `limit_choices_to` still works.
+ A custom field with a `queryset` attribute but no `limit_choices_to`
+ works (#23795).
"""
f = StumpJokeWithCustomFieldForm()
self.assertEqual(f.fields['custom'].queryset, 42)