diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..6deafc2 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 120 diff --git a/drf_extra_fields/fields.py b/drf_extra_fields/fields.py index 3687a95..5e20963 100644 --- a/drf_extra_fields/fields.py +++ b/drf_extra_fields/fields.py @@ -17,7 +17,7 @@ ImageField, IntegerField, ) -from rest_framework.utils import html, humanize_datetime, representation +from rest_framework.utils import html from .compat import ( DateRange, DateTimeTZRange, @@ -196,6 +196,7 @@ class DateRangeField(RangeField): child = DateField() range_type = DateRange + if postgres_fields is not None: # monkey patch modelserializer to map Native django Range fields to # drf_extra_fiels's Range fields. diff --git a/drf_extra_fields/runtests/settings.py b/drf_extra_fields/runtests/settings.py index f53d8fe..37754ec 100644 --- a/drf_extra_fields/runtests/settings.py +++ b/drf_extra_fields/runtests/settings.py @@ -1,3 +1,6 @@ +import os +import django + # Django settings for testproject project. DEBUG = True @@ -14,7 +17,7 @@ DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. + 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'sqlite.db', # Or path to database file if using sqlite3. 'USER': '', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. @@ -68,7 +71,7 @@ TEMPLATE_LOADERS = ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', -# 'django.template.loaders.eggs.Loader', + # 'django.template.loaders.eggs.Loader', ) MIDDLEWARE_CLASSES = ( @@ -105,42 +108,6 @@ # 'rest_framework.tests.users', ) -# OAuth is optional and won't work if there is no oauth_provider & oauth2 -try: - import oauth_provider - import oauth2 -except ImportError: - pass -else: - INSTALLED_APPS += ( - 'oauth_provider', - ) - -try: - import provider -except ImportError: - pass -else: - INSTALLED_APPS += ( - 'provider', - 'provider.oauth2', - ) - -# guardian is optional -try: - import guardian -except ImportError: - pass -else: - ANONYMOUS_USER_ID = -1 - AUTHENTICATION_BACKENDS = ( - 'django.contrib.auth.backends.ModelBackend', # default - 'guardian.backends.ObjectPermissionBackend', - ) - INSTALLED_APPS += ( - 'guardian', - ) - STATIC_URL = '/static/' PASSWORD_HASHERS = ( @@ -154,13 +121,10 @@ AUTH_USER_MODEL = 'auth.User' -import django - if django.VERSION < (1, 3): INSTALLED_APPS += ('staticfiles',) # If we're running on the Jenkins server we want to archive the coverage reports as XML. -import os if os.environ.get('HUDSON_URL', None): TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner' TEST_OUTPUT_VERBOSE = True diff --git a/requirements.txt b/requirements.txt index 5df405c..24b87de 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ Django >= 1.4 djangorestframework >= 3.0.1 -pillow \ No newline at end of file +pillow +flake8 +mock \ No newline at end of file diff --git a/tests/test_fields.py b/tests/test_fields.py index ed1315e..be42565 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -5,8 +5,7 @@ import django from django.core.exceptions import ValidationError from django.test import TestCase, override_settings -from django.db import models -from mock import MagicMock, patch +from mock import patch import pytz from rest_framework import serializers @@ -145,6 +144,7 @@ def test_hybrid_image_field(self): self.assertTrue(mixin_patch.to_internal_value.called) self.assertTrue(image_patch.to_internal_value.called) + class PDFBase64FileField(Base64FileField): ALLOWED_TYPES = ('pdf',) @@ -194,19 +194,16 @@ def test_create_with_base64_prefix(self): self.assertEqual(serializer.validated_data['created'], uploaded_file.created) self.assertFalse(serializer.validated_data is uploaded_file) - def test_validation_error_with_non_file(self): """ Passing non-base64 should raise a validation error. """ now = datetime.datetime.now() errmsg = "Please upload a valid file." - serializer = UploadedBase64FileSerializer(data={'created': now, - 'file': 'abc'}) + serializer = UploadedBase64FileSerializer(data={'created': now, 'file': 'abc'}) self.assertFalse(serializer.is_valid()) self.assertEqual(serializer.errors, {'file': [errmsg]}) - def test_remove_with_empty_string(self): """ Passing empty string as data should cause file to be removed @@ -309,8 +306,8 @@ def test_invalid_latitude(self): serializer = PointSerializer(data={'created': now, 'point': point}) self.assertFalse(serializer.is_valid()) -# Backported from django_rest_framework/tests/test_fields.py +# Backported from django_rest_framework/tests/test_fields.py def get_items(mapping_or_list_of_two_tuples): # Tests accept either lists of two tuples, or dictionaries. if isinstance(mapping_or_list_of_two_tuples, dict): diff --git a/tests/test_relations.py b/tests/test_relations.py index 1490fad..71264fe 100644 --- a/tests/test_relations.py +++ b/tests/test_relations.py @@ -1,5 +1,3 @@ -import pytest - from rest_framework import serializers from rest_framework.test import APISimpleTestCase from .utils import ( diff --git a/tox.ini b/tox.ini index 6a076d7..f724d28 100644 --- a/tox.ini +++ b/tox.ini @@ -9,4 +9,7 @@ deps = pytest-django psycopg2 mock -commands = py.test {posargs} + flake8 +commands = + py.test {posargs} + flake8