Refactoring: fix most of the (many) 'flake8' complaints
This commit is contained in:
parent
9df996e5ad
commit
a951f062f0
|
@ -24,6 +24,7 @@ from django.forms import ModelForm
|
|||
|
||||
from .models import ForwardFile, Collectivite, Guichet
|
||||
|
||||
|
||||
class ForwardFileForm(ModelForm):
|
||||
"""Form for the ForwardFile model."""
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ JSON_SCHEMA_FILE_B64 = {
|
|||
JSON_SCHEMA_DATE_FRENCH = {
|
||||
"type": "string",
|
||||
# pylint: disable=anomalous-backslash-in-string
|
||||
"pattern": "^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/\d{4}$"
|
||||
"pattern": "^(0?[1-9]|[12][0-9]|3[01])/(0?[1-9]|1[012])/\d{4}$" # noqa: W605
|
||||
}
|
||||
|
||||
JSON_SCHEMA_CHECK_STATUS_OUT = {
|
||||
|
@ -374,7 +374,7 @@ JSON_SCHEMA_GET_FWD_FILE_STATUS = {
|
|||
"$id": "#forwardfile-status",
|
||||
"type": "string",
|
||||
# pylint: disable=anomalous-backslash-in-string
|
||||
"pattern": "^\[\w+\] .+ => .+$"
|
||||
"pattern": "^\[\w+\] .+ => .+$" # noqa: W605
|
||||
}
|
||||
|
||||
JSON_SCHEMA_GET_FWD_FILES_STATUS_OUT = {
|
||||
|
|
|
@ -169,7 +169,7 @@ class ForwardFile(models.Model, BaseModel): # pylint: disable=too-many-instance-
|
|||
self.upload_file.delete()
|
||||
# else, update metadata
|
||||
else:
|
||||
self.size = self.upload_file.size if self.upload_file else 0 # pylint: disable=no-member
|
||||
self.size = self.upload_file.size if self.upload_file else 0 # noqa: E501, pylint: disable=no-member
|
||||
self.update_file_hash()
|
||||
self.update_content_type(only_if_empty=True)
|
||||
# validation (calling self.clean())
|
||||
|
@ -188,8 +188,7 @@ class ForwardFile(models.Model, BaseModel): # pylint: disable=too-many-instance-
|
|||
raise ValidationError(
|
||||
_("A %(object)s cannot have all the following fields empty: %(fields)s." % {
|
||||
'object': self.get_verbose_name(),
|
||||
'fields': ['file_hash', 'orig_filename', 'upload_file']}
|
||||
)
|
||||
'fields': ['file_hash', 'orig_filename', 'upload_file']})
|
||||
)
|
||||
return ret
|
||||
|
||||
|
@ -354,8 +353,7 @@ class Guichet(models.Model, BaseModel):
|
|||
or (day > self.ouverture_sem_d
|
||||
and day < self.fermeture_sem_d
|
||||
and date_t > ouverture_jour_date_t
|
||||
and date_t < fermeture_jour_date_t
|
||||
)
|
||||
and date_t < fermeture_jour_date_t)
|
||||
)
|
||||
|
||||
return False
|
||||
|
@ -480,7 +478,6 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
u"Expecting '%s' value in JSON %s in file dict to be a %s (not a %s)" %
|
||||
('file.filename', title, 'string', type(dict_file['filename'])))
|
||||
|
||||
|
||||
def get_first_file_from_payload(self,
|
||||
payload,
|
||||
title='payload',
|
||||
|
@ -503,14 +500,14 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
|
||||
@endpoint(
|
||||
description=_("Test an openADS 'connexion'")
|
||||
#~ get={
|
||||
#~ 'description': _("Test an openADS 'connexion'"),
|
||||
#~ 'response_body': {
|
||||
#~ 'schema': {
|
||||
#~ 'application/json': JSON_SCHEMA_CHECK_STATUS_OUT
|
||||
#~ }
|
||||
#~ }
|
||||
#~ }
|
||||
# get={
|
||||
# 'description': _("Test an openADS 'connexion'"),
|
||||
# 'response_body': {
|
||||
# 'schema': {
|
||||
# 'application/json': JSON_SCHEMA_CHECK_STATUS_OUT
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
)
|
||||
# pylint: disable=unused-argument,arguments-differ,keyword-arg-before-vararg
|
||||
def check_status(self, request=None, *args, **kwargs):
|
||||
|
@ -520,11 +517,10 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
response.raise_for_status()
|
||||
return {'response': response.status_code}
|
||||
|
||||
|
||||
@endpoint(
|
||||
perm='can_access',
|
||||
methods=['post'],
|
||||
pattern='^(?P<type_dossier>\w+)/?$', # pylint: disable=anomalous-backslash-in-string
|
||||
pattern='^(?P<type_dossier>\w+)/?$', # noqa: W605,E501, pylint: disable=anomalous-backslash-in-string
|
||||
example_pattern='{type_dossier}/',
|
||||
parameters={
|
||||
'type_dossier': {'description': _("Type of 'dossier'"), 'example_value': 'DIA'},
|
||||
|
@ -542,11 +538,11 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
'application/json': JSON_SCHEMA_CREATE_DOSSIER_IN
|
||||
} # pylint: disable=too-many-statements,too-many-branches,too-many-locals
|
||||
}
|
||||
#~ 'response_body': {
|
||||
#~ 'schema': {
|
||||
#~ 'application/json': JSON_SCHEMA_CREATE_DOSSIER_OUT
|
||||
#~ }
|
||||
#~ }
|
||||
# 'response_body': {
|
||||
# 'schema': {
|
||||
# 'application/json': JSON_SCHEMA_CREATE_DOSSIER_OUT
|
||||
# }
|
||||
# }
|
||||
}
|
||||
)
|
||||
# pylint: disable=unused-argument,keyword-arg-before-vararg
|
||||
|
@ -850,21 +846,21 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
perm='can_access',
|
||||
description=_("Get informations about an openADS 'dossier'"),
|
||||
# pylint: disable=anomalous-backslash-in-string
|
||||
pattern='^(?P<type_dossier>\w+)/(?P<numero_dossier>\w+)/?$',
|
||||
pattern='^(?P<type_dossier>\w+)/(?P<numero_dossier>\w+)/?$', # noqa: W605
|
||||
example_pattern='{type_dossier}/{numero_dossier}',
|
||||
parameters={
|
||||
'type_dossier': {'description': _("Type of 'dossier'"), 'example_value': 'DIA'},
|
||||
'numero_dossier': {'description': _("Identifier for 'dossier'"),
|
||||
'example_value': 'DIA0130551900001'}
|
||||
},
|
||||
#~ get={
|
||||
#~ 'description': _("Get informations about an openADS 'dossier'"),
|
||||
#~ 'response_body': {
|
||||
#~ 'schema': {
|
||||
#~ 'application/json': JSON_SCHEMA_GET_DOSSIER_OUT
|
||||
#~ }
|
||||
#~ }
|
||||
#~ }
|
||||
# get={
|
||||
# 'description': _("Get informations about an openADS 'dossier'"),
|
||||
# 'response_body': {
|
||||
# 'schema': {
|
||||
# 'application/json': JSON_SCHEMA_GET_DOSSIER_OUT
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
)
|
||||
# pylint: disable=unused-argument,keyword-arg-before-vararg
|
||||
def get_dossier(self, request, type_dossier, numero_dossier, *args, **kwargs):
|
||||
|
@ -896,7 +892,7 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
@endpoint(
|
||||
perm='can_access',
|
||||
description=_("Get informations about the forwarding of user files to openADS"),
|
||||
pattern='^(?P<numero_dossier>\w+)/?$', # pylint: disable=anomalous-backslash-in-string
|
||||
pattern='^(?P<numero_dossier>\w+)/?$', # noqa: W605,E501, pylint: disable=anomalous-backslash-in-string
|
||||
example_pattern='{numero_dossier}/',
|
||||
parameters={
|
||||
'numero_dossier': {'description': _("Identifier for 'dossier'"),
|
||||
|
@ -904,14 +900,14 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
'fichier_id': {'description': _("File identifier"),
|
||||
'example_value': '78'}
|
||||
},
|
||||
#~ get={
|
||||
#~ 'description': _("Get informations about the forwarding of user files to openADS"),
|
||||
#~ 'response_body': {
|
||||
#~ 'schema': {
|
||||
#~ 'application/json': JSON_SCHEMA_GET_FWD_FILES_OUT
|
||||
#~ }
|
||||
#~ }
|
||||
#~ }
|
||||
# get={
|
||||
# 'description': _("Get informations about the forwarding of user files to openADS"),
|
||||
# 'response_body': {
|
||||
# 'schema': {
|
||||
# 'application/json': JSON_SCHEMA_GET_FWD_FILES_OUT
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
)
|
||||
# pylint: disable=unused-argument,keyword-arg-before-vararg,no-self-use
|
||||
def get_fwd_files(self, request, numero_dossier, fichier_id=None, *args, **kwargs):
|
||||
|
@ -959,7 +955,7 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
@endpoint(
|
||||
perm='can_access',
|
||||
description=_("Get informations about the forwarding of a user file to openADS"),
|
||||
pattern='^(?P<numero_dossier>\w+)/?$', # pylint: disable=anomalous-backslash-in-string
|
||||
pattern='^(?P<numero_dossier>\w+)/?$', # noqa: W605,E501, pylint: disable=anomalous-backslash-in-string
|
||||
example_pattern='{numero_dossier}/',
|
||||
parameters={
|
||||
'numero_dossier': {'description': _("Identifier for 'dossier'"),
|
||||
|
@ -967,14 +963,14 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
'fichier_id': {'description': _("File identifier"),
|
||||
'example_value': '78'}
|
||||
},
|
||||
#~ get={
|
||||
#~ 'description': _("Get informations about the forwarding of a user file to openADS"),
|
||||
#~ 'response_body': {
|
||||
#~ 'schema': {
|
||||
#~ 'application/json': JSON_SCHEMA_GET_FWD_FILES_STATUS_OUT
|
||||
#~ }
|
||||
#~ }
|
||||
#~ }
|
||||
# get={
|
||||
# 'description': _("Get informations about the forwarding of a user file to openADS"),
|
||||
# 'response_body': {
|
||||
# 'schema': {
|
||||
# 'application/json': JSON_SCHEMA_GET_FWD_FILES_STATUS_OUT
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
)
|
||||
# pylint: disable=unused-argument,keyword-arg-before-vararg
|
||||
def get_fwd_files_status(self, request, numero_dossier, fichier_id=None, *args, **kwargs):
|
||||
|
@ -1009,8 +1005,7 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
@endpoint(
|
||||
perm='can_access',
|
||||
description=_("Get a 'courrier' from an openADS 'dossier'"),
|
||||
# pylint: disable=anomalous-backslash-in-string
|
||||
pattern='^(?P<type_dossier>\w+)/(?P<numero_dossier>\w+)/(?P<lettre_type>\w+)/?$',
|
||||
pattern='^(?P<type_dossier>\w+)/(?P<numero_dossier>\w+)/(?P<lettre_type>\w+)/?$', # noqa: W605,E501, pylint: disable=anomalous-backslash-in-string
|
||||
example_pattern='{type_dossier}/{numero_dossier}/{lettre_type}',
|
||||
parameters={
|
||||
'type_dossier': {'description': _("Type of 'dossier'"), 'example_value': 'DIA'},
|
||||
|
@ -1019,14 +1014,14 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
'lettre_type': {'description': _("Courrier ID to get"),
|
||||
'example_value': 'dia_renonciation_preempter'}
|
||||
},
|
||||
#~ get={
|
||||
#~ 'description': _("Get a 'courrier' from an openADS 'dossier'"),
|
||||
#~ 'response_body': {
|
||||
#~ 'schema': {
|
||||
#~ 'application/json': JSON_SCHEMA_GET_COURRIER_OUT
|
||||
#~ }
|
||||
#~ }
|
||||
#~ }
|
||||
# get={
|
||||
# 'description': _("Get a 'courrier' from an openADS 'dossier'"),
|
||||
# 'response_body': {
|
||||
# 'schema': {
|
||||
# 'application/json': JSON_SCHEMA_GET_COURRIER_OUT
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
)
|
||||
# pylint: disable=unused-argument,keyword-arg-before-vararg
|
||||
def get_courrier(self, request, type_dossier, numero_dossier, lettre_type, *args, **kwargs):
|
||||
|
@ -1099,7 +1094,7 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
perm='can_access',
|
||||
description=_("Trigger the uploading of user's files to openADS"),
|
||||
# pylint: disable=anomalous-backslash-in-string
|
||||
pattern='^(?P<type_dossier>\w+)/(?P<numero_dossier>\w+)/?$',
|
||||
pattern='^(?P<type_dossier>\w+)/(?P<numero_dossier>\w+)/?$', # noqa: W605
|
||||
example_pattern='{type_dossier}/{numero_dossier}',
|
||||
parameters={
|
||||
'type_dossier': {'description': _("Type of 'dossier'"), 'example_value': 'DIA'},
|
||||
|
@ -1109,14 +1104,14 @@ class AtrealOpenads(BaseResource, HTTPResource, BaseModel):
|
|||
"(coma separated)")),
|
||||
'example_value': '12,18'}
|
||||
}, # pylint: disable=too-many-statements,too-many-branches,too-many-locals
|
||||
#~ get={
|
||||
#~ 'description': _("Trigger the uploading of user's files to openADS"),
|
||||
#~ 'response_body': {
|
||||
#~ 'schema': {
|
||||
#~ 'application/json': JSON_SCHEMA_UPLOAD_USER_FILES
|
||||
#~ }
|
||||
#~ }
|
||||
#~ }
|
||||
# get={
|
||||
# 'description': _("Trigger the uploading of user's files to openADS"),
|
||||
# 'response_body': {
|
||||
# 'schema': {
|
||||
# 'application/json': JSON_SCHEMA_UPLOAD_USER_FILES
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
)
|
||||
# @raise ForwareFile.DoesNotExist if not found
|
||||
# pylint: disable=unused-argument,keyword-arg-before-vararg
|
||||
|
|
|
@ -76,7 +76,7 @@ for view in [
|
|||
|
||||
regex_base = r'^(?P<connecteur>[\w,-]+)/'
|
||||
# pylint: disable=anomalous-backslash-in-string
|
||||
regex_pkey = '/(?P<pk>[\w,-]+)'
|
||||
regex_pkey = '/(?P<pk>[\w,-]+)' # noqa: W605
|
||||
|
||||
url_name = url_prefix + view.model.get_class_name_dash_case()
|
||||
regex_url = '%s%s' % (url_prefix if view_action != 'view' else '',
|
||||
|
@ -93,7 +93,7 @@ for view in [
|
|||
|
||||
# for 'guichet' prefix the regex by the collectivite
|
||||
if view.model.get_class_name() == 'Guichet':
|
||||
regex_base += 'collectivite/(?P<collectivite>[\w,-]+)/'
|
||||
regex_base += 'collectivite/(?P<collectivite>[\w,-]+)/' # noqa: W605
|
||||
|
||||
# build the regex
|
||||
regex = regex_base + regex_url + regex_pkey + '$'
|
||||
|
|
|
@ -56,8 +56,10 @@ class MLStripper(HTMLParser):
|
|||
def __init__(self):
|
||||
self.reset()
|
||||
self.fed = []
|
||||
|
||||
def handle_data(self, data):
|
||||
self.fed.append(data)
|
||||
|
||||
def get_data(self):
|
||||
"""Get the stripped data as a string."""
|
||||
return ''.join(self.fed)
|
||||
|
@ -103,9 +105,11 @@ def get_file_digest(content, chunk_size=100000):
|
|||
"""Return a hash for the content specified."""
|
||||
digest = hashlib.sha256()
|
||||
content.seek(0)
|
||||
|
||||
def read_chunk():
|
||||
"""Read 'chunk_size' amount of data from the content."""
|
||||
return content.read(chunk_size)
|
||||
|
||||
for chunk in iter(read_chunk, ''):
|
||||
digest.update(chunk)
|
||||
return digest.hexdigest()
|
||||
|
@ -145,7 +149,7 @@ def trunc_str_values(value, limit, visited=None, truncate_text=u'…'):
|
|||
|
||||
if visited is None:
|
||||
visited = []
|
||||
if not value in visited:
|
||||
if value not in visited:
|
||||
if isinstance(value, basestring) and len(value) > limit:
|
||||
value = value[:limit] + truncate_text
|
||||
elif isinstance(value, (dict, list, tuple)):
|
||||
|
|
|
@ -26,7 +26,7 @@ LANGUAGE_CODE = 'en-us'
|
|||
TIME_ZONE = 'UTC'
|
||||
|
||||
# include app
|
||||
INSTALLED_APPS += ( # pylint: disable=undefined-variable
|
||||
INSTALLED_APPS += ( # noqa: F821, pylint: disable=undefined-variable
|
||||
'atreal_openads',
|
||||
)
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ def atreal_openads(db):
|
|||
basic_auth_password=OPENADS_API_PASSWORD
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
# pylint: disable=unused-argument,redefined-outer-name,invalid-name
|
||||
def collectivite_1(db, atreal_openads):
|
||||
|
@ -96,6 +97,7 @@ def collectivite_1(db, atreal_openads):
|
|||
openADS_id='3'
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
# pylint: disable=unused-argument,redefined-outer-name,invalid-name
|
||||
def collectivite_1_guichet(db, atreal_openads, collectivite_1):
|
||||
|
|
|
@ -70,6 +70,7 @@ def atreal_openads(db):
|
|||
basic_auth_password=OPENADS_API_PASSWORD
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
# pylint: disable=unused-argument,redefined-outer-name,invalid-name
|
||||
def collectivite_1(db, atreal_openads):
|
||||
|
@ -80,6 +81,7 @@ def collectivite_1(db, atreal_openads):
|
|||
openADS_id='3'
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
# pylint: disable=unused-argument,redefined-outer-name,invalid-name
|
||||
def collectivite_1_guichet(db, atreal_openads, collectivite_1):
|
||||
|
|
|
@ -80,6 +80,7 @@ def atreal_openads(db):
|
|||
basic_auth_password=OPENADS_API_PASSWORD
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
# pylint: disable=unused-argument,redefined-outer-name,invalid-name
|
||||
def collectivite_1(db, atreal_openads):
|
||||
|
@ -90,6 +91,7 @@ def collectivite_1(db, atreal_openads):
|
|||
openADS_id='3'
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
# pylint: disable=unused-argument,redefined-outer-name,invalid-name
|
||||
def collectivite_1_guichet(db, atreal_openads, collectivite_1):
|
||||
|
|
|
@ -85,6 +85,7 @@ def atreal_openads(db):
|
|||
basic_auth_password=OPENADS_API_PASSWORD
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
# pylint: disable=unused-argument,redefined-outer-name,invalid-name
|
||||
def collectivite_1(db, atreal_openads):
|
||||
|
@ -95,6 +96,7 @@ def collectivite_1(db, atreal_openads):
|
|||
openADS_id='3'
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
# pylint: disable=unused-argument,redefined-outer-name,invalid-name
|
||||
def collectivite_1_guichet(db, atreal_openads, collectivite_1):
|
||||
|
@ -109,6 +111,7 @@ def collectivite_1_guichet(db, atreal_openads, collectivite_1):
|
|||
fermeture_sem_h=datetime.time(12, 15)
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
# pylint: disable=unused-argument,redefined-outer-name,invalid-name
|
||||
def forwardfile_1(db, atreal_openads, collectivite_1):
|
||||
|
@ -153,7 +156,7 @@ def test_get_connecteur_from_request(atreal_openads, forwardfile_1): # pylint: d
|
|||
|
||||
|
||||
# pylint: disable=unused-argument,redefined-outer-name
|
||||
def test_get_collectivite_from_request(atreal_openads, collectivite_1): # pylint: disable=invalid-name
|
||||
def test_get_collectivite_from_request(atreal_openads, collectivite_1): # noqa: E501, pylint: disable=invalid-name
|
||||
"""Test for function 'get_collectivite_from_request()'."""
|
||||
|
||||
req = HttpRequest()
|
||||
|
|
Reference in New Issue