Skip to content

Commit

Permalink
add flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
alicertel committed Oct 7, 2017
1 parent 9901c5e commit 1aa4b03
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 53 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120
3 changes: 2 additions & 1 deletion drf_extra_fields/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
46 changes: 5 additions & 41 deletions drf_extra_fields/runtests/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import django

# Django settings for testproject project.

DEBUG = True
Expand All @@ -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.
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 = (
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Django >= 1.4
djangorestframework >= 3.0.1
pillow
pillow
flake8
mock
11 changes: 4 additions & 7 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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',)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions tests/test_relations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

from rest_framework import serializers
from rest_framework.test import APISimpleTestCase
from .utils import (
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ deps =
pytest-django
psycopg2
mock
commands = py.test {posargs}
flake8
commands =
py.test {posargs}
flake8

0 comments on commit 1aa4b03

Please sign in to comment.