compatibilityé python 3.11 (#86371) #6

Merged
bdauvergne merged 6 commits from wip/86371-jenkins-echec-de-build-apres-mon into main 2024-02-02 20:46:42 +01:00
48 changed files with 207 additions and 247 deletions

View File

@ -4,3 +4,5 @@ faa1f97b000c9e259edbf45bed4b362fcb7fad8f
505cf434a05472e23beb8eda340d6e5c8e27c08b
# misc: apply double-quote-string-fixer (#79788)
cf608122ea9e94354d160932637e55c1b0137946
# apply pre-commit (#86371)
65add720c768b038dcf49b2af3e9ba87fc9b8d44

View File

@ -5,22 +5,40 @@ repos:
rev: v4.4.0
hooks:
- id: double-quote-string-fixer
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ['--keep-percent-format', '--py39-plus']
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.13.0
hooks:
- id: django-upgrade
args: ['--target-version', '3.2']
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.1.0
hooks:
- id: black
args: ['--target-version', 'py37', '--skip-string-normalization', '--line-length', '110']
args: ['--target-version', 'py39', '--skip-string-normalization', '--line-length', '110']
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ['--profile', 'black', '--line-length', '110']
- repo: https://github.com/asottile/pyupgrade
rev: v3.1.0
hooks:
- id: pyupgrade
args: ['--keep-percent-format', '--py37-plus']
- repo: https://github.com/rtts/djhtml
rev: '3.0.5'
hooks:
- id: djhtml
args: ['--tabwidth', '2']
- repo: https://git.entrouvert.org/pre-commit-debian.git
rev: v0.3
hooks:
- id: pre-commit-debian
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.15
hooks:
# Run the linter.
- id: ruff
Outdated
Review

on pourrait ajouter

args: ['--fix']

pour gagner un peu de temps quand ruff veut faire des modifs

on pourrait ajouter ``` args: ['--fix'] ``` pour gagner un peu de temps quand ruff veut faire des modifs
args: ['--fix']
exclude: 'debian/.*'

1
Jenkinsfile vendored
View File

@ -13,7 +13,6 @@ pipeline {
utils = new Utils()
utils.publish_coverage('coverage.xml')
utils.publish_coverage_native('index.html')
utils.publish_pylint('pylint.out')
}
mergeJunitResults()
}

View File

@ -19,7 +19,6 @@ from django.db.migrations.operations.base import Operation
class EnsureJsonbType(Operation):
reversible = True
def __init__(self, model_name, field_name):

View File

@ -19,7 +19,7 @@ from django.contrib.auth import get_user_model
from django.shortcuts import redirect
from django.urls import reverse
from django.urls.exceptions import NoReverseMatch
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import never_cache
from . import models
@ -65,11 +65,10 @@ class UserDocumentAdmin(admin.ModelAdmin):
'document__content_hash',
]
@admin.display(description=_('thumbnail'))
def thumbnail(self, instance):
return instance.document.thumbnail_img_tag
thumbnail.short_description = _('thumbnail')
class DocumentAdmin(admin.ModelAdmin):
fields = ['content_hash', 'thumbnail', 'users']
@ -82,11 +81,10 @@ class DocumentAdmin(admin.ModelAdmin):
qs = User.objects.filter(user_documents__document=instance)
return ', '.join('%s' % u for u in qs)
@admin.display(description=_('thumbnail'))
def thumbnail(self, instance):
return instance.thumbnail_img_tag
thumbnail.short_description = _('thumbnail')
class OriginAdmin(admin.ModelAdmin):
fields = ['label', 'slug']

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from rest_framework.serializers import ValidationError

View File

@ -17,7 +17,6 @@
import base64
import uuid
import six
from django.core.files.base import ContentFile
from rest_framework import fields, serializers

View File

@ -19,7 +19,7 @@ import os
from django import forms
from django.conf import settings
from django.template.defaultfilters import filesizeformat
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from . import models

View File

@ -3,7 +3,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

View File

@ -1,16 +1,12 @@
# Generated by Django 1.11.11 on 2018-03-31 13:34
import datetime
import django.db.models.deletion
from django.conf import settings
from django.contrib.postgres.fields import JSONField
from django.db import migrations, models
from django.utils.timezone import utc
class Migration(migrations.Migration):
replaces = [
('fargo', '0001_initial'),
('fargo', '0002_auto_20150818_2117'),

View File

@ -1,8 +1,7 @@
from django.db import migrations, models
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('fargo', '0001_initial'),
]

