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/.travis.yml b/.travis.yml index 13bcbd8..3774b6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,40 +1,23 @@ language: python python: - - "3.5" + - "3.6" 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=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=dj22-py36-me016 + - TOX_ENV=dj22-py36-me018 matrix: fast_finish: true install: - - pip install tox "virtualenv<14" djangorestframework codecov + - pip install tox virtualenv djangorestframework codecov script: - tox -e $TOX_ENV 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..304b02d 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 @@ -39,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'(.*?)'") @@ -55,7 +55,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 0a8fa4a..e123c19 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 @@ -87,6 +86,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 +115,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, @@ -796,7 +797,7 @@ def get_unique_for_date_validators(self): return [] def __repr__(self): - return unicode_to_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 e76883a..8a5009a 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,10 +27,10 @@ def __call__(self, value): raise ValidationError(self.message.format()) def __repr__(self): - return unicode_to_repr('<%s(queryset=%s)>' % ( + return '<%s(queryset=%s)>' % ( self.__class__.__name__, smart_repr(self.queryset) - )) + ) class UniqueTogetherValidator(MongoValidatorMixin, validators.UniqueTogetherValidator): @@ -56,11 +55,11 @@ 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 '<%s(queryset=%s, fields=%s)>' % ( self.__class__.__name__, smart_repr(self.queryset), smart_repr(self.fields) - )) + ) class OptionalUniqueTogetherValidator(UniqueTogetherValidator): 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/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..30cd9f2 100644 --- a/tests/test_embedded.py +++ b/tests/test_embedded.py @@ -4,14 +4,12 @@ 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 from rest_framework_mongoengine.serializers import ( DocumentSerializer, EmbeddedDocumentSerializer ) - from .models import DumbEmbedded, OtherEmbedded from .utils import dedent @@ -56,12 +54,13 @@ class TestSerializer(EmbeddedDocumentSerializer): class Meta: model = DumbEmbedded fields = '__all__' + expected = dedent(""" TestSerializer(): name = CharField(required=False) foo = IntegerField(required=False) """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected def test_embedding(self): class TestSerializer(DocumentSerializer): @@ -69,6 +68,7 @@ class Meta: model = NestedEmbeddingDoc fields = '__all__' depth = 1 + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -78,7 +78,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): @@ -86,6 +86,7 @@ class Meta: model = NestedEmbeddingDoc fields = '__all__' depth = 0 + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -95,7 +96,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): @@ -103,6 +104,7 @@ class Meta: model = NestedEmbeddingDoc fields = '__all__' depth_embedding = 1 + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -110,7 +112,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 +137,7 @@ class Meta: """) serializer = TestSerializer() - assert unicode_repr(serializer) == expected + assert repr(serializer) == expected def test_embedding_recursive_restricted(self): class TestSerializer(DocumentSerializer): @@ -143,6 +145,7 @@ class Meta: model = RecursiveEmbeddingDoc fields = '__all__' depth_embedding = 2 + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -154,13 +157,14 @@ class Meta: """) serializer = TestSerializer() - assert unicode_repr(serializer) == expected + assert repr(serializer) == expected def test_embedding_nested(self): class TestSerializer(DocumentSerializer): class Meta: model = NestedEmbeddingDoc fields = '__all__' + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -170,13 +174,14 @@ 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): class Meta: model = ListEmbeddingDoc fields = '__all__' + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -184,13 +189,14 @@ 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): class Meta: model = RequiredEmbeddingDoc fields = '__all__' + expected = dedent(""" TestSerializer(): id = ObjectIdField(read_only=True) @@ -198,7 +204,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,10 +217,9 @@ 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): - class CustomEmbedding(DocumentField): pass @@ -230,7 +235,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 +254,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 +273,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): @@ -285,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 @@ -299,6 +306,7 @@ class Meta: def test_create(self): """ creating standalone instance """ + class TestSerializer(EmbeddedDocumentSerializer): class Meta: model = OtherEmbedded @@ -316,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} @@ -614,7 +624,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_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..1f7f39f 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): @@ -752,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): @@ -1332,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( @@ -1379,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.']}}} diff --git a/tests/test_reference.py b/tests/test_reference.py index 7e593e9..2132632 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,7 @@ 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 +270,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 +286,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,10 +306,9 @@ 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): - class CustomReferencing(ReferenceField): pass @@ -327,7 +325,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 +344,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 +364,7 @@ class Meta: ref = NestedSerializer(read_only=True): foo = IntegerField() """) - assert unicode_repr(TestSerializer()) == expected + assert repr(TestSerializer()) == expected class DisplayableReferencedModel(Document): @@ -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 diff --git a/tox.ini b/tox.ini index c5e696b..86eb371 100644 --- a/tox.ini +++ b/tox.ini @@ -1,27 +1,18 @@ [tox] -envlist=dj{18,19,110}-py{27,35}-me{09,010,011} +envlist=dj{111,22}-py{36}-me{016,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.* + dj111: Django==1.11.* + 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.* - -[testenv:py27-lint] -commands = ./runtests.py --lintonly -deps = - -rrequirements/requirements-codestyle.txt - -rrequirements/requirements-testing.txt + me016: mongoengine==0.16.* + me016: pymongo==3.* + me018: mongoengine==0.18.* + me018: pymongo==3.* # We don't have any documentation source in the repository yet, so # documentation generation is commented-out. Sphinx or Markdown?