diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2015-03-17 07:42:53 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-03-21 08:16:28 -0400 |
| commit | 966a29c2b83fed2fc7c2b5b09de80cbebc94ac74 (patch) | |
| tree | 05c6511b0c821b3be9731264acba1d32b31967e3 /tests/invalid_models_tests | |
| parent | e304e1344857facd6356af9def3a7c9a78c528f9 (diff) | |
Fixed #24479 -- Added system check to prevent both ordering and order_wrt.
Diffstat (limited to 'tests/invalid_models_tests')
| -rw-r--r-- | tests/invalid_models_tests/test_models.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/invalid_models_tests/test_models.py b/tests/invalid_models_tests/test_models.py index 87a099f3a9..3bc6856480 100644 --- a/tests/invalid_models_tests/test_models.py +++ b/tests/invalid_models_tests/test_models.py @@ -566,6 +566,50 @@ class OtherModelTests(IsolatedModelsTestCase): ] self.assertEqual(errors, expected) + def test_just_ordering_no_errors(self): + class Model(models.Model): + order = models.PositiveIntegerField() + + class Meta: + ordering = ['order'] + + self.assertEquals(Model.check(), []) + + def test_just_order_with_respect_to_no_errors(self): + class Question(models.Model): + pass + + class Answer(models.Model): + question = models.ForeignKey(Question) + + class Meta: + order_with_respect_to = 'question' + + self.assertEquals(Answer.check(), []) + + def test_ordering_with_order_with_respect_to(self): + class Question(models.Model): + pass + + class Answer(models.Model): + question = models.ForeignKey(Question) + order = models.IntegerField() + + class Meta: + order_with_respect_to = 'question' + ordering = ['order'] + + errors = Answer.check() + expected = [ + Error( + "'ordering' and 'order_with_respect_to' cannot be used together.", + hint=None, + obj=Answer, + id='models.E021', + ), + ] + self.assertEqual(errors, expected) + def test_non_valid(self): class RelationModel(models.Model): pass |