View File

@ -5,7 +5,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('fargo', '0001_squashed_0017_auto_20180331_1532'),

View File

@ -16,7 +16,6 @@ def noop(apps, schema_editor):
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('fargo', '0002_auto_20150818_2117'),

View File

@ -6,7 +6,6 @@ from fargo.db_utils import EnsureJsonbType
class Migration(migrations.Migration):
dependencies = [
('fargo', '0002_auto_20210824_0957'),
]

View File

@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fargo', '0003_auto_20150924_1056'),
]

View File

@ -1,11 +1,10 @@
# Generated by Django 2.2.28 on 2022-08-10 11:52
from django.conf import settings
from django.db import migrations, models
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('fargo', '0003_text_to_jsonb'),

View File

@ -3,7 +3,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('fargo', '0004_auto_20160212_0936'),

View File

@ -13,7 +13,6 @@ def noop(apps, schema_editor):
class Migration(migrations.Migration):
dependencies = [
('fargo', '0005_auto_20160312_1809'),
]

View File

@ -3,7 +3,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fargo', '0006_fill_new_columns'),
]

View File

@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fargo', '0007_auto_20160312_1816'),
]

View File

@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fargo', '0008_validation_origin'),
]

View File

@ -3,7 +3,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fargo', '0009_auto_20160326_2104'),
]

View File

@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fargo', '0010_auto_20160413_0809'),
]

View File

@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fargo', '0011_userdocument_deletable_by_user'),
]

View File

@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fargo', '0012_auto_20161124_0626'),
]

View File

@ -2,7 +2,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fargo', '0013_document_mime_type'),
]

View File

@ -5,7 +5,6 @@ from django.utils import timezone
class Migration(migrations.Migration):
dependencies = [
('fargo', '0014_auto_20171016_0854'),
]

View File

@ -4,7 +4,6 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fargo', '0015_document_creation_date'),
]

View File

@ -4,7 +4,6 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('fargo', '0016_auto_20180330_2248'),
]

View File

@ -18,21 +18,17 @@ import base64
import hashlib
import os
import re
import subprocess
import threading
from urllib.parse import quote
from django.conf import settings
from django.contrib.postgres.fields import JSONField
from django.core.files.storage import default_storage
from django.db import models
from django.db.models.signals import post_delete, post_save
from django.db.models.signals import post_delete
from django.dispatch import receiver
from django.urls import reverse
from django.utils.encoding import force_text
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 django.utils.translation import gettext_lazy as _
from sorl.thumbnail import delete, get_thumbnail
from sorl.thumbnail.conf import settings as thumbnail_settings
@ -87,7 +83,7 @@ class UserDocument(models.Model):
@property
def filename_encoded(self):
return urlquote(self.filename, safe='')
return quote(self.filename, safe='')
def __str__(self):
return self.title or self.filename
@ -128,7 +124,7 @@ class Document(models.Model):
if not self.content_hash:
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 ''
self.mime_type = utils.get_mime_type(self.content) or ''
if self.content.name and len(self.content.name) > 200:
file_root, file_ext = os.path.splitext(self.content.name)
file_root, file_ext = file_root[:150], file_ext[:50]

View File

@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import django_tables2 as tables
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from . import models
@ -31,6 +31,6 @@ class DocumentTable(tables.Table):
created = tables.DateTimeColumn(verbose_name=_('Creation Date'))
class Meta:
model = models.Document
model = models.UserDocument
fields = ('size', 'created')
empty_text = _('Your document box is currently empty.')

View File

@ -17,7 +17,6 @@
import hashlib
from django.apps import apps
from django.utils.encoding import smart_bytes
from django.utils.timezone import utc
try:
@ -38,14 +37,11 @@ def sha256_of_file(f):
return hasher.hexdigest()
def get_mime_type(path):
def get_mime_type(fd):
if magic is None:
return None
magic_object = magic.open(magic.MIME)
magic_object.load()
mime_type = magic_object.file(smart_bytes(path))
magic_object.close()
mime_type = magic.from_buffer(next(fd.chunks(1024 * 20)), mime=True)
if mime_type:
mime_type = mime_type.split(';')[0]
if mime_type.startswith('cannot open'):

View File

