diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-09-20 17:51:25 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-09-21 22:20:42 +0200 |
| commit | e542e81b39e8610b70cf1d68f95ece0279028765 (patch) | |
| tree | 92da80cf497dbab79d05d5ec050927bfe107c153 /tests | |
| parent | 2409a4241a07bcdb1be4f3c99bf1aacc87189ebf (diff) | |
Renamed descriptor classes for related objects.
The old names were downright confusing. Some seemed to mean the opposite
of what the class actually did.
The new names follow a consistent nomenclature:
(Forward|Reverse)(ManyToOne|OneToOne|ManyToMany)Descriptor.
I mentioned combinations that do not exist in the docstring in order to
help people who would search for them in the code base.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/foreign_object/models/article.py | 5 | ||||
| -rw-r--r-- | tests/foreign_object/models/empty_join.py | 10 | ||||
| -rw-r--r-- | tests/generic_relations/tests.py | 2 | ||||
| -rw-r--r-- | tests/many_to_many/tests.py | 4 | ||||
| -rw-r--r-- | tests/many_to_one_null/tests.py | 2 | ||||
| -rw-r--r-- | tests/prefetch_related/tests.py | 4 | ||||
| -rw-r--r-- | tests/schema/fields.py | 4 |
7 files changed, 15 insertions, 16 deletions
diff --git a/tests/foreign_object/models/article.py b/tests/foreign_object/models/article.py index f9e6f1fca4..f0c2f3fbac 100644 --- a/tests/foreign_object/models/article.py +++ b/tests/foreign_object/models/article.py @@ -1,11 +1,10 @@ from django.db import models -from django.db.models.fields.related import \ - ReverseSingleRelatedObjectDescriptor +from django.db.models.fields.related import ForwardManyToOneDescriptor from django.utils.encoding import python_2_unicode_compatible from django.utils.translation import get_language -class ArticleTranslationDescriptor(ReverseSingleRelatedObjectDescriptor): +class ArticleTranslationDescriptor(ForwardManyToOneDescriptor): """ The set of articletranslation should not set any local fields. """ diff --git a/tests/foreign_object/models/empty_join.py b/tests/foreign_object/models/empty_join.py index 3bf121bf39..b8b05ea1c2 100644 --- a/tests/foreign_object/models/empty_join.py +++ b/tests/foreign_object/models/empty_join.py @@ -1,6 +1,6 @@ from django.db import models from django.db.models.fields.related import ( - ForeignObjectRel, ForeignRelatedObjectsDescriptor, + ForeignObjectRel, ReverseManyToOneDescriptor, ) from django.db.models.lookups import StartsWith from django.db.models.query_utils import PathInfo @@ -10,7 +10,7 @@ from django.utils.encoding import python_2_unicode_compatible class CustomForeignObjectRel(ForeignObjectRel): """ Define some extra Field methods so this Rel acts more like a Field, which - lets us use ForeignRelatedObjectsDescriptor in both directions. + lets us use ReverseManyToOneDescriptor in both directions. """ @property def foreign_related_fields(self): @@ -24,7 +24,7 @@ class StartsWithRelation(models.ForeignObject): """ A ForeignObject that uses StartsWith operator in its joins instead of the default equality operator. This is logically a many-to-many relation - and creates a ForeignRelatedObjectsDescriptor in both directions. + and creates a ReverseManyToOneDescriptor in both directions. """ auto_created = False @@ -42,7 +42,7 @@ class StartsWithRelation(models.ForeignObject): @property def field(self): """ - Makes ForeignRelatedObjectsDescriptor work in both directions. + Makes ReverseManyToOneDescriptor work in both directions. """ return self.remote_field @@ -66,7 +66,7 @@ class StartsWithRelation(models.ForeignObject): def contribute_to_class(self, cls, name, virtual_only=False): super(StartsWithRelation, self).contribute_to_class(cls, name, virtual_only) - setattr(cls, self.name, ForeignRelatedObjectsDescriptor(self)) + setattr(cls, self.name, ReverseManyToOneDescriptor(self)) class BrokenContainsRelation(StartsWithRelation): diff --git a/tests/generic_relations/tests.py b/tests/generic_relations/tests.py index e9bd748329..72d4d492c6 100644 --- a/tests/generic_relations/tests.py +++ b/tests/generic_relations/tests.py @@ -329,7 +329,7 @@ class GenericRelationsTests(TestCase): def test_assign_with_queryset(self): # Ensure that querysets used in reverse GFK assignments are pre-evaluated # so their value isn't affected by the clearing operation in - # ManyRelatedObjectsDescriptor.__set__. Refs #19816. + # ManyToManyDescriptor.__set__. Refs #19816. bacon = Vegetable.objects.create(name="Bacon", is_yucky=False) bacon.tags.create(tag="fatty") bacon.tags.create(tag="salty") diff --git a/tests/many_to_many/tests.py b/tests/many_to_many/tests.py index ffe5e879ca..be18dcedb0 100644 --- a/tests/many_to_many/tests.py +++ b/tests/many_to_many/tests.py @@ -412,7 +412,7 @@ class ManyToManyTests(TestCase): def test_forward_assign_with_queryset(self): # Ensure that querysets used in m2m assignments are pre-evaluated # so their value isn't affected by the clearing operation in - # ManyRelatedObjectsDescriptor.__set__. Refs #19816. + # ManyToManyDescriptor.__set__. Refs #19816. self.a1.publications = [self.p1, self.p2] qs = self.a1.publications.filter(title='The Python Journal') @@ -424,7 +424,7 @@ class ManyToManyTests(TestCase): def test_reverse_assign_with_queryset(self): # Ensure that querysets used in M2M assignments are pre-evaluated # so their value isn't affected by the clearing operation in - # ManyRelatedObjectsDescriptor.__set__. Refs #19816. + # ManyToManyDescriptor.__set__. Refs #19816. self.p1.article_set = [self.a1, self.a2] qs = self.p1.article_set.filter(headline='Django lets you build Web apps easily') diff --git a/tests/many_to_one_null/tests.py b/tests/many_to_one_null/tests.py index 06f756e35b..ae5e21e1cf 100644 --- a/tests/many_to_one_null/tests.py +++ b/tests/many_to_one_null/tests.py @@ -106,7 +106,7 @@ class ManyToOneNullTests(TestCase): def test_assign_with_queryset(self): # Ensure that querysets used in reverse FK assignments are pre-evaluated # so their value isn't affected by the clearing operation in - # ForeignRelatedObjectsDescriptor.__set__. Refs #19816. + # ReverseManyToOneDescriptor.__set__. Refs #19816. self.r2.article_set = [self.a2, self.a3] qs = self.r2.article_set.filter(headline="Second") diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py index 0a864e93ae..7aed238bc0 100644 --- a/tests/prefetch_related/tests.py +++ b/tests/prefetch_related/tests.py @@ -595,7 +595,7 @@ class CustomPrefetchTests(TestCase): self.assertEqual(lst2[0].houses_lst[0].rooms_lst[0].main_room_of, self.house1) self.assertEqual(len(lst2[1].houses_lst), 0) - # Test ReverseSingleRelatedObjectDescriptor. + # Test ForwardManyToOneDescriptor. houses = House.objects.select_related('owner') with self.assertNumQueries(6): rooms = Room.objects.all().prefetch_related('house') @@ -624,7 +624,7 @@ class CustomPrefetchTests(TestCase): with self.assertNumQueries(3): getattr(rooms.first().house, 'address') - # Test SingleRelatedObjectDescriptor. + # Test ReverseOneToOneDescriptor. houses = House.objects.select_related('owner') with self.assertNumQueries(6): rooms = Room.objects.all().prefetch_related('main_room_of') diff --git a/tests/schema/fields.py b/tests/schema/fields.py index 8499477d65..30357b1061 100644 --- a/tests/schema/fields.py +++ b/tests/schema/fields.py @@ -1,6 +1,6 @@ from django.db import models from django.db.models.fields.related import ( - RECURSIVE_RELATIONSHIP_CONSTANT, ManyRelatedObjectsDescriptor, + RECURSIVE_RELATIONSHIP_CONSTANT, ManyToManyDescriptor, ManyToManyField, ManyToManyRel, RelatedField, create_many_to_many_intermediary_model, ) @@ -42,7 +42,7 @@ class CustomManyToManyField(RelatedField): super(CustomManyToManyField, self).contribute_to_class(cls, name, **kwargs) if not self.remote_field.through and not cls._meta.abstract and not cls._meta.swapped: self.remote_field.through = create_many_to_many_intermediary_model(self, cls) - setattr(cls, self.name, ManyRelatedObjectsDescriptor(self.remote_field)) + setattr(cls, self.name, ManyToManyDescriptor(self.remote_field)) self.m2m_db_table = curry(self._get_m2m_db_table, cls._meta) def get_internal_type(self): |
