From 2a0a00e1ae12e80ef088f25e2ae336f58031e028 Mon Sep 17 00:00:00 2001 From: Nicolae Godina Date: Wed, 24 Apr 2019 20:09:10 +0300 Subject: [PATCH 01/10] add DateField mapping --- rest_framework_mongoengine/serializers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rest_framework_mongoengine/serializers.py b/rest_framework_mongoengine/serializers.py index 0a8fa4a..f445c65 100644 --- a/rest_framework_mongoengine/serializers.py +++ b/rest_framework_mongoengine/serializers.py @@ -87,6 +87,7 @@ class DocumentSerializer(serializers.ModelSerializer): * ``UUIDField`` * ``GeoPointField`` * ``GeoJsonBaseField`` (all those fields) + * ``DateField`` Compound fields: ``ListField`` and ``DictField`` are mapped to corresponding DRF fields, with respect to nested field specification. @@ -115,6 +116,7 @@ class DocumentSerializer(serializers.ModelSerializer): me_fields.DecimalField: drf_fields.DecimalField, me_fields.BooleanField: drf_fields.BooleanField, me_fields.DateTimeField: drf_fields.DateTimeField, + me_fields.DateField: drf_fields.DateField, me_fields.ComplexDateTimeField: drf_fields.DateTimeField, me_fields.ObjectIdField: drfm_fields.ObjectIdField, me_fields.FileField: drfm_fields.FileField, From f666f7b6dc3422f78c2b0c12a56440ce3973ca30 Mon Sep 17 00:00:00 2001 From: Nicolae Godina Date: Wed, 24 Apr 2019 20:10:33 +0300 Subject: [PATCH 02/10] up version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a4bad6b..11e935d 100755 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def get_package_data(package): setup( name='django-rest-framework-mongoengine', - version='3.3.1', + version='3.3.2', description='MongoEngine support for Django Rest Framework.', packages=get_packages('rest_framework_mongoengine'), package_data=get_package_data('rest_framework_mongoengine'), From cf10d57fdef1ced753261f8732221fd945c579ae Mon Sep 17 00:00:00 2001 From: nixon Date: Tue, 18 Jun 2019 16:58:33 +0300 Subject: [PATCH 03/10] Update setup.py revert version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 11e935d..a4bad6b 100755 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def get_package_data(package): setup( name='django-rest-framework-mongoengine', - version='3.3.2', + version='3.3.1', description='MongoEngine support for Django Rest Framework.', packages=get_packages('rest_framework_mongoengine'), package_data=get_package_data('rest_framework_mongoengine'), From 45ae24afef41665948cc716a5ce9f380dad1d22b Mon Sep 17 00:00:00 2001 From: Nicolae Godina Date: Thu, 19 Sep 2019 23:47:54 +0300 Subject: [PATCH 04/10] Remove python 2.7 support, old django versions and old me versions --- .gitignore | 1 + requirements/requirements-testing.txt | 2 +- rest_framework_mongoengine/repr.py | 3 +-- rest_framework_mongoengine/serializers.py | 3 +-- rest_framework_mongoengine/validators.py | 5 ++--- tests/test_basic.py | 17 +++++++------- tests/test_compound.py | 7 +++--- tests/test_dumb.py | 3 +-- tests/test_dynamic.py | 9 ++++---- tests/test_embedded.py | 27 +++++++++++------------ tests/test_files.py | 3 +-- tests/test_geo.py | 3 +-- tests/test_nested_customization.py | 19 ++++++++-------- tests/test_reference.py | 16 +++++++------- tox.ini | 18 +++++++-------- 15 files changed, 63 insertions(+), 73 deletions(-) diff --git a/.gitignore b/.gitignore index 35ed5f4..b6ba0ca 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ __pycache__/ # Distribution / packaging .Python .env/ +venv/ bin/ build/ develop-eggs/ diff --git a/requirements/requirements-testing.txt b/requirements/requirements-testing.txt index a6d1346..f73aa2d 100644 --- a/requirements/requirements-testing.txt +++ b/requirements/requirements-testing.txt @@ -3,4 +3,4 @@ pytest-cov pytest-django mock six - +pytz \ No newline at end of file diff --git a/rest_framework_mongoengine/repr.py b/rest_framework_mongoengine/repr.py index 9455f17..b7a2026 100644 --- a/rest_framework_mongoengine/repr.py +++ b/rest_framework_mongoengine/repr.py @@ -11,7 +11,6 @@ from mongoengine.base import BaseDocument from mongoengine.fields import BaseField from mongoengine.queryset import QuerySet -from rest_framework.compat import unicode_repr from rest_framework.fields import Field from rest_framework_mongoengine.fields import DictField @@ -55,7 +54,7 @@ def smart_repr(value): if isinstance(value, Field): return field_repr(value) - value = unicode_repr(value) + value = repr(value) # Representations like u'help text' # should simply be presented as 'help text' diff --git a/rest_framework_mongoengine/serializers.py b/rest_framework_mongoengine/serializers.py index f445c65..253fc8b 100644 --- a/rest_framework_mongoengine/serializers.py +++ b/rest_framework_mongoengine/serializers.py @@ -7,7 +7,6 @@ from mongoengine.errors import ValidationError as me_ValidationError from rest_framework import fields as drf_fields from rest_framework import serializers -from rest_framework.compat import unicode_to_repr from rest_framework.serializers import ALL_FIELDS from rest_framework.utils.field_mapping import ClassLookupDict @@ -798,7 +797,7 @@ def get_unique_for_date_validators(self): return [] def __repr__(self): - return unicode_to_repr(serializer_repr(self, indent=1)) + return repr(serializer_repr(self, indent=1)) class EmbeddedDocumentSerializer(DocumentSerializer): diff --git a/rest_framework_mongoengine/validators.py b/rest_framework_mongoengine/validators.py index e76883a..9a4125d 100644 --- a/rest_framework_mongoengine/validators.py +++ b/rest_framework_mongoengine/validators.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals from rest_framework import validators -from rest_framework.compat import unicode_to_repr from rest_framework.exceptions import ValidationError from rest_framework.fields import SkipField @@ -28,7 +27,7 @@ def __call__(self, value): raise ValidationError(self.message.format()) def __repr__(self): - return unicode_to_repr('<%s(queryset=%s)>' % ( + return repr('<%s(queryset=%s)>' % ( self.__class__.__name__, smart_repr(self.queryset) )) @@ -56,7 +55,7 @@ def __call__(self, attrs): raise ValidationError(self.message.format(field_names=field_names)) def __repr__(self): - return unicode_to_repr('<%s(queryset=%s, fields=%s)>' % ( + return repr('<%s(queryset=%s, fields=%s)>' % ( self.__class__.__name__, smart_repr(self.queryset), smart_repr(self.fields) diff --git a/tests/test_basic.py b/tests/test_basic.py index 1f5e411..7847e4b 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -18,7 +18,6 @@ from django.test import TestCase from mongoengine import Document, fields from rest_framework import serializers -from rest_framework.compat import unicode_repr from rest_framework_mongoengine.serializers import DocumentSerializer @@ -128,7 +127,7 @@ class Meta: custom_field = DocumentField(model_field=, required=False) """ % regex_repr) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_meta_fields(self): """ @@ -145,7 +144,7 @@ class Meta: str_field = CharField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_meta_exclude(self): """ @@ -180,7 +179,7 @@ class Meta: id_field = ObjectIdField(required=False) """ % regex_repr) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_field_options(self): class TestSerializer(DocumentSerializer): @@ -209,7 +208,7 @@ class Meta: # "('red', 'Red'), ('blue', 'Blue'), ('green', 'Green')", # "(u'red', u'Red'), (u'blue', u'Blue'), (u'green', u'Green')" # ) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_method_field(self): """ @@ -226,7 +225,7 @@ class Meta: id = ObjectIdField(read_only=True) method = ReadOnlyField() """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_pk_fields(self): """ @@ -242,7 +241,7 @@ class Meta: pk = IntegerField(read_only=True) auto_field = IntegerField(read_only=True) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_id_field(self): """ @@ -257,7 +256,7 @@ class Meta: TestSerializer(): id = ObjectIdField(read_only=True) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_extra_field_kwargs(self): """ @@ -274,7 +273,7 @@ class Meta: id = ObjectIdField(read_only=True) str_field = CharField(default='extra') """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_invalid_field(self): """ diff --git a/tests/test_compound.py b/tests/test_compound.py index 0c90716..7299f3d 100644 --- a/tests/test_compound.py +++ b/tests/test_compound.py @@ -3,7 +3,6 @@ from django.test import TestCase from mongoengine import Document, fields -from rest_framework.compat import unicode_repr from rest_framework_mongoengine.serializers import DocumentSerializer @@ -47,7 +46,7 @@ class Meta: int_dict_field = DictField(child=IntegerField(required=False), required=False) int_map_field = DictField(child=IntegerField(required=False), required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_suboptions(self): class TestSerializer(DocumentSerializer): @@ -60,7 +59,7 @@ class Meta: id = ObjectIdField(read_only=True) int_list_field = ListField(child=IntegerField(max_value=7, min_value=3, required=False), required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_nested(self): class TestSerializer(DocumentSerializer): @@ -75,7 +74,7 @@ class Meta: list_dict_field = DictField(child=ListField(required=False), required=False) list_dict_list_field = ListField(child=DictField(child=ListField(required=False), required=False), required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected class TestSerializer(DocumentSerializer): diff --git a/tests/test_dumb.py b/tests/test_dumb.py index 71c09af..453e2ee 100644 --- a/tests/test_dumb.py +++ b/tests/test_dumb.py @@ -4,7 +4,6 @@ from django.test import TestCase from rest_framework import fields -from rest_framework.compat import unicode_repr from rest_framework_mongoengine.serializers import DocumentSerializer @@ -49,7 +48,7 @@ class Meta: """) # better output then self.assertEqual() - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected class TestSerializer(DocumentSerializer): diff --git a/tests/test_dynamic.py b/tests/test_dynamic.py index 641f911..2275447 100644 --- a/tests/test_dynamic.py +++ b/tests/test_dynamic.py @@ -4,7 +4,6 @@ from django.test import TestCase from rest_framework import fields as drf_fields -from rest_framework.compat import unicode_repr from rest_framework_mongoengine.serializers import ( DocumentSerializer, DynamicDocumentSerializer, EmbeddedDocumentSerializer @@ -83,7 +82,7 @@ class Meta: name = CharField(required=False) foo = IntegerField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_extended(self): class TestSerializer(DynamicDocumentSerializer): @@ -100,7 +99,7 @@ class Meta: name = CharField(required=False) foo = IntegerField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected class TestSerializer(DynamicDocumentSerializer): @@ -216,7 +215,7 @@ def test_repr(self): name = CharField(required=False) foo = IntegerField(required=False) """) - assert unicode_repr(EmbeddingDynamicSerializer()) == expected + assert repr(EmbeddingDynamicSerializer()) == expected class TestEmbeddingDynamicIntegration(TestCase): @@ -326,7 +325,7 @@ def test_repr(self): name = CharField(required=False) foo = IntegerField(required=False) """) - assert unicode_repr(DocumentEmbeddingDynamicSerializer()) == expected + assert repr(DocumentEmbeddingDynamicSerializer()) == expected class TestDocumentEmbeddingDynamicIntegration(TestCase): diff --git a/tests/test_embedded.py b/tests/test_embedded.py index d434040..c66a1e7 100644 --- a/tests/test_embedded.py +++ b/tests/test_embedded.py @@ -4,7 +4,6 @@ from django.test import TestCase from mongoengine import Document, EmbeddedDocument, fields from rest_framework import fields as drf_fields -from rest_framework.compat import unicode_repr from rest_framework.serializers import Field, Serializer from rest_framework_mongoengine.fields import DocumentField @@ -61,7 +60,7 @@ class Meta: name = CharField(required=False) foo = IntegerField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_embedding(self): class TestSerializer(DocumentSerializer): @@ -78,7 +77,7 @@ class Meta: name = CharField(required=False) foo = IntegerField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_embedding_nodepth(self): class TestSerializer(DocumentSerializer): @@ -95,7 +94,7 @@ class Meta: name = CharField(required=False) foo = IntegerField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_embedding_restricted(self): class TestSerializer(DocumentSerializer): @@ -110,7 +109,7 @@ class Meta: name = CharField(required=False) embedded = HiddenField(default=None, required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_embedding_recursive(self): class TestSerializer(DocumentSerializer): @@ -135,7 +134,7 @@ class Meta: """) serializer = TestSerializer() - assert unicode_repr(serializer) == expected + assert repr(serializer) == expected def test_embedding_recursive_restricted(self): class TestSerializer(DocumentSerializer): @@ -154,7 +153,7 @@ class Meta: """) serializer = TestSerializer() - assert unicode_repr(serializer) == expected + assert repr(serializer) == expected def test_embedding_nested(self): class TestSerializer(DocumentSerializer): @@ -170,7 +169,7 @@ class Meta: name = CharField(required=False) foo = IntegerField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_embedding_list(self): class TestSerializer(DocumentSerializer): @@ -184,7 +183,7 @@ class Meta: name = CharField(required=False) foo = IntegerField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_embedding_required(self): class TestSerializer(DocumentSerializer): @@ -198,7 +197,7 @@ class Meta: name = CharField(required=False) foo = IntegerField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_embedding_generic(self): class TestSerializer(DocumentSerializer): @@ -211,7 +210,7 @@ class Meta: id = ObjectIdField(read_only=True) embedded = GenericEmbeddedDocumentField(model_field=, required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_embedding_custom_generic(self): @@ -230,7 +229,7 @@ class Meta: id = ObjectIdField(read_only=True) embedded = CustomEmbedding(model_field=, required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_embedding_custom_nested(self): class CustomTestSerializer(Serializer): @@ -249,7 +248,7 @@ class Meta: embedded = EmbeddedSerializer(required=False): bla = CharField() """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_embedding_custom_bottom(self): class CustomEmbedding(Field): @@ -268,7 +267,7 @@ class Meta: id = ObjectIdField(read_only=True) embedded = CustomEmbedding(default=None, required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected class EmbeddingSerializer(DocumentSerializer): diff --git a/tests/test_files.py b/tests/test_files.py index 6e7864e..b40709e 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -6,7 +6,6 @@ from django.core.files.uploadedfile import UploadedFile from django.test import TestCase from mongoengine import Document, fields -from rest_framework.compat import unicode_repr from rest_framework_mongoengine.serializers import DocumentSerializer @@ -54,7 +53,7 @@ class Meta: i = ImageField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected class TestFilesIntegration(TestCase): diff --git a/tests/test_geo.py b/tests/test_geo.py index 0186828..6126581 100644 --- a/tests/test_geo.py +++ b/tests/test_geo.py @@ -1,6 +1,5 @@ from django.test import TestCase from mongoengine import Document, fields -from rest_framework.compat import unicode_repr from rest_framework_mongoengine.fields import GeoJSONField, GeoPointField from rest_framework_mongoengine.serializers import DocumentSerializer @@ -168,4 +167,4 @@ class Meta: multi_line_field = GeoJSONField(geo_type='MultiLineString', required=False) multi_poly_field = GeoJSONField(geo_type='MultiPolygon', required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected diff --git a/tests/test_nested_customization.py b/tests/test_nested_customization.py index b771a3f..efadd00 100644 --- a/tests/test_nested_customization.py +++ b/tests/test_nested_customization.py @@ -12,7 +12,6 @@ from django.test import TestCase from mongoengine import Document, EmbeddedDocument, fields -from rest_framework.compat import unicode_repr from rest_framework.serializers import ValidationError from rest_framework_mongoengine.serializers import DocumentSerializer @@ -62,7 +61,7 @@ class Meta: nested_reference = NestedSerializer(read_only=True): foo = CharField(required=False) """) - assert unicode_repr(ParentSerializer()) == expected + assert repr(ParentSerializer()) == expected def test_exclude(self): """Ensure `exclude` is passed to embedded documents.""" @@ -83,7 +82,7 @@ class Meta: name = CharField(required=False) """) - assert unicode_repr(ParentSerializer()) == expected + assert repr(ParentSerializer()) == expected def test_read_only(self): """Ensure `read_only` are passed to embedded documents.""" @@ -107,7 +106,7 @@ class Meta: age = IntegerField(required=False) """) - assert unicode_repr(ParentSerializer()) == expected + assert repr(ParentSerializer()) == expected def test_extra_field_kwargs(self): """Ensure `extra_kwargs` are passed to embedded documents.""" @@ -134,7 +133,7 @@ class Meta: age = IntegerField(required=False) """) - assert unicode_repr(ParentSerializer()) == expected + assert repr(ParentSerializer()) == expected class TestCompoundCustomizationMapping(TestCase): @@ -163,9 +162,9 @@ class Meta: """) serializer = CompoundParentSerializer() - unicode_repr(serializer) + repr(serializer) - assert unicode_repr(CompoundParentSerializer()) == expected + assert repr(CompoundParentSerializer()) == expected def test_exclude(self): """Ensure `exclude` is passed to embedded documents.""" @@ -190,7 +189,7 @@ class Meta: age = IntegerField(required=False) """) - assert unicode_repr(CompoundParentSerializer()) == expected + assert repr(CompoundParentSerializer()) == expected def test_read_only(self): """Ensure `read_only` are passed to embedded documents.""" @@ -220,7 +219,7 @@ class Meta: age = IntegerField(required=False) """) - assert unicode_repr(CompoundParentSerializer()) == expected + assert repr(CompoundParentSerializer()) == expected def test_extra_field_kwargs(self): class CompoundParentSerializer(DocumentSerializer): @@ -250,7 +249,7 @@ class Meta: age = IntegerField(required=False) """) - assert unicode_repr(CompoundParentSerializer()) == expected + assert repr(CompoundParentSerializer()) == expected class TestNestedCustomizationFieldsIntegration(TestCase): diff --git a/tests/test_reference.py b/tests/test_reference.py index 7e593e9..024c954 100644 --- a/tests/test_reference.py +++ b/tests/test_reference.py @@ -3,7 +3,6 @@ from bson import DBRef from django.test import TestCase from mongoengine import Document, fields -from rest_framework.compat import unicode_repr from rest_framework.fields import IntegerField from rest_framework.serializers import Serializer @@ -257,7 +256,8 @@ class Meta: cached = ReferenceField(queryset=ReferencedDoc.objects, required=False) generic = GenericReferenceField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected + def test_shallow(self): class TestSerializer(DocumentSerializer): @@ -271,7 +271,7 @@ class Meta: id = ObjectIdField(read_only=True) ref = ReferenceField(queryset=ReferencedDoc.objects, required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_deep(self): class TestSerializer(DocumentSerializer): @@ -287,7 +287,7 @@ class Meta: id = ObjectIdField(read_only=True) name = CharField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_recursive(self): class TestSerializer(DocumentSerializer): @@ -307,7 +307,7 @@ class Meta: id = ObjectIdField(read_only=True) ref = ReferenceField(queryset=RecursiveReferencingDoc.objects, required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_custom_field(self): @@ -327,7 +327,7 @@ class Meta: id = ObjectIdField(read_only=True) ref = ReferenceField(queryset=ReferencedDoc.objects, required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_custom_generic(self): class CustomReferencing(GenericReferenceField): @@ -346,7 +346,7 @@ class Meta: id = ObjectIdField(read_only=True) ref = CustomReferencing(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_custom_nested(self): class CustomReferencing(Serializer): @@ -366,7 +366,7 @@ class Meta: ref = NestedSerializer(read_only=True): foo = IntegerField() """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected class DisplayableReferencedModel(Document): diff --git a/tox.ini b/tox.ini index c5e696b..db2cbfb 100644 --- a/tox.ini +++ b/tox.ini @@ -1,21 +1,21 @@ [tox] -envlist=dj{18,19,110}-py{27,35}-me{09,010,011} +envlist=dj{110,21,22}-py{35,36,38}-me{016,017,018} [testenv] commands = ./runtests.py --nolint {posargs} --coverage deps = -rrequirements/requirements-testing.txt - dj18: Django==1.8.* - dj19: Django==1.9.* dj110: Django==1.10.* + dj21: Django==2.1.* + dj22: Django==2.2.* djangorestframework==3.* blinker==1.* - me09: mongoengine==0.9.* - me09: pymongo==2.* - me010: mongoengine==0.10.* - me010: pymongo==3.* - me011: mongoengine==0.11.* - me011: pymongo==3.* + me016: mongoengine==0.16.* + me016: pymongo==3.* + me017: mongoengine==0.17.* + me017: pymongo==3.* + me018: mongoengine==0.18.* + me018: pymongo==3.* [testenv:py27-lint] commands = ./runtests.py --lintonly From b849c98553ef241db2a8a98c037dffcf3945d9a7 Mon Sep 17 00:00:00 2001 From: Nicolae Godina Date: Fri, 20 Sep 2019 11:12:53 +0300 Subject: [PATCH 05/10] fix test for last drf versions --- rest_framework_mongoengine/serializers.py | 2 +- rest_framework_mongoengine/validators.py | 8 ++++---- tests/test_embedded.py | 2 +- tests/test_nested_customization.py | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rest_framework_mongoengine/serializers.py b/rest_framework_mongoengine/serializers.py index 253fc8b..e123c19 100644 --- a/rest_framework_mongoengine/serializers.py +++ b/rest_framework_mongoengine/serializers.py @@ -797,7 +797,7 @@ def get_unique_for_date_validators(self): return [] def __repr__(self): - return repr(serializer_repr(self, indent=1)) + return serializer_repr(self, indent=1) class EmbeddedDocumentSerializer(DocumentSerializer): diff --git a/rest_framework_mongoengine/validators.py b/rest_framework_mongoengine/validators.py index 9a4125d..8a5009a 100644 --- a/rest_framework_mongoengine/validators.py +++ b/rest_framework_mongoengine/validators.py @@ -27,10 +27,10 @@ def __call__(self, value): raise ValidationError(self.message.format()) def __repr__(self): - return repr('<%s(queryset=%s)>' % ( + return '<%s(queryset=%s)>' % ( self.__class__.__name__, smart_repr(self.queryset) - )) + ) class UniqueTogetherValidator(MongoValidatorMixin, validators.UniqueTogetherValidator): @@ -55,11 +55,11 @@ def __call__(self, attrs): raise ValidationError(self.message.format(field_names=field_names)) def __repr__(self): - return repr('<%s(queryset=%s, fields=%s)>' % ( + return '<%s(queryset=%s, fields=%s)>' % ( self.__class__.__name__, smart_repr(self.queryset), smart_repr(self.fields) - )) + ) class OptionalUniqueTogetherValidator(UniqueTogetherValidator): diff --git a/tests/test_embedded.py b/tests/test_embedded.py index c66a1e7..8e9b22b 100644 --- a/tests/test_embedded.py +++ b/tests/test_embedded.py @@ -613,7 +613,7 @@ def test_nested_validation_failing(self): serializer = ValidatingListSerializer(data={'embedded_list': [{'text': 'Fo'}]}) assert not serializer.is_valid() assert 'embedded_list' in serializer.errors - assert 'text' in serializer.errors['embedded_list'] + assert 'text' in serializer.errors['embedded_list'][0] def test_nested_validation_passing(self): serializer = ValidatingListSerializer(data={'embedded_list': [{'text': 'Text'}]}) diff --git a/tests/test_nested_customization.py b/tests/test_nested_customization.py index efadd00..1f7f39f 100644 --- a/tests/test_nested_customization.py +++ b/tests/test_nested_customization.py @@ -751,7 +751,7 @@ def test_update_fail(self): serializer = self.ParentSerializer(instance, data=data) assert not serializer.is_valid() - assert serializer.errors == {'embedded': {'name': [u'Minimum 4 characters.']}} + assert dict(serializer.errors) == {'embedded': {'name': [u'Minimum 4 characters.']}} class TestNestedCompoundCustomizationFieldsIntegration(TestCase): @@ -1331,7 +1331,7 @@ def test_create_fail(self): serializer = self.CompoundParentSerializer(data=data) assert not serializer.is_valid() - assert serializer.errors == {'embedded_list': {'name': [u'Minimum 4 characters.']}} + assert dict(serializer.errors) == {'embedded_list': {0: {'name': [u'Minimum 4 characters.']}}} def test_update_success(self): instance = CompoundParentDocument.objects.create( @@ -1378,4 +1378,4 @@ def test_update_fail(self): serializer = self.CompoundParentSerializer(instance, data=data) assert not serializer.is_valid() - assert serializer.errors == {'embedded_list': {'name': [u'Minimum 4 characters.']}} + assert dict(serializer.errors) == {'embedded_list': {0: {'name': [u'Minimum 4 characters.']}}} From da79c4908fcc5acfb6e2fd27585b4143c1811d34 Mon Sep 17 00:00:00 2001 From: Nicolae Godina Date: Fri, 20 Sep 2019 11:20:13 +0300 Subject: [PATCH 06/10] passing flake8 test --- rest_framework_mongoengine/repr.py | 1 + tests/test_embedded.py | 15 +++++++++++++-- tests/test_reference.py | 4 ++-- tests/test_validators.py | 3 ++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/rest_framework_mongoengine/repr.py b/rest_framework_mongoengine/repr.py index b7a2026..304b02d 100644 --- a/rest_framework_mongoengine/repr.py +++ b/rest_framework_mongoengine/repr.py @@ -38,6 +38,7 @@ def mongo_doc_repr(value): u = '[Bad Unicode data]' return force_str('<%s: %s>' % (value.__class__.__name__, u)) + uni_lit_re = re.compile("u'(.*?)'") diff --git a/tests/test_embedded.py b/tests/test_embedded.py index 8e9b22b..30cd9f2 100644 --- a/tests/test_embedded.py +++ b/tests/test_embedded.py @@ -10,7 +10,6 @@ from rest_framework_mongoengine.serializers import ( DocumentSerializer, EmbeddedDocumentSerializer ) - from .models import DumbEmbedded, OtherEmbedded from .utils import dedent @@ -55,6 +54,7 @@ class TestSerializer(EmbeddedDocumentSerializer): class Meta: model = DumbEmbedded fields = '__all__' + expected = dedent(""" TestSerializer(): name = CharField(required=False) @@ -68,6 +68,7 @@ class Meta: model = NestedEmbeddingDoc fields = '__all__' depth = 1 + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -85,6 +86,7 @@ class Meta: model = NestedEmbeddingDoc fields = '__all__' depth = 0 + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -102,6 +104,7 @@ class Meta: model = NestedEmbeddingDoc fields = '__all__' depth_embedding = 1 + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -142,6 +145,7 @@ class Meta: model = RecursiveEmbeddingDoc fields = '__all__' depth_embedding = 2 + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -160,6 +164,7 @@ class TestSerializer(DocumentSerializer): class Meta: model = NestedEmbeddingDoc fields = '__all__' + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -176,6 +181,7 @@ class TestSerializer(DocumentSerializer): class Meta: model = ListEmbeddingDoc fields = '__all__' + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -190,6 +196,7 @@ class TestSerializer(DocumentSerializer): class Meta: model = RequiredEmbeddingDoc fields = '__all__' + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -213,7 +220,6 @@ class Meta: assert repr(TestSerializer()) == expected def test_embedding_custom_generic(self): - class CustomEmbedding(DocumentField): pass @@ -284,8 +290,10 @@ class Meta: class TestEmbeddedIntegration(TestCase): """ should work on isolated embedded docs """ + def test_retrieve(self): """ serializing standalone doc """ + class TestSerializer(EmbeddedDocumentSerializer): class Meta: model = OtherEmbedded @@ -298,6 +306,7 @@ class Meta: def test_create(self): """ creating standalone instance """ + class TestSerializer(EmbeddedDocumentSerializer): class Meta: model = OtherEmbedded @@ -315,10 +324,12 @@ class Meta: def test_update(self): """ updating standalone instance with partial data """ + class TestSerializer(EmbeddedDocumentSerializer): class Meta: model = OtherEmbedded fields = '__all__' + instance = OtherEmbedded(name="qwe", bar=123) data = {'bar': 234} diff --git a/tests/test_reference.py b/tests/test_reference.py index 024c954..2132632 100644 --- a/tests/test_reference.py +++ b/tests/test_reference.py @@ -258,7 +258,6 @@ class Meta: """) assert repr(TestSerializer()) == expected - def test_shallow(self): class TestSerializer(DocumentSerializer): class Meta: @@ -310,7 +309,6 @@ class Meta: assert repr(TestSerializer()) == expected def test_custom_field(self): - class CustomReferencing(ReferenceField): pass @@ -709,6 +707,7 @@ class ComboReferencingSerializer(DocumentSerializer): class Meta: model = ReferencingDoc fields = '__all__' + ref = ComboReferenceField(serializer=ReferencedSerializer) def save_subdocs(self, validated_data): @@ -750,6 +749,7 @@ class Meta: model = ReferencingDoc fields = '__all__' depth = 1 + ref = ComboReferenceField(serializer=ReferencedSerializer) serializer = TestSerializer(instance) diff --git a/tests/test_validators.py b/tests/test_validators.py index 1a9d9a3..c792774 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -8,7 +8,6 @@ from rest_framework_mongoengine.validators import ( UniqueTogetherValidator, UniqueValidator ) - from .utils import dedent @@ -220,6 +219,7 @@ class UniqueTogetherSerializer(DocumentSerializer): class Meta: model = NullValidatingModel fields = '__all__' + data = {'name': 'existing', 'code': None, 'other': "xxx"} serializer = NullUniqueTogetherValidatorSerializer(data=data) assert serializer.is_valid(), serializer.errors @@ -277,6 +277,7 @@ def test_excluded_fields(self): When model fields are not included in a serializer and have no defaults, then uniqueness validators should not be added for that field. """ + class UniqueTogetherSerializer(DocumentSerializer): class Meta: model = UniqueTogetherModel From 8186fa6183a3bb65be2b426c1c29d6f7d60a872b Mon Sep 17 00:00:00 2001 From: Nicolae Godina Date: Fri, 20 Sep 2019 11:54:44 +0300 Subject: [PATCH 07/10] remove old tox env --- .travis.yml | 26 ++++++++------------------ setup.py | 2 +- tox.ini | 7 ++----- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 13bcbd8..ea760bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,24 +11,14 @@ env: - TOX_ENV=py27-lint # We don't have documentation source in the repo, so no py27-docs yet: # - TOX_ENV=py27-docs - - TOX_ENV=dj18-py27-me09 - - TOX_ENV=dj18-py35-me09 - - TOX_ENV=dj18-py27-me010 - - TOX_ENV=dj18-py35-me010 - - TOX_ENV=dj18-py27-me011 - - TOX_ENV=dj18-py35-me011 - - TOX_ENV=dj19-py27-me09 - - TOX_ENV=dj19-py35-me09 - - TOX_ENV=dj19-py27-me010 - - TOX_ENV=dj19-py35-me010 - - TOX_ENV=dj19-py27-me011 - - TOX_ENV=dj19-py35-me011 - - TOX_ENV=dj110-py27-me09 - - TOX_ENV=dj110-py35-me09 - - TOX_ENV=dj110-py27-me010 - - TOX_ENV=dj110-py35-me010 - - TOX_ENV=dj110-py27-me011 - - TOX_ENV=dj110-py35-me011 + - TOX_ENV=dj111-py36-me016 + - TOX_ENV=dj111-py36-me018 + - TOX_ENV=dj111-py38-me016 + - TOX_ENV=dj111-py38-me018 + - TOX_ENV=dj22-py36-me016 + - TOX_ENV=dj22-py36-me018 + - TOX_ENV=dj22-py38-me016 + - TOX_ENV=dj22-py38-me018 matrix: fast_finish: true diff --git a/setup.py b/setup.py index a4bad6b..e2a4bdc 100755 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ def get_package_data(package): setup( name='django-rest-framework-mongoengine', - version='3.3.1', + version='3.4.0', description='MongoEngine support for Django Rest Framework.', packages=get_packages('rest_framework_mongoengine'), package_data=get_package_data('rest_framework_mongoengine'), diff --git a/tox.ini b/tox.ini index db2cbfb..eecece5 100644 --- a/tox.ini +++ b/tox.ini @@ -1,19 +1,16 @@ [tox] -envlist=dj{110,21,22}-py{35,36,38}-me{016,017,018} +envlist=dj{111,22}-py{36,38}-me{016,018} [testenv] commands = ./runtests.py --nolint {posargs} --coverage deps = -rrequirements/requirements-testing.txt - dj110: Django==1.10.* - dj21: Django==2.1.* + dj111: Django==1.11.* dj22: Django==2.2.* djangorestframework==3.* blinker==1.* me016: mongoengine==0.16.* me016: pymongo==3.* - me017: mongoengine==0.17.* - me017: pymongo==3.* me018: mongoengine==0.18.* me018: pymongo==3.* From 276e037a2802223ad09b41125d35919742b55a63 Mon Sep 17 00:00:00 2001 From: Nicolae Godina Date: Fri, 20 Sep 2019 12:00:00 +0300 Subject: [PATCH 08/10] fix python versions for travis --- .travis.yml | 6 ++---- tox.ini | 6 ------ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index ea760bf..1d60391 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,14 @@ language: python python: - - "3.5" + - "3.6" + - "3.8" services: mongodb sudo: false env: - - TOX_ENV=py27-lint -# We don't have documentation source in the repo, so no py27-docs yet: -# - TOX_ENV=py27-docs - TOX_ENV=dj111-py36-me016 - TOX_ENV=dj111-py36-me018 - TOX_ENV=dj111-py38-me016 diff --git a/tox.ini b/tox.ini index eecece5..dd8a560 100644 --- a/tox.ini +++ b/tox.ini @@ -14,12 +14,6 @@ deps = me018: mongoengine==0.18.* me018: pymongo==3.* -[testenv:py27-lint] -commands = ./runtests.py --lintonly -deps = - -rrequirements/requirements-codestyle.txt - -rrequirements/requirements-testing.txt - # We don't have any documentation source in the repository yet, so # documentation generation is commented-out. Sphinx or Markdown? From d4559db06c355d2a3f4eb3d3f58e55ca7afb195f Mon Sep 17 00:00:00 2001 From: Nicolae Godina Date: Fri, 20 Sep 2019 12:05:05 +0300 Subject: [PATCH 09/10] fix virtual env for travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1d60391..f7334e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ matrix: fast_finish: true install: - - pip install tox "virtualenv<14" djangorestframework codecov + - pip install tox virtualenv djangorestframework codecov script: - tox -e $TOX_ENV From 29abf7772333cd9e49bbc84d5cab21e8105fcefc Mon Sep 17 00:00:00 2001 From: Nicolae Godina Date: Fri, 20 Sep 2019 12:16:45 +0300 Subject: [PATCH 10/10] temporary remove 3.8 test --- .travis.yml | 5 ----- tox.ini | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index f7334e6..3774b6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: python python: - "3.6" - - "3.8" services: mongodb @@ -11,12 +10,8 @@ sudo: false env: - TOX_ENV=dj111-py36-me016 - TOX_ENV=dj111-py36-me018 - - TOX_ENV=dj111-py38-me016 - - TOX_ENV=dj111-py38-me018 - TOX_ENV=dj22-py36-me016 - TOX_ENV=dj22-py36-me018 - - TOX_ENV=dj22-py38-me016 - - TOX_ENV=dj22-py38-me018 matrix: fast_finish: true diff --git a/tox.ini b/tox.ini index dd8a560..86eb371 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=dj{111,22}-py{36,38}-me{016,018} +envlist=dj{111,22}-py{36}-me{016,018} [testenv] commands = ./runtests.py --nolint {posargs} --coverage