diff --git a/fargo/fargo/admin.py b/fargo/fargo/admin.py
index 0db77a8..a5d8ccf 100644
--- a/fargo/fargo/admin.py
+++ b/fargo/fargo/admin.py
@@ -80,7 +80,7 @@ class DocumentAdmin(admin.ModelAdmin):
def users(self, instance):
User = get_user_model()
qs = User.objects.filter(user_documents__document=instance)
- return u', '.join(u'%s' % u for u in qs)
+ return ', '.join('%s' % u for u in qs)
def thumbnail(self, instance):
return instance.thumbnail_img_tag
diff --git a/fargo/fargo/api_errors.py b/fargo/fargo/api_errors.py
index 05cf24c..e21363b 100644
--- a/fargo/fargo/api_errors.py
+++ b/fargo/fargo/api_errors.py
@@ -34,4 +34,4 @@ class APIError(ValidationError):
detail = getattr(self, kind).copy()
detail.update(kwargs)
detail['msg'] = detail['msg'].format(**kwargs)
- super(APIError, self).__init__([detail])
+ super().__init__([detail])
diff --git a/fargo/fargo/api_fields.py b/fargo/fargo/api_fields.py
index d30e12f..27f7ef8 100644
--- a/fargo/fargo/api_fields.py
+++ b/fargo/fargo/api_fields.py
@@ -19,8 +19,8 @@ import uuid
import six
from django.core.files.base import ContentFile
-
from rest_framework import fields, serializers
+
from . import api_errors
@@ -32,7 +32,7 @@ class SlugCreatedRelatedField(serializers.SlugRelatedField):
class Base64FileField(fields.Field):
def __init__(self, *args, **kwargs):
self.max_size = kwargs.pop('max_size', 0)
- super(Base64FileField, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
def get_max_size(self):
if hasattr(self.max_size, '__call__'):
@@ -40,7 +40,7 @@ class Base64FileField(fields.Field):
return self.max_size
def to_internal_value(self, data):
- if isinstance(data, six.string_types):
+ if isinstance(data, str):
# base64 encoded image - decode
name = uuid.uuid4()
try:
diff --git a/fargo/fargo/api_views.py b/fargo/fargo/api_views.py
index 4fc16c1..bbd942a 100644
--- a/fargo/fargo/api_views.py
+++ b/fargo/fargo/api_views.py
@@ -17,19 +17,17 @@
import datetime
from django.conf import settings
-from django.urls import reverse
from django.contrib.auth.models import User
+from django.urls import reverse
from django.utils.text import slugify
from django.utils.timezone import now
-
-from rest_framework import serializers
+from rest_framework import exceptions, filters, mixins, routers, serializers, status, viewsets
from rest_framework.generics import GenericAPIView, ListAPIView
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
-from rest_framework import status, filters, mixins, viewsets, routers, exceptions
-from .models import Origin, Document, UserDocument, Validation
-from . import utils, api_errors, api_fields
+from . import api_errors, api_fields, utils
+from .models import Document, Origin, UserDocument, Validation
try:
from mellon.models import UserSAMLIdentifier
@@ -72,16 +70,16 @@ class UserSerializerMixin(serializers.Serializer):
return value
-class CommonAPIMixin(object):
+class CommonAPIMixin:
def handle_exception(self, exc):
if isinstance(exc, exceptions.APIException):
exc.detail = {'result': 0, 'errors': exc.detail}
- return super(CommonAPIMixin, self).handle_exception(exc)
+ return super().handle_exception(exc)
def finalize_response(self, request, response, *args, **kwargs):
if not isinstance(response.data, dict) or 'result' not in response.data:
response.data = {'result': 1, 'data': response.data}
- return super(CommonAPIMixin, self).finalize_response(request, response, *args, **kwargs)
+ return super().finalize_response(request, response, *args, **kwargs)
def get_max_size():
@@ -95,7 +93,7 @@ class PushDocumentSerializer(UserSerializerMixin):
deletable_by_user = serializers.BooleanField(required=False, default=True)
def validate(self, data):
- data = super(PushDocumentSerializer, self).validate(data)
+ data = super().validate(data)
user = data['user']
if (
Document.objects.used_space(user) + data['file_b64_content'].size
@@ -175,7 +173,7 @@ class ValidationSerializer(UserSerializerMixin, serializers.ModelSerializer):
def __init__(self, *args, **kwargs):
schema = kwargs.pop('schema')
- super(ValidationSerializer, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
self.document_type = schema['name']
self.document_type_schema = schema
for field in schema['metadata']:
@@ -194,7 +192,7 @@ class ValidationSerializer(UserSerializerMixin, serializers.ModelSerializer):
return url
def validate(self, data):
- data = super(ValidationSerializer, self).validate(data)
+ data = super().validate(data)
data['document_type'] = self.document_type
data['created'] = now().replace(microsecond=0)
data['start'] = data['created'].date()
@@ -230,7 +228,7 @@ class ValidationAPI(
queryset = Validation.objects.all()
def get_queryset(self):
- return super(ValidationAPI, self).get_queryset().filter(document_type=self.document_type)
+ return super().get_queryset().filter(document_type=self.document_type)
def initial(self, request, document_type, *args, **kwargs):
self.document_type_schema = utils.get_document_type_schema(settings, document_type)
@@ -239,11 +237,11 @@ class ValidationAPI(
error.status_code = status.HTTP_404_NOT_FOUND
raise error
self.document_type = document_type
- super(ValidationAPI, self).initial(request, document_type, *args, **kwargs)
+ super().initial(request, document_type, *args, **kwargs)
def get_serializer(self, *args, **kwargs):
# pass schema to serializer class
- return super(ValidationAPI, self).get_serializer(schema=self.document_type_schema, *args, **kwargs)
+ return super().get_serializer(schema=self.document_type_schema, *args, **kwargs)
router = routers.SimpleRouter()
diff --git a/fargo/fargo/forms.py b/fargo/fargo/forms.py
index 9946691..ebd0d57 100644
--- a/fargo/fargo/forms.py
+++ b/fargo/fargo/forms.py
@@ -17,10 +17,9 @@
import os
from django import forms
-from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.template.defaultfilters import filesizeformat
-
+from django.utils.translation import ugettext_lazy as _
from . import models
@@ -57,7 +56,7 @@ class UploadForm(forms.ModelForm):
def save(self, *args, **kwargs):
self.instance.filename = self.files['content'].name[:512]
self.instance.document = models.Document.objects.get_by_file(self.files['content'])
- return super(UploadForm, self).save(*args, **kwargs)
+ return super().save(*args, **kwargs)
class Meta:
model = models.UserDocument
diff --git a/fargo/fargo/management/commands/fargo-cleanup.py b/fargo/fargo/management/commands/fargo-cleanup.py
index f70aff0..09b4230 100644
--- a/fargo/fargo/management/commands/fargo-cleanup.py
+++ b/fargo/fargo/management/commands/fargo-cleanup.py
@@ -14,8 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
-from django.core.management.base import BaseCommand
from django.core.management import call_command
+from django.core.management.base import BaseCommand
from fargo.fargo.utils import cleanup
diff --git a/fargo/fargo/managers.py b/fargo/fargo/managers.py
index fc1f2fa..580c821 100644
--- a/fargo/fargo/managers.py
+++ b/fargo/fargo/managers.py
@@ -46,4 +46,4 @@ class DocumentManager(models.Manager):
return o
def used_space(self, user):
- return sum([doc.content.size for doc in self.filter(user_documents__user=user)])
+ return sum(doc.content.size for doc in self.filter(user_documents__user=user))
diff --git a/fargo/fargo/migrations/0001_initial.py b/fargo/fargo/migrations/0001_initial.py
index 302a852..dad8b23 100644
--- a/fargo/fargo/migrations/0001_initial.py
+++ b/fargo/fargo/migrations/0001_initial.py
@@ -1,8 +1,5 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import models, migrations
from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/fargo/fargo/migrations/0001_squashed_0017_auto_20180331_1532.py b/fargo/fargo/migrations/0001_squashed_0017_auto_20180331_1532.py
index 7c12faa..244e5c5 100644
--- a/fargo/fargo/migrations/0001_squashed_0017_auto_20180331_1532.py
+++ b/fargo/fargo/migrations/0001_squashed_0017_auto_20180331_1532.py
@@ -1,13 +1,12 @@
-# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-03-31 13:34
-from __future__ import unicode_literals
import datetime
+
+import django.db.models.deletion
+import jsonfield.fields
from django.conf import settings
from django.db import migrations, models
-import django.db.models.deletion
from django.utils.timezone import utc
-import jsonfield.fields
class Migration(migrations.Migration):
diff --git a/fargo/fargo/migrations/0002_auto_20150818_2117.py b/fargo/fargo/migrations/0002_auto_20150818_2117.py
index bbe3155..8d3bd37 100644
--- a/fargo/fargo/migrations/0002_auto_20150818_2117.py
+++ b/fargo/fargo/migrations/0002_auto_20150818_2117.py
@@ -1,7 +1,4 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import models, migrations
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/fargo/fargo/migrations/0003_auto_20150924_1056.py b/fargo/fargo/migrations/0003_auto_20150924_1056.py
index 2445409..9937799 100644
--- a/fargo/fargo/migrations/0003_auto_20150924_1056.py
+++ b/fargo/fargo/migrations/0003_auto_20150924_1056.py
@@ -1,11 +1,9 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import models, migrations
-import jsonfield.fields
-from django.utils.timezone import utc
import datetime
+
+import jsonfield.fields
from django.conf import settings
+from django.db import migrations, models
+from django.utils.timezone import utc
def clear_document(apps, schema_editor):
diff --git a/fargo/fargo/migrations/0004_auto_20160212_0936.py b/fargo/fargo/migrations/0004_auto_20160212_0936.py
index e18da34..8e9cdb2 100644
--- a/fargo/fargo/migrations/0004_auto_20160212_0936.py
+++ b/fargo/fargo/migrations/0004_auto_20160212_0936.py
@@ -1,7 +1,4 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import models, migrations
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/fargo/fargo/migrations/0005_auto_20160312_1809.py b/fargo/fargo/migrations/0005_auto_20160312_1809.py
index 775c753..dd98a75 100644
--- a/fargo/fargo/migrations/0005_auto_20160312_1809.py
+++ b/fargo/fargo/migrations/0005_auto_20160312_1809.py
@@ -1,8 +1,5 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations, models
from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/fargo/fargo/migrations/0006_fill_new_columns.py b/fargo/fargo/migrations/0006_fill_new_columns.py
index 40be11b..a967ff0 100644
--- a/fargo/fargo/migrations/0006_fill_new_columns.py
+++ b/fargo/fargo/migrations/0006_fill_new_columns.py
@@ -1,6 +1,3 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
from django.db import migrations
diff --git a/fargo/fargo/migrations/0007_auto_20160312_1816.py b/fargo/fargo/migrations/0007_auto_20160312_1816.py
index 713665a..43c8074 100644
--- a/fargo/fargo/migrations/0007_auto_20160312_1816.py
+++ b/fargo/fargo/migrations/0007_auto_20160312_1816.py
@@ -1,8 +1,5 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations, models
from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/fargo/fargo/migrations/0008_validation_origin.py b/fargo/fargo/migrations/0008_validation_origin.py
index 45eeecb..b9f0eb8 100644
--- a/fargo/fargo/migrations/0008_validation_origin.py
+++ b/fargo/fargo/migrations/0008_validation_origin.py
@@ -1,6 +1,3 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
from django.db import migrations, models
diff --git a/fargo/fargo/migrations/0009_auto_20160326_2104.py b/fargo/fargo/migrations/0009_auto_20160326_2104.py
index 343efa4..f3713b1 100644
--- a/fargo/fargo/migrations/0009_auto_20160326_2104.py
+++ b/fargo/fargo/migrations/0009_auto_20160326_2104.py
@@ -1,6 +1,3 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
from django.db import migrations, models
diff --git a/fargo/fargo/migrations/0010_auto_20160413_0809.py b/fargo/fargo/migrations/0010_auto_20160413_0809.py
index 4b5a878..0086d65 100644
--- a/fargo/fargo/migrations/0010_auto_20160413_0809.py
+++ b/fargo/fargo/migrations/0010_auto_20160413_0809.py
@@ -1,8 +1,5 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations, models
from django.conf import settings
+from django.db import migrations, models
class Migration(migrations.Migration):
diff --git a/fargo/fargo/migrations/0011_userdocument_deletable_by_user.py b/fargo/fargo/migrations/0011_userdocument_deletable_by_user.py
index 777949b..877163a 100644
--- a/fargo/fargo/migrations/0011_userdocument_deletable_by_user.py
+++ b/fargo/fargo/migrations/0011_userdocument_deletable_by_user.py
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-29 14:37
-from __future__ import unicode_literals
from django.db import migrations, models
diff --git a/fargo/fargo/migrations/0012_auto_20161124_0626.py b/fargo/fargo/migrations/0012_auto_20161124_0626.py
index df42d54..c578223 100644
--- a/fargo/fargo/migrations/0012_auto_20161124_0626.py
+++ b/fargo/fargo/migrations/0012_auto_20161124_0626.py
@@ -1,6 +1,3 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
from django.db import migrations, models
diff --git a/fargo/fargo/migrations/0013_document_mime_type.py b/fargo/fargo/migrations/0013_document_mime_type.py
index fd44432..9163136 100644
--- a/fargo/fargo/migrations/0013_document_mime_type.py
+++ b/fargo/fargo/migrations/0013_document_mime_type.py
@@ -1,6 +1,3 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
from django.db import migrations, models
diff --git a/fargo/fargo/migrations/0014_auto_20171016_0854.py b/fargo/fargo/migrations/0014_auto_20171016_0854.py
index 40c09d6..b4d9302 100644
--- a/fargo/fargo/migrations/0014_auto_20171016_0854.py
+++ b/fargo/fargo/migrations/0014_auto_20171016_0854.py
@@ -1,6 +1,3 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
from django.db import migrations, models
diff --git a/fargo/fargo/migrations/0015_document_creation_date.py b/fargo/fargo/migrations/0015_document_creation_date.py
index 579891f..70055b9 100644
--- a/fargo/fargo/migrations/0015_document_creation_date.py
+++ b/fargo/fargo/migrations/0015_document_creation_date.py
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-03-23 15:30
-from __future__ import unicode_literals
from django.db import migrations, models
from django.utils import timezone
diff --git a/fargo/fargo/migrations/0016_auto_20180330_2248.py b/fargo/fargo/migrations/0016_auto_20180330_2248.py
index aa3dab3..9f861db 100644
--- a/fargo/fargo/migrations/0016_auto_20180330_2248.py
+++ b/fargo/fargo/migrations/0016_auto_20180330_2248.py
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-03-30 22:48
-from __future__ import unicode_literals
from django.db import migrations, models
diff --git a/fargo/fargo/migrations/0017_auto_20180331_1532.py b/fargo/fargo/migrations/0017_auto_20180331_1532.py
index 1c62b36..c1b1021 100644
--- a/fargo/fargo/migrations/0017_auto_20180331_1532.py
+++ b/fargo/fargo/migrations/0017_auto_20180331_1532.py
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-03-31 13:32
-from __future__ import unicode_literals
from django.db import migrations
diff --git a/fargo/fargo/models.py b/fargo/fargo/models.py
index e3d084f..903706a 100644
--- a/fargo/fargo/models.py
+++ b/fargo/fargo/models.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# fargo - document box
# Copyright (C) 2016-2019 Entr'ouvert
#
@@ -17,30 +16,27 @@
import base64
import hashlib
-import subprocess
import os
import re
+import subprocess
import threading
from django.conf import settings
-from django.urls import reverse
-from django.db import models
-from django.utils.encoding import python_2_unicode_compatible
-from django.utils.translation import ugettext_lazy as _
-from django.utils.encoding import force_text
-from django.utils.text import slugify
-from django.utils.http import urlquote
-from django.utils.html import format_html
-from django.dispatch import receiver
-from django.db.models.signals import post_save, post_delete
from django.core.files.storage import default_storage
-
-from sorl.thumbnail import get_thumbnail, delete
+from django.db import models
+from django.db.models.signals import post_delete, post_save
+from django.dispatch import receiver
+from django.urls import reverse
+from django.utils.encoding import force_text, python_2_unicode_compatible
+from django.utils.html import format_html
+from django.utils.http import urlquote
+from django.utils.text import slugify
+from django.utils.translation import ugettext_lazy as _
+from jsonfield import JSONField
+from sorl.thumbnail import delete, get_thumbnail
from sorl.thumbnail.conf import settings as thumbnail_settings
-from jsonfield import JSONField
-
-from . import utils, managers
+from . import managers, utils
def slug_truncate(label, length=256):
@@ -58,7 +54,7 @@ class Origin(models.Model):
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slug_truncate(self.label)
- return super(Origin, self).save(*args, **kwargs)
+ return super().save(*args, **kwargs)
def __str__(self):
return self.label
@@ -153,13 +149,13 @@ class Validation(models.Model):
parts = []
for meta_field in self.metadata:
parts.append(
- _(u'%(label)s: %(value)s')
+ _('%(label)s: %(value)s')
% {
'label': meta_field['label'],
'value': self.data.get(meta_field['varname'], ''),
}
)
- return force_text(u'; '.join(parts))
+ return force_text('; '.join(parts))
display.short_description = _('description')
@@ -191,7 +187,7 @@ class Document(models.Model):
self.content_hash = utils.sha256_of_file(self.content)
if not self.mime_type:
self.mime_type = utils.get_mime_type(self.content.file.name) or ''
- super(Document, self).save(*args, **kwargs)
+ super().save(*args, **kwargs)
@property
def thumbnail(self):
@@ -205,7 +201,7 @@ class Document(models.Model):
# check file exists and is readable
default_storage.open(thumbnail.name)
return thumbnail
- except IOError:
+ except OSError:
pass
return None
@@ -239,7 +235,7 @@ class Document(models.Model):
return {'src': self.thumbnail_data_url, 'width': thumbnail.width, 'height': thumbnail.height}
def __unicode__(self):
- return u'%s %s' % (os.path.basename(self.content.name), self.content_hash[:6])
+ return '%s %s' % (os.path.basename(self.content.name), self.content_hash[:6])
class Meta:
verbose_name = _('document')
diff --git a/fargo/fargo/tables.py b/fargo/fargo/tables.py
index 4ca42b0..288c036 100644
--- a/fargo/fargo/tables.py
+++ b/fargo/fargo/tables.py
@@ -14,9 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
-from django.utils.translation import ugettext_lazy as _
-
import django_tables2 as tables
+from django.utils.translation import ugettext_lazy as _
from . import models
diff --git a/fargo/fargo/utils.py b/fargo/fargo/utils.py
index 569ee96..dadf3fc 100644
--- a/fargo/fargo/utils.py
+++ b/fargo/fargo/utils.py
@@ -16,9 +16,9 @@
import hashlib
-from django.utils.timezone import utc
-from django.utils.encoding import smart_bytes
from django.apps import apps
+from django.utils.encoding import smart_bytes
+from django.utils.timezone import utc
try:
import magic
diff --git a/fargo/fargo/views.py b/fargo/fargo/views.py
index 19e6fbf..9b3e608 100644
--- a/fargo/fargo/views.py
+++ b/fargo/fargo/views.py
@@ -15,39 +15,37 @@
# along with this program. If not, see .
import logging
-from json import dumps
from copy import deepcopy
+from json import dumps
-from django.core.exceptions import PermissionDenied
-from django.views.decorators.clickjacking import xframe_options_exempt
-from django.views.generic import CreateView, DeleteView, UpdateView, View, TemplateView
-from django.urls import reverse, reverse_lazy
-from django.contrib.auth.decorators import login_required
-from django.shortcuts import get_object_or_404, resolve_url
-from django.http import (
- HttpResponse,
- HttpResponseRedirect,
- HttpResponseBadRequest,
- HttpResponseForbidden,
- Http404,
-)
-from django.core import signing
+from django.conf import settings
from django.contrib import messages
-from django.contrib.auth import get_user_model, REDIRECT_FIELD_NAME
+from django.contrib.auth import REDIRECT_FIELD_NAME, get_user_model
from django.contrib.auth import logout as auth_logout
from django.contrib.auth import views as auth_views
-from django.utils.http import quote
-from django.utils.translation import ugettext as _
+from django.contrib.auth.decorators import login_required
+from django.core import signing
+from django.core.exceptions import PermissionDenied
+from django.http import (
+ Http404,
+ HttpResponse,
+ HttpResponseBadRequest,
+ HttpResponseForbidden,
+ HttpResponseRedirect,
+)
+from django.shortcuts import get_object_or_404, resolve_url
+from django.urls import reverse, reverse_lazy
from django.utils.decorators import method_decorator
from django.utils.functional import cached_property
-from django.utils.decorators import method_decorator
+from django.utils.http import quote
+from django.utils.translation import ugettext as _
from django.views.decorators.cache import never_cache
-from django.conf import settings
-
+from django.views.decorators.clickjacking import xframe_options_exempt
+from django.views.generic import CreateView, DeleteView, TemplateView, UpdateView, View
from django_tables2 import SingleTableMixin
from ..utils import make_url
-from . import models, forms, tables
+from . import forms, models, tables
try:
from mellon.utils import get_idps
@@ -57,12 +55,12 @@ except ImportError:
return []
-class Logger(object):
+class Logger:
def __init__(self, *args, **kwargs):
self.logger = logging.getLogger(__name__)
-class Documents(object):
+class Documents:
def get_queryset(self):
return models.UserDocument.objects.filter(user=self.request.user).select_related('document', 'user')
@@ -81,14 +79,14 @@ class CommonUpload(Logger, Documents, CreateView):
template_name = 'fargo/upload.html'
def get_form_kwargs(self, **kwargs):
- kwargs = super(CommonUpload, self).get_form_kwargs(**kwargs)
+ kwargs = super().get_form_kwargs(**kwargs)
kwargs['instance'] = models.UserDocument(user=self.request.user)
return kwargs
def form_valid(self, form):
- result = super(CommonUpload, self).form_valid(form)
+ result = super().form_valid(form)
self.logger.info(
- u'user uploaded file %s (sha256=%s)', self.object.filename, self.object.document.content_hash
+ 'user uploaded file %s (sha256=%s)', self.object.filename, self.object.document.content_hash
)
return result
@@ -101,12 +99,12 @@ class Upload(CommonUpload):
def dispatch(self, request, *args, **kwargs):
if self.full:
return HttpResponseRedirect(self.get_success_url())
- return super(Upload, self).dispatch(request, *args, **kwargs)
+ return super().dispatch(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
if 'cancel' in request.POST:
return HttpResponseRedirect(self.get_success_url())
- return super(Upload, self).post(request, *args, **kwargs)
+ return super().post(request, *args, **kwargs)
class Homepage(SingleTableMixin, CommonUpload):
@@ -121,7 +119,7 @@ class Homepage(SingleTableMixin, CommonUpload):
success_url = reverse_lazy('home')
def get_context_data(self, **kwargs):
- ctx = super(Homepage, self).get_context_data(**kwargs)
+ ctx = super().get_context_data(**kwargs)
ctx['include_edit_link'] = settings.INCLUDE_EDIT_LINK
ctx['max_document_size'] = settings.FARGO_MAX_DOCUMENT_SIZE
occupancy = ctx['occupancy'] = models.Document.objects.used_space(self.request.user)
@@ -138,12 +136,12 @@ class Homepage(SingleTableMixin, CommonUpload):
return super(CommonUpload, self).post(request, *args, **kwargs)
-class PickView(object):
+class PickView:
def dispatch(self, request, *args, **kwargs):
self.pick_url = request.GET.get('pick')
if not self.pick_url:
return HttpResponseBadRequest('missing pick parameter')
- return super(PickView, self).dispatch(request, *args, **kwargs)
+ return super().dispatch(request, *args, **kwargs)
class PickList(PickView, Homepage):
@@ -152,7 +150,7 @@ class PickList(PickView, Homepage):
def post(self, request, *args, **kwargs):
if 'cancel' in request.POST:
return HttpResponseRedirect(make_url(self.pick_url, cancel=''))
- return super(PickList, self).post(request, *args, **kwargs)
+ return super().post(request, *args, **kwargs)
class Delete(Logger, Documents, DeleteView):
@@ -161,7 +159,7 @@ class Delete(Logger, Documents, DeleteView):
def delete(self, request, *args, **kwargs):
if not self.get_object().deletable_by_user:
raise PermissionDenied()
- result = super(Delete, self).delete(request, *args, **kwargs)
+ result = super().delete(request, *args, **kwargs)
messages.info(request, _('File %s deleted') % self.object.filename)
self.logger.info('user deleted file %r(%s)', self.object.filename, self.object.pk)
return result
@@ -177,7 +175,7 @@ class Edit(Logger, UpdateView):
def dispatch(self, request, *args, **kwargs):
if getattr(request, 'user', None) != self.get_object().user:
raise PermissionDenied
- return super(Edit, self).dispatch(request, *args, **kwargs)
+ return super().dispatch(request, *args, **kwargs)
def get_success_url(self):
return '../..?%s' % self.request.META['QUERY_STRING']
@@ -195,7 +193,7 @@ class Pick(PickView, Documents, Logger, View):
request=request,
)
self.logger.info(
- u'user picked file %s sha256 %s returned to %s',
+ 'user picked file %s sha256 %s returned to %s',
user_document.filename,
user_document.document.content_hash,
pick,
@@ -292,7 +290,7 @@ class ChooseDocumentKind(TemplateView):
template_name = 'fargo/choose_document_kind.html'
def get_context_data(self, **kwargs):
- ctx = super(ChooseDocumentKind, self).get_context_data(**kwargs)
+ ctx = super().get_context_data(**kwargs)
ctx['document_kinds'] = settings.FARGO_DOCUMENT_KINDS
return ctx
@@ -305,7 +303,7 @@ class LoginView(auth_views.LoginView):
return HttpResponseRedirect(
resolve_url('mellon_login') + '?next=' + quote(request.GET.get('next'))
)
- return super(LoginView, self).get(request, *args, **kwargs)
+ return super().get(request, *args, **kwargs)
login = LoginView.as_view()
@@ -316,7 +314,7 @@ class LogoutView(auth_views.LogoutView):
def dispatch(self, request, *args, **kwargs):
if any(get_idps()):
return HttpResponseRedirect(resolve_url('mellon_logout'))
- return super(LogoutView, self).dispatch(request, *args, **kwargs)
+ return super().dispatch(request, *args, **kwargs)
logout = LogoutView.as_view()
diff --git a/fargo/oauth2/admin.py b/fargo/oauth2/admin.py
index cf2a1d9..f2e0f89 100644
--- a/fargo/oauth2/admin.py
+++ b/fargo/oauth2/admin.py
@@ -17,7 +17,7 @@
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
-from .models import OAuth2Client, OAuth2Authorize, OAuth2TempFile
+from .models import OAuth2Authorize, OAuth2Client, OAuth2TempFile
class OAuth2ClientAdmin(admin.ModelAdmin):
diff --git a/fargo/oauth2/authentication.py b/fargo/oauth2/authentication.py
index 9311910..d85b31c 100644
--- a/fargo/oauth2/authentication.py
+++ b/fargo/oauth2/authentication.py
@@ -17,19 +17,16 @@
import logging
import requests
-
from django.conf import settings
-
from django.utils.six.moves.urllib import parse as urlparse
from django.utils.translation import ugettext_lazy as _
-
from rest_framework.authentication import BasicAuthentication
from rest_framework.exceptions import AuthenticationFailed
from .models import OAuth2Client
-class OAuth2User(object):
+class OAuth2User:
"""Fake user class to return in case OAuth2 Client authentication"""
def __init__(self, oauth2_client):
@@ -64,7 +61,7 @@ class FargoOAUTH2Authentication(BasicAuthentication):
authentic_idp = getattr(settings, 'FARGO_IDP_URL', None)
if not authentic_idp:
- logger.warning(u'idp check-password not configured')
+ logger.warning('idp check-password not configured')
return False, ''
url = urlparse.urljoin(authentic_idp, 'api/check-password/')
@@ -77,16 +74,16 @@ class FargoOAUTH2Authentication(BasicAuthentication):
)
response.raise_for_status()
except requests.RequestException as e:
- logger.warning(u'idp check-password API failed: %s', e)
+ logger.warning('idp check-password API failed: %s', e)
return False, 'idp is down'
try:
response = response.json()
except ValueError as e:
- logger.warning(u'idp check-password API failed: %s, %r', e, response.content)
+ logger.warning('idp check-password API failed: %s, %r', e, response.content)
return False, 'idp is down'
if response.get('result') == 0:
- logger.warning(u'idp check-password API failed')
+ logger.warning('idp check-password API failed')
return False, response.get('errors', [''])[0]
return True, None
diff --git a/fargo/oauth2/forms.py b/fargo/oauth2/forms.py
index 0ca356b..5ca4afb 100644
--- a/fargo/oauth2/forms.py
+++ b/fargo/oauth2/forms.py
@@ -29,6 +29,6 @@ class OAuth2AuthorizeForm(forms.Form):
document = UserDocModelChoiceField(queryset=None)
def __init__(self, user, *args, **kwargs):
- super(OAuth2AuthorizeForm, self).__init__(*args, **kwargs)
+ super().__init__(*args, **kwargs)
self.fields['document'].queryset = UserDocument.objects.filter(user=user)
self.fields['document'].label = _('Document')
diff --git a/fargo/oauth2/management/commands/oauth2-put-document.py b/fargo/oauth2/management/commands/oauth2-put-document.py
index 1f896a7..9671f2c 100644
--- a/fargo/oauth2/management/commands/oauth2-put-document.py
+++ b/fargo/oauth2/management/commands/oauth2-put-document.py
@@ -16,13 +16,13 @@
import os
-from django.core.management.base import BaseCommand
from django.core.files.base import ContentFile
+from django.core.management.base import BaseCommand
from django.urls import reverse
-from fargo.utils import make_url
from fargo.fargo.models import Document
-from fargo.oauth2.models import OAuth2TempFile, OAuth2Client
+from fargo.oauth2.models import OAuth2Client, OAuth2TempFile
+from fargo.utils import make_url
class Command(BaseCommand):
diff --git a/fargo/oauth2/migrations/0001_initial.py b/fargo/oauth2/migrations/0001_initial.py
index c7667fb..ef55087 100644
--- a/fargo/oauth2/migrations/0001_initial.py
+++ b/fargo/oauth2/migrations/0001_initial.py
@@ -1,7 +1,5 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
+from django.db import migrations, models
-from django.db import models, migrations
import fargo.oauth2.models
diff --git a/fargo/oauth2/migrations/0001_squashed_0005_auto_20180331_1532.py b/fargo/oauth2/migrations/0001_squashed_0005_auto_20180331_1532.py
index bd880fa..be79473 100644
--- a/fargo/oauth2/migrations/0001_squashed_0005_auto_20180331_1532.py
+++ b/fargo/oauth2/migrations/0001_squashed_0005_auto_20180331_1532.py
@@ -1,9 +1,8 @@
-# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-03-31 13:36
-from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
+
import fargo.oauth2.models
diff --git a/fargo/oauth2/migrations/0002_auto_20180321_2343.py b/fargo/oauth2/migrations/0002_auto_20180321_2343.py
index 6b7978c..7bc8f5a 100644
--- a/fargo/oauth2/migrations/0002_auto_20180321_2343.py
+++ b/fargo/oauth2/migrations/0002_auto_20180321_2343.py
@@ -1,9 +1,7 @@
-# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-03-21 23:43
-from __future__ import unicode_literals
-from django.db import migrations, models
import django.db.models.deletion
+from django.db import migrations, models
def delete_all_client_linked_models(apps, schema_editor):
diff --git a/fargo/oauth2/migrations/0003_auto_20180322_1016.py b/fargo/oauth2/migrations/0003_auto_20180322_1016.py
index af987ed..1321033 100644
--- a/fargo/oauth2/migrations/0003_auto_20180322_1016.py
+++ b/fargo/oauth2/migrations/0003_auto_20180322_1016.py
@@ -1,8 +1,7 @@
-# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-03-22 10:16
-from __future__ import unicode_literals
from django.db import migrations, models
+
import fargo.oauth2.models
diff --git a/fargo/oauth2/migrations/0004_auto_20180326_1330.py b/fargo/oauth2/migrations/0004_auto_20180326_1330.py
index 80c3f78..a63dc91 100644
--- a/fargo/oauth2/migrations/0004_auto_20180326_1330.py
+++ b/fargo/oauth2/migrations/0004_auto_20180326_1330.py
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-03-26 13:30
-from __future__ import unicode_literals
from django.db import migrations, models
diff --git a/fargo/oauth2/migrations/0005_auto_20180331_1532.py b/fargo/oauth2/migrations/0005_auto_20180331_1532.py
index 36b432c..c9e5a11 100644
--- a/fargo/oauth2/migrations/0005_auto_20180331_1532.py
+++ b/fargo/oauth2/migrations/0005_auto_20180331_1532.py
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
# Generated by Django 1.11.11 on 2018-03-31 13:32
-from __future__ import unicode_literals
from django.db import migrations
diff --git a/fargo/oauth2/models.py b/fargo/oauth2/models.py
index 583e3d5..8daeef3 100644
--- a/fargo/oauth2/models.py
+++ b/fargo/oauth2/models.py
@@ -14,17 +14,17 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
-import uuid
import datetime
+import uuid
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.validators import URLValidator
from django.db import models
-from django.utils.encoding import python_2_unicode_compatible
-from django.utils.translation import ugettext_lazy as _
from django.db.models.query import QuerySet
+from django.utils.encoding import python_2_unicode_compatible
from django.utils.timezone import now
+from django.utils.translation import ugettext_lazy as _
from fargo.fargo.models import Document, UserDocument
diff --git a/fargo/oauth2/urls.py b/fargo/oauth2/urls.py
index 2e96e4e..50782cf 100644
--- a/fargo/oauth2/urls.py
+++ b/fargo/oauth2/urls.py
@@ -18,11 +18,11 @@ from django.conf.urls import url
from .views import (
authorize_get_document,
- get_document_token,
- get_document,
authorize_put_document,
- put_document,
download_put_document,
+ get_document,
+ get_document_token,
+ put_document,
)
urlpatterns = [
diff --git a/fargo/oauth2/utils.py b/fargo/oauth2/utils.py
index 75b5d65..83eb5cc 100644
--- a/fargo/oauth2/utils.py
+++ b/fargo/oauth2/utils.py
@@ -16,10 +16,10 @@
import cgi
+from django.conf import settings
from django.utils import six
from django.utils.http import unquote
from django.utils.timezone import now
-from django.conf import settings
from .models import OAuth2Authorize
@@ -52,15 +52,7 @@ def get_content_disposition_value(request):
return None, 'wrong disposition type: attachment expected'
if 'filename*' in filename:
encode, country, name = filename['filename*'].split("'")
- if six.PY3:
- return (unquote(name, encode), None)
- # check accepted charset from rfc 5987
- if encode == 'UTF-8':
- return unquote(name).decode('utf8'), None
- elif encode == 'ISO-8859-1':
- return unquote(name).decode('iso-8859-1'), None
- else:
- return None, 'unknown encoding: UTF-8 or ISO-8859-1 allowed'
+ return (unquote(name, encode), None)
elif 'filename' in filename:
return filename['filename'], None
else:
diff --git a/fargo/oauth2/views.py b/fargo/oauth2/views.py
index a1d1d9f..b0c350c 100644
--- a/fargo/oauth2/views.py
+++ b/fargo/oauth2/views.py
@@ -16,30 +16,28 @@
import logging
-from django.shortcuts import get_object_or_404
-from django.utils.http import quote
-from django.utils.translation import ugettext as _
-from django.utils.timezone import now
+from django.conf import settings
+from django.contrib.auth.decorators import login_required
from django.core.files.base import ContentFile
-from django.urls import reverse
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseRedirect
+from django.shortcuts import get_object_or_404
+from django.urls import reverse
+from django.utils.http import quote
+from django.utils.timezone import now
+from django.utils.translation import ugettext as _
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import FormView, TemplateView, View
-from django.contrib.auth.decorators import login_required
-from django.conf import settings
-
from rest_framework.response import Response
from rest_framework.views import APIView
+from fargo.fargo.models import Document, UserDocument
+from fargo.utils import make_url
+
from .authentication import FargoOAUTH2Authentication
from .forms import OAuth2AuthorizeForm
from .models import OAuth2Authorize, OAuth2Client, OAuth2TempFile
from .utils import authenticate_bearer, get_content_disposition_value
-from fargo.fargo.models import UserDocument, Document
-from fargo.utils import make_url
-
-
logger = logging.getLogger(__name__)
@@ -53,7 +51,7 @@ class OAUTH2APIViewMixin(APIView):
@csrf_exempt
def dispatch(self, request, *args, **kwargs):
- return super(OAUTH2APIViewMixin, self).dispatch(request, *args, **kwargs)
+ return super().dispatch(request, *args, **kwargs)
class OAuth2AuthorizeView(FormView):
@@ -83,15 +81,15 @@ class OAuth2AuthorizeView(FormView):
except OAuth2Client.DoesNotExist:
return self.redirect(error='unauthorized_client')
self.state = request.GET.get('state', None)
- return super(OAuth2AuthorizeView, self).dispatch(request)
+ return super().dispatch(request)
def post(self, request):
if 'cancel' in request.POST:
return self.redirect(error='access_denied')
- return super(OAuth2AuthorizeView, self).post(request)
+ return super().post(request)
def get_form_kwargs(self):
- kwargs = super(OAuth2AuthorizeView, self).get_form_kwargs()
+ kwargs = super().get_form_kwargs()
kwargs['user'] = self.request.user
return kwargs
@@ -99,7 +97,7 @@ class OAuth2AuthorizeView(FormView):
document = form.cleaned_data['document']
authorization = OAuth2Authorize.objects.create(client=self.client, user_document=document)
logger.info(
- u'user %s authorized client "%s" to get document "%s" (%s) with code "%s"',
+ 'user %s authorized client "%s" to get document "%s" (%s) with code "%s"',
self.request.user,
self.client,
document,
@@ -110,7 +108,7 @@ class OAuth2AuthorizeView(FormView):
def get_context_data(self, **kwargs):
kwargs['oauth2_client'] = self.client
- return super(OAuth2AuthorizeView, self).get_context_data(**kwargs)
+ return super().get_context_data(**kwargs)
authorize_get_document = login_required(OAuth2AuthorizeView.as_view())
@@ -137,7 +135,7 @@ class GetDocumentTokenView(OAUTH2APIViewMixin):
if (now() - authorize.creation_date).total_seconds() > settings.FARGO_CODE_LIFETIME:
return self.error('invalid_grant', 'code is expired')
logger.info(
- u'client "%s" resolved code "%s" to access token "%s"',
+ 'client "%s" resolved code "%s" to access token "%s"',
request.user.oauth2_client,
authorize.code,
authorize.access_token,
@@ -172,7 +170,7 @@ def get_document(request):
user_document = oauth_authorize.user_document
logger.info(
- u'client "%s" retrieved document "%s" (%s) with access token "%s"',
+ 'client "%s" retrieved document "%s" (%s) with access token "%s"',
oauth_authorize.client,
user_document,
user_document.pk,
@@ -197,7 +195,7 @@ class PutDocumentAPIView(OAUTH2APIViewMixin):
response = Response()
response['Location'] = uri
logger.info(
- u'client "%s" uploaded document "%s" (%s)',
+ 'client "%s" uploaded document "%s" (%s)',
request.user.oauth2_client,
filename,
oauth2_document.pk,
@@ -220,7 +218,7 @@ class OAuth2AuthorizePutView(TemplateView):
if not self.redirect_uri:
return HttpResponseBadRequest('missing redirect_uri parameter')
self.oauth2_document = OAuth2TempFile.objects.filter(pk=kwargs['pk']).first()
- return super(OAuth2AuthorizePutView, self).dispatch(request)
+ return super().dispatch(request)
def get_context_data(self, **kwargs):
if self.oauth2_document:
@@ -242,7 +240,7 @@ class OAuth2AuthorizePutView(TemplateView):
else:
kwargs['error_message'] = _('The document has not been uploaded')
kwargs['redirect_uri'] = self.request.GET['redirect_uri']
- return super(OAuth2AuthorizePutView, self).get_context_data(**kwargs)
+ return super().get_context_data(**kwargs)
def post(self, request):
if not self.oauth2_document:
@@ -258,7 +256,7 @@ class OAuth2AuthorizePutView(TemplateView):
filename=self.oauth2_document.filename,
)
logger.info(
- u'user %s accepted document "%s" (%s) from client "%s"',
+ 'user %s accepted document "%s" (%s) from client "%s"',
request.user,
self.oauth2_document.filename,
self.oauth2_document.pk,
diff --git a/fargo/settings.py b/fargo/settings.py
index d6d616f..9d62c78 100644
--- a/fargo/settings.py
+++ b/fargo/settings.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# fargo - document box
# Copyright (C) 2016-2019 Entr'ouvert
#
@@ -24,11 +23,11 @@ https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
-from django.conf.global_settings import STATICFILES_FINDERS
-
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
+from django.conf.global_settings import STATICFILES_FINDERS
+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
@@ -185,17 +184,17 @@ FARGO_VALIDATION_LIFETIME = 3600 * 24 * 31 * 6 # nearly 6 months
FARGO_DOCUMENT_TYPES = [
{
'name': 'avis-d-imposition',
- 'label': u'Avis d\'imposition',
+ 'label': 'Avis d\'imposition',
'metadata': [
- {'label': u'Personne-s concernée-s', 'varname': 'personnes_concernees', 'type': 'string'},
+ {'label': 'Personne-s concernée-s', 'varname': 'personnes_concernees', 'type': 'string'},
{
- 'label': u'Année',
+ 'label': 'Année',
'varname': 'annee',
'type': 'string',
'validation': ' *[0-9]{4} *',
},
{
- 'label': u'Revenu fiscal de référence',
+ 'label': 'Revenu fiscal de référence',
'varname': 'revenu_fiscal_de_reference',
'type': 'string',
'validation': ' *[0-9]+ *',
diff --git a/fargo/urls.py b/fargo/urls.py
index 1deaed7..4396c9e 100644
--- a/fargo/urls.py
+++ b/fargo/urls.py
@@ -18,23 +18,23 @@ from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
+from .fargo.api_views import push_document, recent_documents, router
from .fargo.views import (
- home,
- jsonp,
- json,
- download,
- pick,
delete,
- upload,
+ document_types,
+ download,
edit,
- remote_download,
+ home,
+ json,
+ jsonp,
login,
logout,
+ pick,
pick_list,
- document_types,
+ remote_download,
thumbnail,
+ upload,
)
-from .fargo.api_views import push_document, recent_documents, router
urlpatterns = [
url(r'^$', home, name='home'),
diff --git a/fargo/wsgi.py b/fargo/wsgi.py
index cb85623..30e28e9 100644
--- a/fargo/wsgi.py
+++ b/fargo/wsgi.py
@@ -23,9 +23,10 @@ For more information on this file, see
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
"""
-from django.core.wsgi import get_wsgi_application
import os
+from django.core.wsgi import get_wsgi_application
+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "fargo.settings")
application = get_wsgi_application()
diff --git a/setup.py b/setup.py
index 2e45de3..574a8a0 100755
--- a/setup.py
+++ b/setup.py
@@ -1,15 +1,14 @@
#! /usr/bin/env python
-# -*- coding: utf-8 -*-
import os
import subprocess
import sys
-
-from setuptools.command.install_lib import install_lib as _install_lib
-from distutils.command.build import build as _build
-from setuptools.command.sdist import sdist
from distutils.cmd import Command
-from setuptools import setup, find_packages
+from distutils.command.build import build as _build
+
+from setuptools import find_packages, setup
+from setuptools.command.install_lib import install_lib as _install_lib
+from setuptools.command.sdist import sdist
class eo_sdist(sdist):
@@ -30,7 +29,7 @@ def get_version():
tag exists, take 0.0- and add the length of the commit log.
"""
if os.path.exists('VERSION'):
- with open('VERSION', 'r') as v:
+ with open('VERSION') as v:
return v.read()
if os.path.exists('.git'):
p = subprocess.Popen(
diff --git a/tests/conftest.py b/tests/conftest.py
index f66e61f..4c05c5b 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# fargo - document box
# Copyright (C) 2016-2019 Entr'ouvert
#
@@ -17,13 +16,13 @@
import logging
-import pytest
+
import django_webtest
-
-from django.core.files.base import ContentFile
+import pytest
from django.contrib.auth.models import User
+from django.core.files.base import ContentFile
-from fargo.fargo.models import UserDocument, Document
+from fargo.fargo.models import Document, UserDocument
class WebTestMixin(django_webtest.WebTestMixin):
diff --git a/tests/test_api.py b/tests/test_api.py
index 406ecaa..0935c88 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -18,9 +18,10 @@ import base64
import pytest
from django.utils.http import urlencode
-from fargo.fargo import utils, models
from test_manager import login
+from fargo.fargo import models, utils
+
pytestmark = pytest.mark.django_db
@@ -48,9 +49,9 @@ def test_create_validation(settings, app, admin_user, john_doe, jane_doe):
}
)
response1 = app.post_json(url, params=data, status=201)
- assert set(response1.json.keys()) == set(['result', 'data'])
+ assert set(response1.json.keys()) == {'result', 'data'}
assert response1.json['result'] == 1
- assert set(data.keys()) - set(['user_email']) < set(response1.json['data'].keys())
+ assert set(data.keys()) - {'user_email'} < set(response1.json['data'].keys())
assert models.Validation.objects.count() == 1
data['user_email'] = jane_doe.email
response2 = app.post_json(url, params=data, status=201)
@@ -79,7 +80,7 @@ def test_push_document(app, admin_user, john_doe):
assert models.UserDocument.objects.count() == 0
assert models.Document.objects.count() == 0
assert response.json['result'] == 0
- assert set(response.json['errors'].keys()) == set(['origin', 'file_b64_content'])
+ assert set(response.json['errors'].keys()) == {'origin', 'file_b64_content'}
data.update(
{
'origin': 'wcs',
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 2a5f496..9c8d187 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -16,12 +16,12 @@
import datetime
+from django.contrib.auth.models import User
+from django.core.files.base import ContentFile
from django.core.management import call_command
-from django.contrib.auth.models import User
-from fargo.fargo.models import UserDocument, Document
-from fargo.oauth2.models import OAuth2TempFile, OAuth2Client
-from django.core.files.base import ContentFile
+from fargo.fargo.models import Document, UserDocument
+from fargo.oauth2.models import OAuth2Client, OAuth2TempFile
def test_cleanup(freezer, john_doe):
diff --git a/tests/test_manager.py b/tests/test_manager.py
index e85e65d..a4e9e24 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -15,8 +15,8 @@
# along with this program. If not, see .
import os
-import pytest
+import pytest
from django.core.files.base import ContentFile
from fargo.fargo.models import Document
diff --git a/tests/test_oauth2.py b/tests/test_oauth2.py
index b408a7c..9151bcc 100644
--- a/tests/test_oauth2.py
+++ b/tests/test_oauth2.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# fargo - document box
# Copyright (C) 2016-2019 Entr'ouvert
#
@@ -15,21 +14,20 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
-import os
import json
-import mock
-import pytest
+import os
+from unittest import mock
-from django.urls import reverse
+import pytest
from django.core.management import call_command
+from django.urls import reverse
from django.utils.http import quote, urlencode
from django.utils.six.moves.urllib import parse as urlparse
-
-from fargo.oauth2.models import OAuth2Client, OAuth2Authorize, OAuth2TempFile
-from fargo.fargo.models import UserDocument
-
from test_manager import login
+from fargo.fargo.models import UserDocument
+from fargo.oauth2.models import OAuth2Authorize, OAuth2Client, OAuth2TempFile
+
pytestmark = pytest.mark.django_db
@@ -79,7 +77,7 @@ def test_get_document_oauth2(app, john_doe, oauth2_client, user_doc):
assert resp.status_code == 200
assert len(resp.form['document'].options) == 2
options = resp.form['document'].options
- assert u'éléphant.txt' in options[1]
+ assert 'éléphant.txt' in options[1]
# select the second document 'éléphant.txt'
resp.form['document'].select(options[1][0])
@@ -161,9 +159,7 @@ def test_put_document(app, john_doe, oauth2_client):
assert OAuth2TempFile.objects.count() == 1
assert UserDocument.objects.count() == 1
assert OAuth2TempFile.objects.get().document == UserDocument.objects.get().document
- assert UserDocument.objects.filter(
- user=john_doe, document=doc.document, filename=u'éléphant.txt'
- ).exists()
+ assert UserDocument.objects.filter(user=john_doe, document=doc.document, filename='éléphant.txt').exists()
def test_confirm_put_document_file_exception(app, oauth2_client, john_doe, user_doc):
@@ -197,7 +193,7 @@ def test_idp_authentication(mocked_post, settings, app, oauth2_client, john_doe,
params['redirect_uri'] = 'https://example.com'
resp = app.get(url, params=params)
options = resp.form['document'].options
- assert u'éléphant.txt' in options[1]
+ assert 'éléphant.txt' in options[1]
resp.form['document'].select(options[1][0])
resp = resp.form.submit()
auth = OAuth2Authorize.objects.filter(user_document__user=john_doe)[0]
diff --git a/tests/test_public.py b/tests/test_public.py
index 43ddc8d..ccfda96 100644
--- a/tests/test_public.py
+++ b/tests/test_public.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
# fargo - document box
# Copyright (C) 2016-2019 Entr'ouvert
#
@@ -16,21 +15,20 @@
# along with this program. If not, see .
-from webtest import Upload
import pytest
-
from django.urls import reverse
from django.utils.six.moves.urllib import parse as urlparse
+from webtest import Upload
try:
import magic
except ImportError:
magic = None
-from fargo.fargo.models import UserDocument
-
from test_manager import login
+from fargo.fargo.models import UserDocument
+
pytestmark = pytest.mark.django_db
@@ -59,7 +57,7 @@ def test_upload(app, john_doe):
form['content'] = Upload('monfichier.pdf', b'%PDF-1.4 ...', 'application/pdf')
response2 = form.submit().follow()
assert 'monfichier.pdf' in response2.text
- assert u'12 bytes' in response2.text
+ assert '12 bytes' in response2.text
if magic is not None:
assert UserDocument.objects.get(filename='monfichier.pdf').document.mime_type == 'application/pdf'
assert ' mime-application ' in response2.text