diff options
| author | Simon Charette <charette.s@gmail.com> | 2012-05-07 20:08:20 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2012-05-07 20:08:20 +0300 |
| commit | 5cbfb48b92cb26a335f9c8c0f79d3390290103e2 (patch) | |
| tree | 197836116e12332cc43b62dce75af54878cb70cb /tests/modeltests/basic | |
| parent | 1aae1cba99b0f8232527742d64b120e4d902c68d (diff) | |
Made model fields comparable to other objects
Fixed #17851 -- Added __lt__ and @total_ordering to models.Field,
made sure these work correctly on other objects than Field, too.
Diffstat (limited to 'tests/modeltests/basic')
| -rw-r--r-- | tests/modeltests/basic/tests.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/modeltests/basic/tests.py b/tests/modeltests/basic/tests.py index fc1f593c13..84e20487c5 100644 --- a/tests/modeltests/basic/tests.py +++ b/tests/modeltests/basic/tests.py @@ -3,7 +3,7 @@ from __future__ import absolute_import from datetime import datetime from django.core.exceptions import ObjectDoesNotExist -from django.db.models.fields import FieldDoesNotExist +from django.db.models.fields import Field, FieldDoesNotExist from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from django.utils.translation import ugettext_lazy @@ -520,6 +520,22 @@ class ModelTest(TestCase): s = set([a10, a11, a12]) self.assertTrue(Article.objects.get(headline='Article 11') in s) + def test_field_ordering(self): + """ + Field instances have a `__lt__` comparison function to define an + ordering based on their creation. Prior to #17851 this ordering + comparison relied on the now unsupported `__cmp__` and was assuming + compared objects were both Field instances raising `AttributeError` + when it should have returned `NotImplemented`. + """ + f1 = Field() + f2 = Field(auto_created=True) + f3 = Field() + self.assertTrue(f2 < f1) + self.assertTrue(f3 > f1) + self.assertFalse(f1 == None) + self.assertFalse(f2 in (None, 1, '')) + def test_extra_method_select_argument_with_dashes_and_values(self): # The 'select' argument to extra() supports names with dashes in # them, as long as you use values(). |