@ -16,13 +16,11 @@
import logging
import urllib.parse
from copy import deepcopy
from json import dumps
from django.conf import settings
from django.contrib import messages
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.contrib.auth.decorators import login_required
from django.core import signing
@ -39,7 +37,7 @@ from django.urls import reverse, reverse_lazy
from django.utils.decorators import method_decorator
from django.utils.functional import cached_property
from django.utils.http import quote
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from django.views.decorators.cache import never_cache
from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.generic import CreateView, DeleteView, TemplateView, UpdateView, View
@ -307,7 +305,7 @@ class ChooseDocumentKind(TemplateView):
class LoginView(auth_views.LoginView):
def get(self, request, *args, **kwargs):
if any(get_idps()):
if not 'next' in request.GET:
if 'next' not in request.GET:
return HttpResponseRedirect(resolve_url('mellon_login'))
return HttpResponseRedirect(
resolve_url('mellon_login') + '?next=' + quote(request.GET.get('next'))

View File

@ -3,8 +3,8 @@
{% block page-title %}Fargo{% endblock %}
{% block site-title %}Fargo{% endblock %}
{% block css %}
{{ block.super }}
<link rel="stylesheet" href="{% static "fargo/css/style.css" %}" />
{{ block.super }}
<link rel="stylesheet" href="{% static "fargo/css/style.css" %}" />
{% endblock %}
{% block logout-url %}{% url "auth_logout" %}{% endblock %}

View File

@ -42,42 +42,42 @@
</script>
<div class="cell">
<h2>{% if site_title %}{{ site_title }}{% else %}{% trans "Portfolio" %}{% endif %}</h2>
<div id="user-files">
{% render_table table "fargo/table.html" %}
<h2>{% if site_title %}{{ site_title }}{% else %}{% trans "Portfolio" %}{% endif %}</h2>
<div id="user-files">
{% render_table table "fargo/table.html" %}
{% if full %}
<div class="infonotice">
<p>
{% blocktrans count max_documents_per_user=max_documents_per_user trimmed %}
The limit of {{ max_documents_per_user }} document per user is reached.
You cannot add any more documents.
{% plural %}
The limit of {{ max_documents_per_user }} documents per user is reached.
You cannot add any more documents.
{% endblocktrans %}
</p>
{% if full %}
<div class="infonotice">
<p>
{% blocktrans count max_documents_per_user=max_documents_per_user trimmed %}
The limit of {{ max_documents_per_user }} document per user is reached.
You cannot add any more documents.
{% plural %}
The limit of {{ max_documents_per_user }} documents per user is reached.
You cannot add any more documents.
{% endblocktrans %}
</p>
</div>
{% else %}
<form id="send-file" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.non_field_errors }}
{{ form.content.errors }}
<div style="display: none">
{{ form.as_p }}
<input type="submit" name="submit" value="Upload">
</div>
<div class="invalid-file-error" style="display: none">
<p>
{% blocktrans with max_size_mb=max_document_size|filesizeformat %}
Error: an uploaded document can't exceed {{ max_size_mb }}.
{% endblocktrans %}
</p>
<p>{% trans "Please try again with a smaller document." %}</p>
</div>
<button>{% trans "Upload a new document" %}</button>
</form>
{% endif %}
</div>
{% else %}
<form id="send-file" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.non_field_errors }}
{{ form.content.errors }}
<div style="display: none">
{{ form.as_p }}
<input type="submit" name="submit" value="Upload">
</div>
<div class="invalid-file-error" style="display: none">
<p>
{% blocktrans with max_size_mb=max_document_size|filesizeformat %}
Error: an uploaded document can't exceed {{ max_size_mb }}.
{% endblocktrans %}
</p>
<p>{% trans "Please try again with a smaller document." %}</p>
</div>
<button>{% trans "Upload a new document" %}</button>
</form>
{% endif %}
</div>
</div>
{% endblock %}

View File

