diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bbf59cb..8872da0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,10 +7,10 @@ repos: - id: pyupgrade args: ['--keep-percent-format', '--py37-plus'] - repo: https://github.com/adamchainz/django-upgrade - rev: 1.10.0 + rev: 1.13.0 hooks: - id: django-upgrade - args: ['--target-version', '2.2'] + args: ['--target-version', '3.2'] - repo: https://github.com/psf/black rev: 22.3.0 hooks: diff --git a/README b/README index 698ed46..9b9db3f 100644 --- a/README +++ b/README @@ -194,7 +194,7 @@ djhtml is used to automatically indent html files, using those parameters: django-upgrade is used to automatically upgrade Django syntax, using those parameters: - django-upgrade --target-version 2.2 + django-upgrade --target-version 3.2 There is .pre-commit-config.yaml to use pre-commit to automatically run these tools before commits. (execute `pre-commit install` to install the git hook.) diff --git a/hobo/agent/authentic2/__init__.py b/hobo/agent/authentic2/__init__.py index a524709..e69de29 100644 --- a/hobo/agent/authentic2/__init__.py +++ b/hobo/agent/authentic2/__init__.py @@ -1 +0,0 @@ -default_app_config = 'hobo.agent.authentic2.apps.Authentic2AgentConfig' diff --git a/hobo/agent/authentic2/management/commands/hobo_deploy.py b/hobo/agent/authentic2/management/commands/hobo_deploy.py index 2dc4286..2f7bd47 100644 --- a/hobo/agent/authentic2/management/commands/hobo_deploy.py +++ b/hobo/agent/authentic2/management/commands/hobo_deploy.py @@ -15,7 +15,7 @@ from django.contrib.auth import get_user_model from django.contrib.contenttypes.models import ContentType from django.core import serializers from django.utils.translation import activate -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from tenant_schemas.utils import tenant_context from hobo.agent.authentic2.provisionning import Provisionning diff --git a/hobo/agent/authentic2/provisionning.py b/hobo/agent/authentic2/provisionning.py index 231ddca..3e9bbb0 100644 --- a/hobo/agent/authentic2/provisionning.py +++ b/hobo/agent/authentic2/provisionning.py @@ -15,7 +15,7 @@ from django.conf import settings from django.contrib.auth import get_user_model from django.db import connection, transaction from django.urls import reverse -from django.utils.encoding import force_text +from django.utils.encoding import force_str from hobo.agent.common import notify_agents from hobo.signature import sign_url @@ -141,7 +141,7 @@ class Provisionning(threading.local): tuple(allowed_technical_roles_prefixes) ) - issuer = force_text(self.get_entity_id()) + issuer = force_str(self.get_entity_id()) if mode == 'provision': def user_to_json(ou, service, user, user_roles): @@ -245,7 +245,7 @@ class Provisionning(threading.local): continue logger.info( 'provisionning users %s to %s', - ', '.join(map(force_text, users)), + ', '.join(map(force_str, users)), ', '.join(audience), ) self.notify_agents( @@ -264,7 +264,7 @@ class Provisionning(threading.local): elif users: audience = [audience for ou in ous.keys() for s, audience in self.get_audience(ou)] logger.info( - 'deprovisionning users %s from %s', ', '.join(map(force_text, users)), ', '.join(audience) + 'deprovisionning users %s from %s', ', '.join(map(force_str, users)), ', '.join(audience) ) self.notify_agents( { diff --git a/hobo/agent/common/management/commands/hobo_deploy.py b/hobo/agent/common/management/commands/hobo_deploy.py index 8ff04fd..940d2e2 100644 --- a/hobo/agent/common/management/commands/hobo_deploy.py +++ b/hobo/agent/common/management/commands/hobo_deploy.py @@ -9,7 +9,7 @@ import requests from django.conf import settings from django.core.management import call_command, get_commands from django.core.management.base import BaseCommand, CommandError -from django.utils.encoding import force_text +from django.utils.encoding import force_str from tenant_schemas.utils import tenant_context from hobo.multitenant.middleware import TenantMiddleware, TenantNotFound @@ -23,7 +23,7 @@ def replace_file(path, content): dirname = os.path.dirname(path) fd, temp = tempfile.mkstemp(dir=dirname, prefix='.tmp-' + os.path.basename(path) + '-') f = os.fdopen(fd, 'w') - f.write(force_text(content)) + f.write(force_str(content)) f.flush() os.fsync(f.fileno()) f.close() @@ -32,7 +32,7 @@ def replace_file(path, content): class Command(BaseCommand): early_secondary_exit = True - requires_system_checks = False + requires_system_checks = [] me = None def add_arguments(self, parser): diff --git a/hobo/agent/common/management/commands/hobo_notify.py b/hobo/agent/common/management/commands/hobo_notify.py index ea62d29..409d9b5 100644 --- a/hobo/agent/common/management/commands/hobo_notify.py +++ b/hobo/agent/common/management/commands/hobo_notify.py @@ -29,7 +29,7 @@ logger = logging.getLogger(__name__) class Command(BaseCommand, NotificationProcessing): - requires_system_checks = False + requires_system_checks = [] def add_arguments(self, parser): parser.add_argument('notification', metavar='NOTIFICATION', type=str) diff --git a/hobo/agent/common/models.py b/hobo/agent/common/models.py index de69f7d..5cc80c2 100644 --- a/hobo/agent/common/models.py +++ b/hobo/agent/common/models.py @@ -1,7 +1,8 @@ from django.conf import settings from django.contrib.auth.models import Group -from django.contrib.postgres.fields import ArrayField, JSONField +from django.contrib.postgres.fields import ArrayField from django.db import models +from django.db.models import JSONField class Role(Group): diff --git a/hobo/agent/hobo/__init__.py b/hobo/agent/hobo/__init__.py index e61b19d..e69de29 100644 --- a/hobo/agent/hobo/__init__.py +++ b/hobo/agent/hobo/__init__.py @@ -1 +0,0 @@ -default_app_config = 'hobo.agent.hobo.apps.HoboAgentConfig' diff --git a/hobo/applications/forms.py b/hobo/applications/forms.py index 4796cf1..3bb0588 100644 --- a/hobo/applications/forms.py +++ b/hobo/applications/forms.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from hobo.applications.models import Application diff --git a/hobo/applications/models.py b/hobo/applications/models.py index 8005c1b..53b4895 100644 --- a/hobo/applications/models.py +++ b/hobo/applications/models.py @@ -23,12 +23,12 @@ import traceback import urllib.parse from django.conf import settings -from django.contrib.postgres.fields import JSONField from django.core.files.base import ContentFile from django.db import connection, models +from django.db.models import JSONField from django.utils.text import slugify from django.utils.timezone import now -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from hobo.environment.utils import get_installed_services diff --git a/hobo/applications/views.py b/hobo/applications/views.py index 8fe42f2..0bcd6b1 100644 --- a/hobo/applications/views.py +++ b/hobo/applications/views.py @@ -26,7 +26,7 @@ from django.shortcuts import get_object_or_404 from django.urls import reverse, reverse_lazy from django.utils.text import slugify from django.utils.timezone import now -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.views.generic import DetailView, FormView, ListView, TemplateView from django.views.generic.edit import CreateView, DeleteView, UpdateView diff --git a/hobo/debug/forms.py b/hobo/debug/forms.py index 16577ee..a8ba01d 100644 --- a/hobo/debug/forms.py +++ b/hobo/debug/forms.py @@ -17,7 +17,7 @@ from django import forms from django.core.exceptions import ValidationError from django.core.validators import validate_ipv46_address -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ def validate_space_separated_ips(value): diff --git a/hobo/deploy/__init__.py b/hobo/deploy/__init__.py index 3d3a59a..e69de29 100644 --- a/hobo/deploy/__init__.py +++ b/hobo/deploy/__init__.py @@ -1,27 +0,0 @@ -# hobo - portal to configure and deploy applications -# Copyright (C) 2015 Entr'ouvert -# -# This program is free software: you can redistribute it and/or modify it -# under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -import django.apps - - -class AppConfig(django.apps.AppConfig): - name = 'hobo.deploy' - - def ready(self): - from . import signals - - -default_app_config = 'hobo.deploy.AppConfig' diff --git a/hobo/deploy/apps.py b/hobo/deploy/apps.py new file mode 100644 index 0000000..6cef39f --- /dev/null +++ b/hobo/deploy/apps.py @@ -0,0 +1,24 @@ +# hobo - portal to configure and deploy applications +# Copyright (C) 2015 Entr'ouvert +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import django.apps + + +class AppConfig(django.apps.AppConfig): + name = 'hobo.deploy' + + def ready(self): + from . import signals diff --git a/hobo/emails/forms.py b/hobo/emails/forms.py index 1e64a27..ec062b3 100644 --- a/hobo/emails/forms.py +++ b/hobo/emails/forms.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from django import forms from django.core.validators import validate_email -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from hobo.emails.validators import validate_email_address, validate_email_domain, validate_email_spf diff --git a/hobo/emails/validators.py b/hobo/emails/validators.py index eb66893..787d40c 100644 --- a/hobo/emails/validators.py +++ b/hobo/emails/validators.py @@ -22,7 +22,7 @@ import dns.resolver from django.conf import settings from django.core.exceptions import ValidationError from django.utils.encoding import force_bytes -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from hobo.environment.utils import get_operational_services diff --git a/hobo/emails/views.py b/hobo/emails/views.py index 69b4765..e6eb967 100644 --- a/hobo/emails/views.py +++ b/hobo/emails/views.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from django.conf import settings -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.views.generic import TemplateView from hobo.environment.forms import VariablesFormMixin diff --git a/hobo/environment/forms.py b/hobo/environment/forms.py index 31d21e0..02799d4 100644 --- a/hobo/environment/forms.py +++ b/hobo/environment/forms.py @@ -19,7 +19,7 @@ from django.conf import settings from django.contrib import messages from django.http import HttpResponseRedirect from django.template.defaultfilters import slugify -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .models import Authentic, BiJoe, Chrono, Combo, Fargo, Hobo, Lingo, Passerelle, Variable, Wcs, Welco from .utils import get_variable diff --git a/hobo/environment/models.py b/hobo/environment/models.py index 33a849d..d41cc4d 100644 --- a/hobo/environment/models.py +++ b/hobo/environment/models.py @@ -25,15 +25,15 @@ import requests from django.conf import settings from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation from django.contrib.contenttypes.models import ContentType -from django.contrib.postgres.fields import JSONField from django.core.cache import cache from django.core.exceptions import ValidationError from django.core.validators import URLValidator from django.db import models +from django.db.models import JSONField from django.utils.crypto import get_random_string -from django.utils.encoding import force_text +from django.utils.encoding import force_str from django.utils.timezone import now -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from .utils import Zone, get_installed_services, get_local_key @@ -188,7 +188,7 @@ class ServiceBase(models.Model): if self.legacy_urls: as_dict['legacy_urls'] = self.legacy_urls as_dict['service-id'] = self.Extra.service_id - as_dict['service-label'] = force_text(self.Extra.service_label) + as_dict['service-label'] = force_str(self.Extra.service_label) as_dict['variables'] = {v.name: v.json for v in self.variables.all()} as_dict['secondary'] = self.secondary if self.get_saml_sp_metadata_url(): diff --git a/hobo/environment/utils.py b/hobo/environment/utils.py index 76614db..3fcdb79 100644 --- a/hobo/environment/utils.py +++ b/hobo/environment/utils.py @@ -22,7 +22,7 @@ from django.conf import settings from django.core.management.base import CommandError from django.db import connection, transaction from django.urls import reverse -from django.utils.encoding import force_text +from django.utils.encoding import force_str from hobo.middleware.utils import StoreRequestMiddleware from hobo.multitenant.settings_loaders import KnownServices @@ -48,7 +48,7 @@ def get_operational_services(): def get_local_key(url): - secret1 = force_text(settings.SECRET_KEY) + secret1 = force_str(settings.SECRET_KEY) secret2 = url return KnownServices.shared_secret(secret1, secret2)[:40] diff --git a/hobo/environment/views.py b/hobo/environment/views.py index 713c6b2..bc9372e 100644 --- a/hobo/environment/views.py +++ b/hobo/environment/views.py @@ -23,8 +23,8 @@ from django.contrib.contenttypes.models import ContentType from django.http import Http404, HttpResponse, HttpResponseRedirect, JsonResponse from django.shortcuts import get_object_or_404 from django.urls import reverse_lazy -from django.utils.encoding import force_text -from django.utils.translation import ugettext_lazy as _ +from django.utils.encoding import force_str +from django.utils.translation import gettext_lazy as _ from django.views.generic import View from django.views.generic.base import TemplateView from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView @@ -213,7 +213,7 @@ class ImportView(FormView): def form_valid(self, form): try: - parameters_json = json.loads(force_text(self.request.FILES['parameters_json'].read())) + parameters_json = json.loads(force_str(self.request.FILES['parameters_json'].read())) except ValueError: form.add_error('parameters_json', _('File is not in the expected JSON format.')) return self.form_invalid(form) diff --git a/hobo/maintenance/forms.py b/hobo/maintenance/forms.py index b265e46..f15a800 100644 --- a/hobo/maintenance/forms.py +++ b/hobo/maintenance/forms.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class MaintenanceForm(forms.Form): diff --git a/hobo/matomo/forms.py b/hobo/matomo/forms.py index 45bfd67..2187c1d 100644 --- a/hobo/matomo/forms.py +++ b/hobo/matomo/forms.py @@ -17,7 +17,7 @@ import xml.etree.ElementTree as etree from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class SettingsForm(forms.Form): diff --git a/hobo/middleware/common.py b/hobo/middleware/common.py index 5572d42..b19cad2 100644 --- a/hobo/middleware/common.py +++ b/hobo/middleware/common.py @@ -1,7 +1,7 @@ import django from django.http import JsonResponse from django.middleware.common import CommonMiddleware -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class HoboCommonMiddleware(CommonMiddleware): diff --git a/hobo/middleware/cors.py b/hobo/middleware/cors.py index 3050d37..6678fc9 100644 --- a/hobo/middleware/cors.py +++ b/hobo/middleware/cors.py @@ -14,7 +14,7 @@ class CORSMiddleware(MiddlewareMixin): view/exception middleware along with the requested view; it will call any response middlewares """ - if request.method == 'OPTIONS' and "HTTP_ACCESS_CONTROL_REQUEST_METHOD" in request.META: + if request.method == 'OPTIONS' and "access-control-request-method" in request.headers: response = HttpResponse() return response return None diff --git a/hobo/middleware/maintenance.py b/hobo/middleware/maintenance.py index f41f502..2b2fa83 100644 --- a/hobo/middleware/maintenance.py +++ b/hobo/middleware/maintenance.py @@ -18,7 +18,7 @@ from ipaddress import ip_address, ip_network from django.conf import settings from django.template.response import TemplateResponse -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ def pass_through(request): diff --git a/hobo/middleware/xforwardedfor.py b/hobo/middleware/xforwardedfor.py index a996e2f..c9c0369 100644 --- a/hobo/middleware/xforwardedfor.py +++ b/hobo/middleware/xforwardedfor.py @@ -10,7 +10,7 @@ class XForwardedForMiddleware(MiddlewareMixin): def process_request(self, request): if getattr(settings, 'USE_X_FORWARDED_FOR', False): - if 'HTTP_X_FORWARDED_FOR' in request.META: + if 'x-forwarded-for' in request.headers: ip = request.headers.get('X-Forwarded-For', '').split(",")[0].strip() if ip: request.META['REMOTE_ADDR'] = ip diff --git a/hobo/multitenant/__init__.py b/hobo/multitenant/__init__.py index 2dd1126..8070565 100644 --- a/hobo/multitenant/__init__.py +++ b/hobo/multitenant/__init__.py @@ -1,5 +1,3 @@ -default_app_config = 'hobo.multitenant.apps.MultitenantAppConfig' - # import the context_processors module so it gets to compute the versions hash # early on. from hobo import context_processors diff --git a/hobo/multitenant/management/commands/tenant_command.py b/hobo/multitenant/management/commands/tenant_command.py index 2142ff7..2df0d5a 100644 --- a/hobo/multitenant/management/commands/tenant_command.py +++ b/hobo/multitenant/management/commands/tenant_command.py @@ -13,7 +13,7 @@ from django.core.exceptions import ImproperlyConfigured from django.core.management import call_command, get_commands, load_command_class from django.core.management.base import BaseCommand, CommandError, SystemCheckError, handle_default_options from django.db import connection, connections -from django.utils.encoding import force_text +from django.utils.encoding import force_str from hobo.multitenant.management.commands import InteractiveTenantOption from hobo.multitenant.middleware import TenantMiddleware @@ -26,12 +26,12 @@ def exception_to_text(e): pass try: - return force_text(str(e), errors='ignore') + return force_str(str(e), errors='ignore') except Exception: pass try: - return force_text(repr(e), errors='ignore') + return force_str(repr(e), errors='ignore') except Exception: pass diff --git a/hobo/profile/forms.py b/hobo/profile/forms.py index e41a15a..7c94328 100644 --- a/hobo/profile/forms.py +++ b/hobo/profile/forms.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class EditFullNameTemplateForm(forms.Form): diff --git a/hobo/profile/models.py b/hobo/profile/models.py index 24daedb..5fa5a7c 100644 --- a/hobo/profile/models.py +++ b/hobo/profile/models.py @@ -16,7 +16,7 @@ from django.core.validators import RegexValidator from django.db import models -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ validate_attribute_name = RegexValidator( r'^[a-z][a-z0-9_]*\Z', diff --git a/hobo/profile/views.py b/hobo/profile/views.py index 386a8e4..b04283e 100644 --- a/hobo/profile/views.py +++ b/hobo/profile/views.py @@ -16,7 +16,7 @@ from django.shortcuts import redirect from django.urls import reverse, reverse_lazy -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.views.generic import CreateView, ListView, RedirectView, TemplateView, UpdateView from hobo.deploy.signals import notify_agents diff --git a/hobo/provisionning/middleware.py b/hobo/provisionning/middleware.py index 200da18..7588409 100644 --- a/hobo/provisionning/middleware.py +++ b/hobo/provisionning/middleware.py @@ -23,7 +23,7 @@ from django.conf import settings from django.db import connection from django.http import HttpResponseBadRequest, HttpResponseForbidden, JsonResponse from django.utils.deprecation import MiddlewareMixin -from django.utils.encoding import force_bytes, force_text +from django.utils.encoding import force_bytes, force_str from hobo.provisionning.utils import NotificationProcessing from hobo.rest_authentication import PublikAuthentication, PublikAuthenticationFailed @@ -46,7 +46,7 @@ class ProvisionningMiddleware(MiddlewareMixin, NotificationProcessing): return HttpResponseForbidden() try: - notification = json.loads(force_text(request.body)) + notification = json.loads(force_str(request.body)) except ValueError: return HttpResponseBadRequest() if not isinstance(notification, dict) or 'objects' not in notification: diff --git a/hobo/seo/forms.py b/hobo/seo/forms.py index d54f18b..007d8f4 100644 --- a/hobo/seo/forms.py +++ b/hobo/seo/forms.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class RobotsTxtForm(forms.Form): diff --git a/hobo/settings.py b/hobo/settings.py index a6875be..027b0df 100644 --- a/hobo/settings.py +++ b/hobo/settings.py @@ -10,7 +10,7 @@ and to disable DEBUG mode in production. import os from django.conf import global_settings -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(__file__)) diff --git a/hobo/sms/forms.py b/hobo/sms/forms.py index 08c97e2..d5b8185 100644 --- a/hobo/sms/forms.py +++ b/hobo/sms/forms.py @@ -16,7 +16,7 @@ from django import forms from django.core.exceptions import ValidationError from django.core.validators import RegexValidator -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from hobo.utils import TemplateError, get_templated_url diff --git a/hobo/sms/views.py b/hobo/sms/views.py index bcbf533..dd057c1 100644 --- a/hobo/sms/views.py +++ b/hobo/sms/views.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from django.conf import settings -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.views.generic import TemplateView from hobo.environment.forms import VariablesFormMixin diff --git a/hobo/theme/forms.py b/hobo/theme/forms.py index b539573..351ddcf 100644 --- a/hobo/theme/forms.py +++ b/hobo/theme/forms.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from django import forms -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ class ThemeOptionsForm(forms.Form): diff --git a/hobo/theme/views.py b/hobo/theme/views.py index 5f238b3..ca44d5c 100644 --- a/hobo/theme/views.py +++ b/hobo/theme/views.py @@ -19,7 +19,7 @@ import random from django.contrib import messages from django.urls import reverse -from django.utils.translation import ugettext as _ +from django.utils.translation import gettext as _ from django.views.generic import RedirectView, TemplateView from hobo.environment.forms import VariablesFormMixin diff --git a/hobo/urls.py b/hobo/urls.py index 6079f0c..a3d5a33 100644 --- a/hobo/urls.py +++ b/hobo/urls.py @@ -56,12 +56,12 @@ urlpatterns += [ path('logout/', logout, name='logout'), path('login/', login, name='auth_login'), path('login/local/', login_local), # to be used as backup, in case of idp down - re_path(r'^accounts/mellon/', include('mellon.urls')), + path('accounts/mellon/', include('mellon.urls')), ] if settings.DEBUG and 'debug_toolbar' in settings.INSTALLED_APPS: import debug_toolbar # pylint: disable=import-error urlpatterns = [ - re_path(r'^__debug__/', include(debug_toolbar.urls)), + path('__debug__/', include(debug_toolbar.urls)), ] + urlpatterns diff --git a/hobo/views.py b/hobo/views.py index 6817389..a7828e8 100644 --- a/hobo/views.py +++ b/hobo/views.py @@ -9,8 +9,8 @@ from django.core.exceptions import PermissionDenied from django.http import HttpResponse, HttpResponseRedirect, JsonResponse from django.shortcuts import resolve_url from django.urls import reverse -from django.utils.encoding import force_text -from django.utils.translation import ugettext as _ +from django.utils.encoding import force_str +from django.utils.translation import gettext as _ from django.views.generic import edit from django.views.generic.base import TemplateView @@ -89,7 +89,7 @@ def health_json(request): def menu_json(request): label = _('System') json_str = json.dumps( - [{'label': force_text(label), 'slug': 'system', 'url': request.build_absolute_uri(reverse('home'))}] + [{'label': force_str(label), 'slug': 'system', 'url': request.build_absolute_uri(reverse('home'))}] ) content_type = 'application/json' for variable in ('jsonpCallback', 'callback'): diff --git a/tests/test_emails.py b/tests/test_emails.py index ade42eb..3513463 100644 --- a/tests/test_emails.py +++ b/tests/test_emails.py @@ -9,7 +9,7 @@ from unittest import mock import dns.resolver import pytest from django.core.exceptions import ValidationError -from django.utils.encoding import force_text +from django.utils.encoding import force_str from dns import name from dns.rdtypes.ANY import MX, TXT from test_manager import login @@ -129,7 +129,7 @@ def test_invalid_address(client, admin_user): client.post('/login/', {'username': 'admin', 'password': 'password'}) response = client.post('/emails/', {'default_from_email': 'foobar'}) assert response.status_code == 200 - assert 'Enter a valid email address' in force_text(response.content) + assert 'Enter a valid email address' in force_str(response.content) def test_unkown_address(client, admin_user, dns_resolver, smtp_server, settings): @@ -137,7 +137,7 @@ def test_unkown_address(client, admin_user, dns_resolver, smtp_server, settings) client.post('/login/', {'username': 'admin', 'password': 'password'}) response = client.post('/emails/', {'default_from_email': 'john.doe@unknown.com'}) assert response.status_code == 200 - assert 'Email address not found' in force_text(response.content) + assert 'Email address not found' in force_str(response.content) def test_kown_address_nospf(client, admin_user, dns_resolver, smtp_server, settings): @@ -145,7 +145,7 @@ def test_kown_address_nospf(client, admin_user, dns_resolver, smtp_server, setti client.post('/login/', {'username': 'admin', 'password': 'password'}) response = client.post('/emails/', {'default_from_email': 'john.doe@example.com'}, follow=True) assert response.status_code == 200 - assert 'Emails settings have been updated. It will take a few seconds to be effective.' in force_text( + assert 'Emails settings have been updated. It will take a few seconds to be effective.' in force_str( response.content ) @@ -157,7 +157,7 @@ def test_spf_allow_all_mail(client, admin_user, dns_resolver, smtp_server, setti '/emails/', {'default_from_email': 'john.doe@example-spf-allow-all.com'}, follow=True ) assert response.status_code == 200 - assert 'Emails settings have been updated. It will take a few seconds to be effective.' in force_text( + assert 'Emails settings have been updated. It will take a few seconds to be effective.' in force_str( response.content ) @@ -168,7 +168,7 @@ def test_invalid_spf(client, admin_user, dns_resolver, smtp_server, settings): client.post('/login/', {'username': 'admin', 'password': 'password'}) response = client.post('/emails/', {'default_from_email': 'john.doe@example-invalid-spf.com'}) assert response.status_code == 200 - assert 'No suitable SPF record found' in force_text(response.content) + assert 'No suitable SPF record found' in force_str(response.content) def test_strict_nospf(client, admin_user, dns_resolver, smtp_server, monkeypatch, settings): @@ -178,7 +178,7 @@ def test_strict_nospf(client, admin_user, dns_resolver, smtp_server, monkeypatch client.post('/login/', {'username': 'admin', 'password': 'password'}) response = client.post('/emails/', {'default_from_email': 'john.doe@example.com'}, follow=True) assert response.status_code == 200 - assert 'No suitable SPF record found' in force_text(response.content) + assert 'No suitable SPF record found' in force_str(response.content) def test_valid_spf(client, admin_user, dns_resolver, smtp_server, settings): @@ -187,7 +187,7 @@ def test_valid_spf(client, admin_user, dns_resolver, smtp_server, settings): client.post('/login/', {'username': 'admin', 'password': 'password'}) response = client.post('/emails/', {'default_from_email': 'john.doe@example-spf.com'}, follow=True) assert response.status_code == 200 - assert 'Emails settings have been updated. It will take a few seconds to be effective.' in force_text( + assert 'Emails settings have been updated. It will take a few seconds to be effective.' in force_str( response.content ) @@ -200,7 +200,7 @@ def test_no_spf_validation(client, admin_user, dns_resolver, smtp_server, settin '/emails/', {'default_from_email': 'john.doe@example-invalid-spf.com'}, follow=True ) assert response.status_code == 200 - assert 'Emails settings have been updated. It will take a few seconds to be effective.' in force_text( + assert 'Emails settings have been updated. It will take a few seconds to be effective.' in force_str( response.content ) @@ -211,14 +211,14 @@ def test_sender_allowed_domains(client, admin_user, dns_resolver, smtp_server, s client.post('/login/', {'username': 'admin', 'password': 'password'}) response = client.post('/emails/', {'default_from_email': 'john.doe@example.com'}, follow=True) assert response.status_code == 200 - assert 'Domain example.com is not allowed' in force_text(response.content) - assert 'Emails settings have been updated.' not in force_text(response.content) + assert 'Domain example.com is not allowed' in force_str(response.content) + assert 'Emails settings have been updated.' not in force_str(response.content) settings.EMAIL_FROM_ALLOWED_DOMAINS = ['example.com', 'foo.bar'] response = client.post('/emails/', {'default_from_email': 'john.doe@example.com'}, follow=True) assert response.status_code == 200 - assert 'Emails settings have been updated.' in force_text(response.content) - assert 'Domain example.com is not allowed' not in force_text(response.content) + assert 'Emails settings have been updated.' in force_str(response.content) + assert 'Domain example.com is not allowed' not in force_str(response.content) settings.EMAIL_FROM_ALLOWED_DOMAINS = [] combo = Combo(base_url='https://example.org/test') @@ -227,21 +227,21 @@ def test_sender_allowed_domains(client, admin_user, dns_resolver, smtp_server, s response = client.post('/emails/', {'default_from_email': 'john.doe@example.org'}, follow=True) assert response.status_code == 200 - assert 'Emails settings have been updated.' in force_text(response.content) + assert 'Emails settings have been updated.' in force_str(response.content) response = client.post('/emails/', {'default_from_email': 'john.doe@example.com'}, follow=True) assert response.status_code == 200 - assert 'Domain example.com is not allowed' in force_text(response.content) + assert 'Domain example.com is not allowed' in force_str(response.content) response = client.post('/emails/', {'default_from_email': 'john.doe@brother.example.org'}, follow=True) assert response.status_code == 200 - assert 'Domain brother.example.org is not allowed' in force_text(response.content) + assert 'Domain brother.example.org is not allowed' in force_str(response.content) combo.base_url = 'https://www.example.com' combo.save() response = client.post('/emails/', {'default_from_email': 'john.doe@example.com'}, follow=True) assert response.status_code == 200 - assert 'Emails settings have been updated.' in force_text(response.content) + assert 'Emails settings have been updated.' in force_str(response.content) def test_emails_view(app, admin_user, dns_resolver, smtp_server, settings): diff --git a/tests/test_matomo_utils.py b/tests/test_matomo_utils.py index a6ce05a..e93cdba 100644 --- a/tests/test_matomo_utils.py +++ b/tests/test_matomo_utils.py @@ -3,7 +3,7 @@ from unittest import mock import pytest from django.test import override_settings -from django.utils.encoding import force_text +from django.utils.encoding import force_str from requests import Response from hobo.environment.models import Combo, Fargo, Hobo, Variable, Wcs @@ -727,7 +727,7 @@ def test_upgrade_user(mocked_post): def test_compute_cnil_acknowledgment_level(): """function use to inspect javascript content""" - warning_content = force_text(JAVASCRIPT_TAG) + warning_content = force_str(JAVASCRIPT_TAG) # can't find cookie's life time extension prevention assert compute_cnil_acknowledgment_level(warning_content) == 'good' diff --git a/tests_multitenant/test_agent_worker.py b/tests_multitenant/test_agent_worker.py index 44862b6..b852f5b 100644 --- a/tests_multitenant/test_agent_worker.py +++ b/tests_multitenant/test_agent_worker.py @@ -4,7 +4,7 @@ import os from unittest import mock import pytest -from django.utils.encoding import force_text +from django.utils.encoding import force_str from hobo.agent.worker import settings from hobo.agent.worker.services import deploy, notify @@ -106,7 +106,7 @@ def test_deploy(mocked_subprocess, mocked_exists): mock_calls = mocked_communicate.mock_calls assert len(mock_calls) == 4 for i in range(0, len(mock_calls)): - assert json.loads(force_text(mock_calls[0][2]['input'])) == ENVIRONMENT + assert json.loads(force_str(mock_calls[0][2]['input'])) == ENVIRONMENT mocked_opened.returncode = 1 with pytest.raises(RuntimeError, match='failed: '): @@ -151,7 +151,7 @@ def test_notify(mocked_subprocess, mocked_listdir, mocked_exists): # notification sent mock_calls = mocked_communicate.mock_calls assert len(mock_calls) == 1 - assert json.loads(force_text(mock_calls[0][2]['input']))['objects']['data'][0]['uuid'] == '12345' + assert json.loads(force_str(mock_calls[0][2]['input']))['objects']['data'][0]['uuid'] == '12345' mocked_opened.returncode = 1 with pytest.raises(RuntimeError, match='failed: '):