@ -5,20 +5,20 @@
{% block bodyclasses %}fargo-popup fargo-pick-popup{% endblock %}
{% block content %}
{% render_table table "fargo/pick_table.html" %}
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.non_field_errors }}
{{ form.content.errors }}
<div style="display: none">
{% render_table table "fargo/pick_table.html" %}
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.non_field_errors }}
{{ form.content.errors }}
<div style="display: none">
{{ form.as_p }}
</div>
</form>
<script type="text/javascript">
$(function() {
$('table').on('click', 'tbody tr', function() {
$(this).find('form').submit();
});
</div>
</form>
<script type="text/javascript">
$(function() {
$('table').on('click', 'tbody tr', function() {
$(this).find('form').submit();
});
</script>
});
</script>
{% endblock %}

View File

@ -2,8 +2,8 @@
{% load django_tables2 i18n %}
{% block action-column %}
<form method="post" action="{% url 'pick' pk=row.record.pk %}{% querystring %}">
{% csrf_token %}
<button class="pick-button">{% trans "Pick" %}</button>
</form>
<form method="post" action="{% url 'pick' pk=row.record.pk %}{% querystring %}">
{% csrf_token %}
<button class="pick-button">{% trans "Pick" %}</button>
</form>
{% endblock %}

View File

@ -24,40 +24,40 @@
{% block table.tbody.row %}
<tr class="{{ forloop.counter|divisibleby:2|yesno:"even,odd" }} {{row.record.css_classes}}"
data-url="{{row.record.get_download_url}}"
> {# avoid cycle for Django 1.2-1.6 compatibility #}
> {# avoid cycle for Django 1.2-1.6 compatibility #}
<td class="title">
{{ row.record }}
{{ row.record }}
</td>
{% for column, cell in row.items %}
<td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td>
{% endfor %}
{% with thumbnail=row.record.thumbnail_image %}
<td class="thumbnail desktop-only" rowspan={{ row.record.description|yesno:"2,1" }}>
{% if thumbnail %}
<img src="{{ thumbnail.src }}" height="{{ thumbnail.height }}" width="{{ thumbnail.width }}"/>
{% endif %}
</td>
{% endwith %}
{% with thumbnail=row.record.thumbnail_image %}
<td class="thumbnail desktop-only" rowspan={{ row.record.description|yesno:"2,1" }}>
{% if thumbnail %}
<img src="{{ thumbnail.src }}" height="{{ thumbnail.height }}" width="{{ thumbnail.width }}"/>
{% endif %}
</td>
{% endwith %}
<td class="action-column" rowspan={{ row.record.description|yesno:"2,1" }}>
{% block action-column %}
{% if table.context.include_edit_link or include_edit_link %}<!-- dj11 compatibility -->
<a class="icon-edit" rel="popup" data-selector="#edit-form" href="{% url 'edit' pk=row.record.pk %}"></a>
{% endif %}
{% if row.record.deletable_by_user %}
<a class="icon-remove" rel="popup" data-selector="#delete-form" href="{% url 'delete' pk=row.record.pk %}"></a>
{% endif %}
{% if table.context.include_edit_link or include_edit_link %}<!-- dj11 compatibility -->
<a class="icon-edit" rel="popup" data-selector="#edit-form" href="{% url 'edit' pk=row.record.pk %}"></a>
{% endif %}
{% if row.record.deletable_by_user %}
<a class="icon-remove" rel="popup" data-selector="#delete-form" href="{% url 'delete' pk=row.record.pk %}"></a>
{% endif %}
{% endblock %}
</td>
</td>
</tr>
{% if row.record.description %}
<tr class="{{ forloop.counter|divisibleby:2|yesno:"even,odd" }} description-row">
<tr class="{{ forloop.counter|divisibleby:2|yesno:"even,odd" }} description-row">
<td class="description" colspan={{table.columns|length|add:"1"}}>{{row.record.description}}</td>
</tr>
</tr>
{% endif %}
{% endblock table.tbody.row %}
{% block table.tbody.empty_text %}
<tr class="empty"><td colspan="{{ table.columns|length|add:3 }}">{{ table.empty_text }}</td></tr>
<tr class="empty"><td colspan="{{ table.columns|length|add:3 }}">{{ table.empty_text }}</td></tr>
{% endblock %}
{% block pagination.cardinality %}

View File

@ -2,14 +2,14 @@
{% load i18n %}
{% block content %}
<form method="post" id="delete-form">
{% csrf_token %}
<p>
{% blocktrans %}Are you sure you want to delete "{{ object }}"?{% endblocktrans %}
</p>
<div class="buttons">
<button class="delete-button">{% trans 'Delete' %}</button>
<a class="cancel" href="{% url 'home' %}">{% trans 'Cancel' %}</a>
</div>
</form>
<form method="post" id="delete-form">
{% csrf_token %}
<p>
{% blocktrans %}Are you sure you want to delete "{{ object }}"?{% endblocktrans %}
</p>
<div class="buttons">
<button class="delete-button">{% trans 'Delete' %}</button>
<a class="cancel" href="{% url 'home' %}">{% trans 'Cancel' %}</a>
</div>
</form>
{% endblock %}

View File

@ -2,16 +2,16 @@
{% load i18n %}
{% block content %}
<div id="appbar">
<h2>{% trans "Edit" %}</h2>
</div>
<form action="{% url 'edit' pk=object.pk %}" method="post" id="edit-form">
{% csrf_token %}
{{form.as_p}}
<div class="buttons">
<button class="submit-button">{% trans "Save" %}</button>
<a class="cancel" href="{% url 'home' %}">{% trans 'Cancel' %}</a>
<div id="appbar">
<h2>{% trans "Edit" %}</h2>
</div>
</form>
<form action="{% url 'edit' pk=object.pk %}" method="post" id="edit-form">
{% csrf_token %}
{{form.as_p}}
<div class="buttons">
<button class="submit-button">{% trans "Save" %}</button>
<a class="cancel" href="{% url 'home' %}">{% trans 'Cancel' %}</a>
</div>
</form>
{% endblock %}

View File

@ -3,7 +3,7 @@
{% block extra_head %}
<link rel="stylesheet" type="text/css" media="all"
href="{% xstatic 'jquery-ui' 'themes/smoothness/jquery-ui.min.css' %}"/>
href="{% xstatic 'jquery-ui' 'themes/smoothness/jquery-ui.min.css' %}"/>
<script src="{% xstatic 'jquery-ui' 'jquery-ui.min.js' %}"></script>
<script src="{% static "fargo/js/datepicker-fr.js" %}"></script>
<script src="{% static 'fargo/js/fargo.js' %}"></script>
@ -12,15 +12,15 @@
{% block bodyclasses %}fargo-popup fargo-pick-popup{% endblock %}
{% block content %}
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<div class="buttons">
<button name="submit">{% trans "Validate" %}</button>
<button name="cancel">{% trans "Cancel" %}</button>
</div>
</form>
<script>
$('#id_start, #id_end').datepicker($.datepicker.regional["fr"]);
</script>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<div class="buttons">
<button name="submit">{% trans "Validate" %}</button>
<button name="cancel">{% trans "Cancel" %}</button>
</div>
</form>
<script>
$('#id_start, #id_end').datepicker($.datepicker.regional["fr"]);
</script>
{% endblock %}

View File

@ -15,8 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.urls import include, path, re_path
from .fargo.api_views import push_document, recent_documents
from .fargo.views import (
@ -36,30 +36,30 @@ from .fargo.views import (
)
urlpatterns = [
url(r'^$', home, name='home'),
url(r'^pick/$', pick_list, name='list_to_pick'),
url(r'^jsonp/$', jsonp, name='jsonp'),
url(r'^json/$', json, name='json'),
url(r'^(?P<pk>\d+)/edit/$', edit, name='edit'),
url(r'^(?P<pk>\d+)/delete/$', delete, name='delete'),
url(r'^(?P<pk>\d+)/pick/$', pick, name='pick'),
url(r'^(?P<pk>\d+)/download/(?P<filename>[^/]*)$', download, name='download'),
url(r'^(?P<pk>\d+)/thumbnail/(?P<filename>[^/]*)$', thumbnail, name='thumbnail'),
url(r'^upload/$', upload, name='upload'),
url(r'^remote-download/(?P<filename>[^/]*)$', remote_download, name='remote_download'),
url(r'^admin/', admin.site.urls),
url(r'^login/$', login, name='auth_login'),
url(r'^logout/$', logout, name='auth_logout'),
url(r'^api/documents/push/$', push_document, name='fargo-api-push-document'),
url(r'^api/documents/recently-added/$', recent_documents),
path('', home, name='home'),
path('pick/', pick_list, name='list_to_pick'),
path('jsonp/', jsonp, name='jsonp'),
path('json/', json, name='json'),
path('<int:pk>/edit/', edit, name='edit'),
path('<int:pk>/delete/', delete, name='delete'),
path('<int:pk>/pick/', pick, name='pick'),
re_path(r'^(?P<pk>\d+)/download/(?P<filename>[^/]*)$', download, name='download'),
re_path(r'^(?P<pk>\d+)/thumbnail/(?P<filename>[^/]*)$', thumbnail, name='thumbnail'),
path('upload/', upload, name='upload'),
re_path(r'^remote-download/(?P<filename>[^/]*)$', remote_download, name='remote_download'),
re_path(r'^admin/', admin.site.urls),
path('login/', login, name='auth_login'),
path('logout/', logout, name='auth_logout'),
path('api/documents/push/', push_document, name='fargo-api-push-document'),
path('api/documents/recently-added/', recent_documents),
]
if settings.DEBUG and 'debug_toolbar' in settings.INSTALLED_APPS:
import debug_toolbar
urlpatterns = [
url(r'^__debug__/', include(debug_toolbar.urls)),
path('__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
if 'mellon' in settings.INSTALLED_APPS:
urlpatterns.append(url(r'^accounts/mellon/', include('mellon.urls')))
urlpatterns.append(path('accounts/mellon/', include('mellon.urls')))

View File

@ -1,16 +0,0 @@
#!/bin/sh
set -e -x
env
if [ -f /var/lib/jenkins/pylint.django.rc ]; then
PYLINT_RC=/var/lib/jenkins/pylint.django.rc
elif [ -f pylint.django.rc ]; then
PYLINT_RC=pylint.django.rc
else
echo No pylint RC found
exit 0
fi
test -f pylint.out && cp pylint.out pylint.out.prev
pylint -f parseable --rcfile ${PYLINT_RC} "$@" | tee pylint.out || /bin/true
test -f pylint.out.prev && (diff pylint.out.prev pylint.out | grep '^[><]' | grep .py) || /bin/true

7
test-requirements.txt Normal file
View File

@ -0,0 +1,7 @@
psycopg2-binary
django-webtest
pytest
pytest-cov
pytest-random
pytest-django
pytest-freezer

View File

@ -1,4 +1,3 @@
# fargo - document box
# Copyright (C) 2016-2019 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
@ -29,6 +28,12 @@ class WebTestMixin(django_webtest.WebTestMixin):
csrf_checks = False
@pytest.fixture(autouse=True)
def media(settings, tmpdir):
settings.MEDIA_ROOT = str(tmpdir.mkdir('media'))
return settings.MEDIA_ROOT
@pytest.fixture
def app(request):
wtm = WebTestMixin()

View File

@ -14,22 +14,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import tempfile
DEBUG = False
ALLOWED_HOSTS = ['*']
LANGUAGE_CODE = 'en-US'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.' + os.environ.get('DB_ENGINE', 'sqlite3'),
'NAME': 'fargo.sqlite3',
'TEST': {
'NAME': 'fargo-test-' + os.environ.get('DB_ENGINE', 'sqlite3'),
},
}
}
MEDIA_ROOT = tempfile.mkdtemp('fargo-test')
DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'fargo'}}

View File

@ -17,10 +17,9 @@
import base64
import pytest
from django.utils.http import urlencode
from test_manager import login
from fargo.fargo import models, utils
from fargo.fargo import models
pytestmark = pytest.mark.django_db

45
tox.ini
View File

@ -1,39 +1,36 @@
[tox]
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/fargo/{env:BRANCH_NAME:}
envlist =
py3-dj32-black-coverage-pylint
py3-dj22
envlist = py3,codestyle
[testenv]
usedevelop = True
whitelist_externals =
/bin/mv
setenv =
DB_ENGINE=postgresql_psycopg2
DJANGO_SETTINGS_MODULE=fargo.settings
FARGO_SETTINGS_FILE=tests/settings.py
SETUPTOOLS_USE_DISTUTILS=stdlib
coverage: COVERAGE=--junitxml=junit-{envname}.xml --random --cov-report xml --cov-report html --cov=fargo/
JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml}
COVERAGE={tty::--cov --cov-append --cov-report xml --cov-report html --cov-context=test --cov-config=tox.ini}
deps =
pytest
psycopg2<2.9
pylint<3
astroid<3
pylint-django
dj22: django>=2.2,<2.3
dj32: django>=3.2,<3.3
django>=3.2,<3.3
django-filter>=2.4,<23.2
django-tables2==2.4.1
pytest-cov
pytest-random
pytest-mock
pytest-django
pytest-freezegun
django-webtest
WebTest
mock<4
-r test-requirements.txt
commands =
py.test {env:JUNIT:} {env:COVERAGE:} {posargs:tests/}
[testenv:codestyle]
skip_install = true
deps =
pre-commit
commands =
py.test {env:COVERAGE:} {posargs:tests/}
pylint: ./pylint.sh fargo/
black: pre-commit run black --all-files --show-diff-on-failure
pre-commit run --all-files --show-diff-on-failure
[coverage:run]
source =
fargo
tests
branch = True
[coverage:html]
show_contexts = True