ajouter le hook double-quote-string-fixer (#79788) #67

Merged
vdeniaud merged 3 commits from wip/79788-single-quotes into main 2023-08-16 10:27:09 +02:00
39 changed files with 222 additions and 216 deletions

View File

@ -8,3 +8,5 @@ a107b7ef0e847882dcd6d5fc8c39e8feccc5705e
a5ec15a465840c454ed1d94547be821523fed473
# misc: apply django-upgrade (#69798)
5a6b5c5cd2efad36be91c39fc0cc9326cac7e6e6
# misc: apply double-quote-string-fixer (#79788)
1b3c26ba2a9f636f2f33484b44bfc5dbf2673a54

View File

@ -1,6 +1,10 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: double-quote-string-fixer
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:

View File

@ -38,8 +38,8 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('base_url', metavar='BASE_URL', nargs='?', type=str)
parser.add_argument('json_filename', metavar='JSON_FILENAME', nargs='?', type=str)
parser.add_argument('--ignore-timestamp', dest='ignore_timestamp', action="store_true", default=False)
parser.add_argument('--redeploy', action="store_true", default=False)
parser.add_argument('--ignore-timestamp', dest='ignore_timestamp', action='store_true', default=False)
parser.add_argument('--redeploy', action='store_true', default=False)
def handle(
self, base_url=None, json_filename=None, ignore_timestamp=None, redeploy=None, *args, **kwargs

View File

@ -12,7 +12,7 @@ class Command(BaseCommand):
obj.check_operational()
if int(kwargs.get('verbosity')) > 1:
if obj.is_operational():
print("%s is operational" % obj.title)
print('%s is operational' % obj.title)
else:
print(self.style.NOTICE('%s is NOT operational' % obj.title))
if obj.last_operational_success_timestamp:

View File

@ -42,7 +42,7 @@ class RequestContextFilter(logging.Filter):
DEFAULT_IP = '-'
DEFAULT_PATH = '-'
DEFAULT_REQUEST_ID = '-'
DEFAULT_USER = "-"
DEFAULT_USER = '-'
DEFAULT_USER_NAME = '-'
DEFAULT_USER_EMAIL = '-'
DEFAULT_USER_DISPLAY_NAME = '-'

View File

@ -234,7 +234,7 @@ class MatomoWS:
def create_fake_first_tracking_visit(self, id_site):
"""this function use a different matomo's webservice API"""
url = "%s/matomo.php" % self.url_ws_base
url = '%s/matomo.php' % self.url_ws_base
data = {'requests': ['?idsite=%s&action_name=ping&rec=1' % id_site]}
resp = requests.post(url, json=data, timeout=30)
if resp.status_code != 200:
@ -274,7 +274,7 @@ def upgrade_user(matomo, user_login, id_site):
# generate a password and add a new user
characters = string.ascii_letters + string.punctuation + string.digits
password = "".join(choice(characters) for x in range(randint(8, 16)))
password = ''.join(choice(characters) for x in range(randint(8, 16)))
matomo.add_user(user_login, password, id_site)
# build the user's login url

View File

@ -17,7 +17,7 @@ class HoboCommonMiddleware(CommonMiddleware):
self.will_redirect_with_slash
and isinstance(response, self.response_redirect_class)
and request.path_info.startswith('/api/')
and request.method in ("POST", "PUT", "PATCH")
and request.method in ('POST', 'PUT', 'PATCH')
)
def process_request(self, request):

View File

@ -12,7 +12,7 @@ class CORSMiddleware(MiddlewareMixin):
view/exception middleware along with the requested view;
it will call any response middlewares
"""
if request.method == 'OPTIONS' and "access-control-request-method" in request.headers:
if request.method == 'OPTIONS' and 'access-control-request-method' in request.headers:
response = HttpResponse()
return response
return None

View File

@ -17,7 +17,7 @@ class XForwardedForMiddleware(MiddlewareMixin):
headers = getattr(settings, 'USE_X_FORWARDED_FOR_HEADERS', None) or ('X-Forwarded-For',)
for header in headers:
if header in request.headers:
ip = request.headers.get(header, '').split(",")[0].strip()
ip = request.headers.get(header, '').split(',')[0].strip()
if ip:
request.META['REMOTE_ADDR'] = ip
break

View File

@ -35,8 +35,8 @@ class BaseTenantCommand(BaseCommand):
# prepend the command's original help with the info about schemata
# iteration
obj.help = (
"Calls {cmd} for all registered schemata. You can use regular "
"{cmd} options.\n\nOriginal help for {cmd}:\n\n{help}".format(
'Calls {cmd} for all registered schemata. You can use regular '
'{cmd} options.\n\nOriginal help for {cmd}:\n\n{help}'.format(
cmd=obj.COMMAND_NAME,
help=getattr(obj._original_command, 'help', 'none'),
)
@ -46,7 +46,7 @@ class BaseTenantCommand(BaseCommand):
def add_arguments(self, parser):
super().add_arguments(parser)
parser.add_argument("-d", "--domain", dest="domain")
parser.add_argument('-d', '--domain', dest='domain')
# use the privately held reference to the underlying command to invoke
# the add_arguments path on this parser instance
self._original_command.add_arguments(parser)
@ -87,7 +87,7 @@ class BaseTenantCommand(BaseCommand):
class InteractiveTenantOption:
def add_arguments(self, parser):
parser.add_argument("-d", "--domain", dest="domain", help='specify tenant domain')
parser.add_argument('-d', '--domain', dest='domain', help='specify tenant domain')
def get_tenant_from_options_or_interactive(self, **options):
all_tenants = list(TenantMiddleware.get_tenants())
@ -119,7 +119,7 @@ https://django-tenant-schemas.readthedocs.org/en/latest/use.html#creating-a-tena
else:
displayed_tenants = [x for x in all_tenants if domain in x.domain_url]
for i, tenant in enumerate(displayed_tenants):
print("[%2d] %s (schema %s)" % (i + 1, tenant.domain_url, tenant.schema_name))
print('[%2d] %s (schema %s)' % (i + 1, tenant.domain_url, tenant.schema_name))
return TenantMiddleware.get_tenant_by_hostname(domain)
@ -166,8 +166,8 @@ class SyncCommon(BaseCommand):
'migration. Use the name "zero" to unapply all migrations.'
),
)
parser.add_argument("-d", "--domain", dest="domain")
parser.add_argument("-s", "--schema", dest="schema_name")
parser.add_argument('-d', '--domain', dest='domain')
parser.add_argument('-s', '--schema', dest='schema_name')
def handle(self, *args, **options):
self.domain = options.get('domain')

View File

@ -9,11 +9,11 @@ from .create_tenant import Command as CreateTenantCommand
class Command(CreateTenantCommand):
help = "Create hobo tenant(s) by hostname(s)"
help = 'Create hobo tenant(s) by hostname(s)'
def handle(self, hostnames, **options):
if not hostnames:
raise CommandError("you must give at least one tenant hostname")
raise CommandError('you must give at least one tenant hostname')
if '-' in hostnames: # get additional list of hostnames from stdin
hostnames = list(hostnames)

View File

@ -5,7 +5,7 @@ from hobo.multitenant.middleware import TenantMiddleware
class Command(BaseCommand):
help = "Create schemas for all declared tenants"
help = 'Create schemas for all declared tenants'
def handle(self, *args, **options):
verbosity = int(options.get('verbosity'))
@ -15,6 +15,6 @@ class Command(BaseCommand):
for tenant in all_tenants:
if verbosity >= 1:
print()
print(self.style.NOTICE("=== Creating schema ") + self.style.SQL_TABLE(tenant.schema_name))
print(self.style.NOTICE('=== Creating schema ') + self.style.SQL_TABLE(tenant.schema_name))
tenant.create_schema(check_if_exists=True)

View File

@ -8,7 +8,7 @@ from hobo.multitenant.middleware import TenantMiddleware, get_tenant_model
class Command(BaseCommand):
help = "Create tenant(s) by hostname(s)"
help = 'Create tenant(s) by hostname(s)'
def add_arguments(self, parser):
parser.add_argument('hostnames', metavar='HOSTNAME', nargs='+')
@ -17,7 +17,7 @@ class Command(BaseCommand):
def handle(self, hostnames, legacy_hostname, **options):
verbosity = int(options.get('verbosity'))
if not hostnames:
raise CommandError("you must give at least one tenant hostname")
raise CommandError('you must give at least one tenant hostname')
if '-' in hostnames: # get additional list of hostnames from stdin
hostnames = list(hostnames)
@ -25,15 +25,15 @@ class Command(BaseCommand):
hostnames.extend([x.strip() for x in sys.stdin.readlines()])
if legacy_hostname and len(hostnames) > 1:
raise CommandError("You must specify only hostname when using --legacy-hostname")
raise CommandError('You must specify only hostname when using --legacy-hostname')
for hostname in hostnames:
try:
tenant_base = TenantMiddleware.base()
except AttributeError:
raise CommandError("you must configure TENANT_BASE in your settings")
raise CommandError('you must configure TENANT_BASE in your settings')
if not tenant_base:
raise CommandError("you must set a value to TENANT_BASE in your settings")
raise CommandError('you must set a value to TENANT_BASE in your settings')
tenant_dir = os.path.join(tenant_base, hostname)
if os.path.exists(tenant_dir):
raise CommandError('tenant already exists')
@ -62,12 +62,12 @@ class Command(BaseCommand):
legacy_schema = TenantMiddleware.hostname2schema(legacy_hostname)
tenant = get_tenant_model()(schema_name=schema, domain_url=hostname)
if verbosity >= 1:
msg = self.style.NOTICE("=== Creating schema ") + self.style.SQL_TABLE(tenant.schema_name)
msg = self.style.NOTICE('=== Creating schema ') + self.style.SQL_TABLE(tenant.schema_name)
if legacy_schema:
msg = (
self.style.NOTICE("=== Renamin schema ")
self.style.NOTICE('=== Renamin schema ')
+ self.style.SQL_TABLE(legacy_schema)
+ " to "
+ ' to '
+ self.style.SQL_TABLE(tenant.schema_name)
)
print()

View File

@ -6,7 +6,7 @@ from hobo.multitenant.middleware import TenantMiddleware
class Command(BaseCommand):
help = "Delete tenant(s) by hostname(s)"
help = 'Delete tenant(s) by hostname(s)'
def add_arguments(self, parser):
parser.add_argument(
@ -19,7 +19,7 @@ class Command(BaseCommand):
def handle(self, hostnames, **options):
if not hostnames:
raise CommandError("you must give at least one tenant hostname")
raise CommandError('you must give at least one tenant hostname')
if '-' in hostnames: # get additional list of hostnames from stdin
hostnames = list(hostnames)

View File

@ -11,4 +11,4 @@ class Command(BaseCommand):
all_tenants = TenantMiddleware.get_tenants()
for tenant in all_tenants:
print(f"{tenant.schema_name} {tenant.domain_url}")
print(f'{tenant.schema_name} {tenant.domain_url}')

View File

@ -26,7 +26,7 @@ from hobo.multitenant.middleware import TenantMiddleware, TenantNotFound
class MigrateSchemasCommand(SyncCommon):
help = "Updates database schema. Manages both apps with migrations and those without."
help = 'Updates database schema. Manages both apps with migrations and those without.'
requires_system_checks = []
def add_arguments(self, parser):
@ -70,7 +70,7 @@ class MigrateSchemasCommand(SyncCommon):
if all([x in applied_migrations for x in all_migrations]):
if int(self.options.get('verbosity', 1)) >= 1:
self._notice(
"=== Skipping migrations of tenant %s (%s/%s)"
'=== Skipping migrations of tenant %s (%s/%s)'
% (tenant.domain_url, step, len_tenants)
)
continue
@ -90,7 +90,7 @@ class MigrateSchemasCommand(SyncCommon):
def run_migrations(self, tenant, included_apps, step=1, steps=1):
if int(self.options.get('verbosity', 1)) >= 1:
self._notice("=== Running migrate for tenant %s (%s/%s)" % (tenant.domain_url, step, steps))
self._notice('=== Running migrate for tenant %s (%s/%s)' % (tenant.domain_url, step, steps))
connection.set_tenant(tenant, include_public=False)
command = MigrateCommand()
command.requires_system_checks = False
@ -100,7 +100,7 @@ class MigrateSchemasCommand(SyncCommon):
def run_migrations_on_schema(self, schema, included_apps):
if int(self.options.get('verbosity', 1)) >= 1:
self._notice("=== Running migrate for schema %s" % schema)
self._notice('=== Running migrate for schema %s' % schema)
connection.set_schema(schema, include_public=False)
command = MigrateCommand()
command.requires_system_checks = False

View File

@ -23,7 +23,7 @@ from hobo.multitenant.middleware import TenantMiddleware, TenantNotFound
class ShowMigrationsSchemasCommand(SyncCommon):
help = "Show database schema migrations."
help = 'Show database schema migrations.'
def add_arguments(self, parser):
super().add_arguments(parser)
@ -43,7 +43,7 @@ class ShowMigrationsSchemasCommand(SyncCommon):
self.run_showmigrations(tenant, settings.TENANT_APPS)
def run_showmigrations(self, tenant, included_apps):
self._notice("=== Show migrations for schema %s" % tenant.domain_url)
self._notice('=== Show migrations for schema %s' % tenant.domain_url)
connection.set_tenant(tenant, include_public=False)
command = ShowMigrationsCommand()
command.execute(*self.args, **self.options)

View File

@ -64,7 +64,7 @@ def run_command_from_argv(command, argv):
class Command(InteractiveTenantOption, BaseCommand):
help = "Wrapper around django commands for use with an individual tenant"
help = 'Wrapper around django commands for use with an individual tenant'
args = '<other_command>'
def run_from_argv(self, argv):
@ -77,7 +77,7 @@ class Command(InteractiveTenantOption, BaseCommand):
try:
app_name = get_commands()[argv[2]]
except KeyError:
raise CommandError("Unknown command: %r" % argv[2])
raise CommandError('Unknown command: %r' % argv[2])
if isinstance(app_name, BaseCommand):
# if the command is already loaded, use it directly.
@ -92,8 +92,8 @@ class Command(InteractiveTenantOption, BaseCommand):
# and forward the rest of the arguments to the actual command being wrapped.
del argv[1]
args_parser = argparse.ArgumentParser()
args_parser.add_argument("--all-tenants", help="apply command to all tenants", action='store_true')
args_parser.add_argument("-d", "--domain", dest="domain_name", help="specify tenant domain name")
args_parser.add_argument('--all-tenants', help='apply command to all tenants', action='store_true')
args_parser.add_argument('-d', '--domain', dest='domain_name', help='specify tenant domain name')
args_parser.add_argument(
'--force-job',
dest='force_job',

View File

@ -75,7 +75,7 @@ class Tenant(TenantMixin):
if connection.schema_name not in (self.schema_name, get_public_schema_name()):
raise Exception(
"Can't delete tenant outside it's own schema or "
"the public schema. Current schema is %s." % connection.schema_name
'the public schema. Current schema is %s.' % connection.schema_name
)
if force_drop:
rmtree(self.get_directory())

View File

@ -22,7 +22,7 @@ from hobo.environment.utils import get_variable, set_variable
from .forms import RobotsTxtForm, SettingsForm
ALLOW = ""
ALLOW = ''
DISALLOW = """User-agent: *
Disallow: /"""

View File

@ -35,7 +35,7 @@ def get_safe_db_name(max_length=53):
return 'hobo-test'
BRANCH_NAME = os.environ.get('BRANCH_NAME', '').replace('/', '-')[:15]
parts = [BRANCH_NAME]
if not os.environ.get("TOX_PARALLEL_ENV"):
if not os.environ.get('TOX_PARALLEL_ENV'):
# when we're in parallel mode, pytest-django will do this
# for us at a later point
parts.append(os.environ.get('TOX_ENV_NAME'))
@ -57,5 +57,5 @@ def find_free_port():
s.bind(('', 0))
# SO_LINGER (man 7 socket) l_onoff=1 l_linger=0, immediately release
# the port on closing of the socket
s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 1, 0))
return s.getsockname()[1]

View File

@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hobo.settings")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hobo.settings')
application = get_wsgi_application()

View File

@ -2,8 +2,8 @@
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hobo.settings")
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hobo.settings')
from django.core.management import execute_from_command_line

View File

@ -27,133 +27,133 @@ from hobo.environment.models import Authentic, Variable, Wcs
pytestmark = pytest.mark.django_db
WCS_AVAILABLE_OBJECTS = {
"data": [
'data': [
{
"id": "forms",
"text": "Forms",
"singular": "Form",
"urls": {"list": "https://wcs.example.invalid/api/export-import/forms/"},
'id': 'forms',
'text': 'Forms',
'singular': 'Form',
'urls': {'list': 'https://wcs.example.invalid/api/export-import/forms/'},
},
{
"id": "cards",
"text": "Card Models",
"singular": "Card Model",
"urls": {"list": "https://wcs.example.invalid/api/export-import/cards/"},
'id': 'cards',
'text': 'Card Models',
'singular': 'Card Model',
'urls': {'list': 'https://wcs.example.invalid/api/export-import/cards/'},
},
{
"id": "workflows",
"text": "Workflows",
"singular": "Workflow",
"urls": {"list": "https://wcs.example.invalid/api/export-import/workflows/"},
'id': 'workflows',
'text': 'Workflows',
'singular': 'Workflow',
'urls': {'list': 'https://wcs.example.invalid/api/export-import/workflows/'},
},
{
"id": "blocks",
"text": "Blocks",
"singular": "Block of fields",
"minor": True,
"urls": {"list": "https://wcs.example.invalid/api/export-import/blocks/"},
'id': 'blocks',
'text': 'Blocks',
'singular': 'Block of fields',
'minor': True,
'urls': {'list': 'https://wcs.example.invalid/api/export-import/blocks/'},
},
{
"id": "data-sources",
"text": "Data Sources",
"singular": "Data Source",
"minor": True,
"urls": {"list": "https://wcs.example.invalid/api/export-import/data-sources/"},
'id': 'data-sources',
'text': 'Data Sources',
'singular': 'Data Source',
'minor': True,
'urls': {'list': 'https://wcs.example.invalid/api/export-import/data-sources/'},
},
{
"id": "mail-templates",
"text": "Mail Templates",
"singular": "Mail Template",
"minor": True,
"urls": {"list": "https://wcs.example.invalid/api/export-import/mail-templates/"},
'id': 'mail-templates',
'text': 'Mail Templates',
'singular': 'Mail Template',
'minor': True,
'urls': {'list': 'https://wcs.example.invalid/api/export-import/mail-templates/'},
},
{
"id": "comment-templates-categories",
"text": "Categories (comment templates)",
"singular": "Category (comment templates)",
"minor": True,
"urls": {"list": "https://wcs.example.invalid/api/export-import/comment-templates-categories/"},
'id': 'comment-templates-categories',
'text': 'Categories (comment templates)',
'singular': 'Category (comment templates)',
'minor': True,
'urls': {'list': 'https://wcs.example.invalid/api/export-import/comment-templates-categories/'},
},
{
"id": "wscalls",
"text": "Webservice Calls",
"singular": "Webservice Call",
"minor": True,
"urls": {"list": "https://wcs.example.invalid/api/export-import/wscalls/"},
'id': 'wscalls',
'text': 'Webservice Calls',
'singular': 'Webservice Call',
'minor': True,
'urls': {'list': 'https://wcs.example.invalid/api/export-import/wscalls/'},
},
{
"id": "roles",
"text": "Roles",
"singular": "Role",
"minor": True,
"urls": {"list": "https://wcs.example.invalid/api/export-import/roles/"},
'id': 'roles',
'text': 'Roles',
'singular': 'Role',
'minor': True,
'urls': {'list': 'https://wcs.example.invalid/api/export-import/roles/'},
},
]
}
WCS_AVAILABLE_FORMS = {
"data": [
'data': [
{
"id": "test-form",
"text": "Test Form",
"type": "forms",
"urls": {
"export": "https://wcs.example.invalid/api/export-import/forms/test-form/",
"dependencies": "https://wcs.example.invalid/api/export-import/forms/test-form/dependencies/",
"redirect": "https://wcs.example.invalid/api/export-import/forms/test-form/redirect/",
'id': 'test-form',
'text': 'Test Form',
'type': 'forms',
'urls': {
'export': 'https://wcs.example.invalid/api/export-import/forms/test-form/',
'dependencies': 'https://wcs.example.invalid/api/export-import/forms/test-form/dependencies/',
'redirect': 'https://wcs.example.invalid/api/export-import/forms/test-form/redirect/',
},
},
{
"id": "test2-form",
"text": "Second Test Form",
"type": "forms",
"urls": {
"export": "https://wcs.example.invalid/api/export-import/forms/test2-form/",
"dependencies": "https://wcs.example.invalid/api/export-import/forms/test2-form/dependencies/",
'id': 'test2-form',
'text': 'Second Test Form',
'type': 'forms',
'urls': {
'export': 'https://wcs.example.invalid/api/export-import/forms/test2-form/',
'dependencies': 'https://wcs.example.invalid/api/export-import/forms/test2-form/dependencies/',
},
},
{
"id": "foo2-form",
"text": "Foo2 Test Form",
"type": "forms",
"category": "Foo",
"urls": {
"export": "https://wcs.example.invalid/api/export-import/forms/foo2-form/",
"dependencies": "https://wcs.example.invalid/api/export-import/forms/foo2-form/dependencies/",
'id': 'foo2-form',
'text': 'Foo2 Test Form',
'type': 'forms',
'category': 'Foo',
'urls': {
'export': 'https://wcs.example.invalid/api/export-import/forms/foo2-form/',
'dependencies': 'https://wcs.example.invalid/api/export-import/forms/foo2-form/dependencies/',
},
},
{
"id": "foo-form",
"text": "Foo Test Form",
"type": "forms",
"category": "Foo",
"urls": {
"export": "https://wcs.example.invalid/api/export-import/forms/foo-form/",
"dependencies": "https://wcs.example.invalid/api/export-import/forms/foo-form/dependencies/",
'id': 'foo-form',
'text': 'Foo Test Form',
'type': 'forms',
'category': 'Foo',
'urls': {
'export': 'https://wcs.example.invalid/api/export-import/forms/foo-form/',
'dependencies': 'https://wcs.example.invalid/api/export-import/forms/foo-form/dependencies/',
},
},
{
"id": "bar-form",
"text": "Bar Test Form",
"type": "forms",
"category": "Bar",
"urls": {
"export": "https://wcs.example.invalid/api/export-import/forms/bar-form/",
"dependencies": "https://wcs.example.invalid/api/export-import/forms/bar-form/dependencies/",
'id': 'bar-form',
'text': 'Bar Test Form',
'type': 'forms',
'category': 'Bar',
'urls': {
'export': 'https://wcs.example.invalid/api/export-import/forms/bar-form/',
'dependencies': 'https://wcs.example.invalid/api/export-import/forms/bar-form/dependencies/',
},
},
]
}
WCS_FORM_DEPENDENCIES = {
"data": [
'data': [
{
"id": "test-card",
"text": "Test Card",
"type": "cards",
"urls": {
"export": "https://wcs.example.invalid/api/export-import/cards/test-card/",
"dependencies": "https://wcs.example.invalid/api/export-import/cards/test-card/dependencies/",
'id': 'test-card',
'text': 'Test Card',
'type': 'cards',
'urls': {
'export': 'https://wcs.example.invalid/api/export-import/cards/test-card/',
'dependencies': 'https://wcs.example.invalid/api/export-import/cards/test-card/dependencies/',
},
}
]
@ -511,7 +511,7 @@ def test_scandeps_on_unknown_element(app, admin_user, settings):
name='Unknown',
cache={
'urls': {
"dependencies": "https://wcs.example.invalid/api/export-import/forms/unknown/dependencies/",
'dependencies': 'https://wcs.example.invalid/api/export-import/forms/unknown/dependencies/',
}
},
)
@ -585,13 +585,13 @@ def test_scandeps_on_renamed_element(app, admin_user, settings):
)
Relation.objects.create(application=application, element=element)
element2 = Element.objects.create(
type="cards",
slug="test-card",
name="Test Card",
type='cards',
slug='test-card',
name='Test Card',
cache={
"urls": {
"export": "https://wcs.example.invalid/api/export-import/cards/test-card/",
"dependencies": "https://wcs.example.invalid/api/export-import/cards/test-card/dependencies/",
'urls': {
'export': 'https://wcs.example.invalid/api/export-import/cards/test-card/',
'dependencies': 'https://wcs.example.invalid/api/export-import/cards/test-card/dependencies/',
}
},
)
@ -601,15 +601,15 @@ def test_scandeps_on_renamed_element(app, admin_user, settings):
if url.path == '/api/export-import/forms/':
return {
'content': {
"data": [
'data': [
{
"id": "test-form",
"text": "Test Form (renamed)",
"type": "forms",
"urls": {
"export": "https://wcs.example.invalid/api/export-import/forms/test-form/",
"dependencies": "https://wcs.example.invalid/api/export-import/forms/test-form/dependencies/",
"redirect": "https://wcs.example.invalid/api/export-import/forms/test-form/redirect/",
'id': 'test-form',
'text': 'Test Form (renamed)',
'type': 'forms',
'urls': {
'export': 'https://wcs.example.invalid/api/export-import/forms/test-form/',
'dependencies': 'https://wcs.example.invalid/api/export-import/forms/test-form/dependencies/',
'redirect': 'https://wcs.example.invalid/api/export-import/forms/test-form/redirect/',
},
},
]
@ -619,13 +619,13 @@ def test_scandeps_on_renamed_element(app, admin_user, settings):
if url.path == '/api/export-import/forms/test-form/dependencies/':
return {
'content': {
"data": [
'data': [
{
"id": "test-card",
"text": "Test Card (renamed)",
"type": "cards",
"urls": {
"dependencies": "https://wcs.example.invalid/api/export-import/cards/test-card/dependencies/",
'id': 'test-card',
'text': 'Test Card (renamed)',
'type': 'cards',
'urls': {
'dependencies': 'https://wcs.example.invalid/api/export-import/cards/test-card/dependencies/',
},
}
]
@ -642,23 +642,23 @@ def test_scandeps_on_renamed_element(app, admin_user, settings):
element.refresh_from_db()
assert element.name == 'Test Form (renamed)'
assert element.cache == {
"id": "test-form",
"text": "Test Form (renamed)",
"type": "forms",
"urls": {
"export": "https://wcs.example.invalid/api/export-import/forms/test-form/",
"dependencies": "https://wcs.example.invalid/api/export-import/forms/test-form/dependencies/",
"redirect": "https://wcs.example.invalid/api/export-import/forms/test-form/redirect/",
'id': 'test-form',
'text': 'Test Form (renamed)',
'type': 'forms',
'urls': {
'export': 'https://wcs.example.invalid/api/export-import/forms/test-form/',
'dependencies': 'https://wcs.example.invalid/api/export-import/forms/test-form/dependencies/',
'redirect': 'https://wcs.example.invalid/api/export-import/forms/test-form/redirect/',
},
}
element2 = Element.objects.get(relation__auto_dependency=True)
assert element2.name == 'Test Card (renamed)'
assert element2.cache == {
"id": "test-card",
"text": "Test Card (renamed)",
"type": "cards",
"urls": {
"dependencies": "https://wcs.example.invalid/api/export-import/cards/test-card/dependencies/",
'id': 'test-card',
'text': 'Test Card (renamed)',
'type': 'cards',
'urls': {
'dependencies': 'https://wcs.example.invalid/api/export-import/cards/test-card/dependencies/',
},
}
@ -959,20 +959,20 @@ def test_deploy_application(app, admin_user, settings, app_bundle, app_bundle_wi
assert job.exception == 'Failed to deploy module wcs (500)'
form_def = {
"id": "test",
"text": "Test",
"type": "forms",
"urls": {
"export": "https://wcs.example.invalid/api/export-import/forms/test/",
"dependencies": "https://wcs.example.invalid/api/export-import/forms/test/dependencies/",
"redirect": "https://wcs.example.invalid/api/export-import/forms/test/redirect/",
'id': 'test',
'text': 'Test',
'type': 'forms',
'urls': {
'export': 'https://wcs.example.invalid/api/export-import/forms/test/',
'dependencies': 'https://wcs.example.invalid/api/export-import/forms/test/dependencies/',
'redirect': 'https://wcs.example.invalid/api/export-import/forms/test/redirect/',
},
}
def response_content(url, request): # noqa pylint: disable=function-redefined
if url.path == '/api/export-import/forms/':
return {
'content': {"data": [form_def]},
'content': {'data': [form_def]},
'status_code': 200,
}
return mocked_http(url, request)
@ -1245,20 +1245,20 @@ def test_refresh_application(app, admin_user, settings):
Relation.objects.create(application=application, element=element)
form_def = {
"id": "test",
"text": "Test",
"type": "forms",
"urls": {
"export": "https://wcs.example.invalid/api/export-import/forms/test/",
"dependencies": "https://wcs.example.invalid/api/export-import/forms/test/dependencies/",
"redirect": "https://wcs.example.invalid/api/export-import/forms/test/redirect/",
'id': 'test',
'text': 'Test',
'type': 'forms',
'urls': {
'export': 'https://wcs.example.invalid/api/export-import/forms/test/',
'dependencies': 'https://wcs.example.invalid/api/export-import/forms/test/dependencies/',
'redirect': 'https://wcs.example.invalid/api/export-import/forms/test/redirect/',
},
}
def response_content(url, request):
if url.path == '/api/export-import/forms/':
return {
'content': {"data": [form_def]},
'content': {'data': [form_def]},
'status_code': 200,
}
return mocked_http(url, request)
@ -1608,7 +1608,7 @@ def app_bundle_parameters():
'slug': 'test',
'description': '',
'elements': [],
'parameters': [{"label": "Foo", "name": "app_foo", "default_value": "xxx"}],
'parameters': [{'label': 'Foo', 'name': 'app_foo', 'default_value': 'xxx'}],
}
manifest_fd = io.BytesIO(json.dumps(manifest_json, indent=2).encode())
tarinfo = tarfile.TarInfo('manifest.json')

View File

@ -139,8 +139,8 @@ def test_service_creation_url_validation(app, admin_user, monkeypatch):
app = login(app)
response = app.get('/sites/new-combo')
form = response.form
form['title'] = "test"
form['base_url'] = "http://portal-test.example.net"
form['title'] = 'test'
form['base_url'] = 'http://portal-test.example.net'
response = form.submit()
assert 'not resolvable' in response

View File

@ -43,7 +43,7 @@ def test_is_resolvable(app, admin_user, services, monkeypatch):
cache.clear()
def gethostname(netloc):
if netloc == "jazz.example.publik":
if netloc == 'jazz.example.publik':
return '176.31.123.109'
else:
raise socket.gaierror

View File

@ -95,7 +95,7 @@ def test_healt_view(app):
def test_menu_view(app, admin_user):
expected = [{"slug": "system", "label": "System", "url": "http://testserver/"}]
expected = [{'slug': 'system', 'label': 'System', 'url': 'http://testserver/'}]
app = login(app)
resp = app.get('/menu.json')
assert resp.content_type == 'application/json'

View File

@ -87,7 +87,7 @@ def test_manage(app, admin_user, settings):
resp.form.set('maintenance_pass_trough_header', '')
resp.form.set('disable_cron', False)
resp = resp.form.submit()
assert "No HTTP header pass through is configured" in resp.text
assert 'No HTTP header pass through is configured' in resp.text
assert 'Check this box if you are sure to enable the maintenance page.' in resp.text
# check the confirmation checkbox

View File

@ -357,7 +357,7 @@ def test_parse_response():
# error (not XML format)
content = """this is not XML"""
with pytest.raises(MatomoException, match="XMLSyntaxError: Start tag expected"):
with pytest.raises(MatomoException, match='XMLSyntaxError: Start tag expected'):
tree = matomo.parse_response(content)
@ -475,20 +475,20 @@ def test_add_site(mocked_post):
# success
content = ADD_SITE_SUCCESS
mocked_post.return_value.content = content
site_id = matomo.add_site("hobo.dev.publik.love")
site_id = matomo.add_site('hobo.dev.publik.love')
assert site_id == '42'
# error
content = ADD_SITE_ERROR
mocked_post.return_value.content = content
with pytest.raises(MatomoError, match="Please specify a value for 'siteName'."):
site_id = matomo.add_site("hobo.dev.publik.love")
site_id = matomo.add_site('hobo.dev.publik.love')
# strange message
content = ADD_SITE_BAD_RESPONSE
mocked_post.return_value.content = content
with pytest.raises(MatomoException, match='add_site fails'):
site_id = matomo.add_site("hobo.dev.publik.love")
site_id = matomo.add_site('hobo.dev.publik.love')
@mock.patch('requests.post')
@ -666,32 +666,32 @@ def test_upgrade_site(mocked_post):
# site not already here
contents = [GET_NO_SITE_FROM_URL, ADD_SITE_SUCCESS, ADD_SITE_ALIAS_URLS_SUCCESS]
mocked_post.side_effect = requests_post_mocked_replies(contents)
site_id = upgrade_site(matomo, "hobo.dev.publik.love", urls)
site_id = upgrade_site(matomo, 'hobo.dev.publik.love', urls)
assert site_id == '42'
# site already here
contents = [GET_SITE_42_FROM_URL, ADD_SITE_ALIAS_URLS_SUCCESS]
mocked_post.side_effect = requests_post_mocked_replies(contents)
site_id = upgrade_site(matomo, "hobo.dev.publik.love", urls)
site_id = upgrade_site(matomo, 'hobo.dev.publik.love', urls)
assert site_id == '42'
# error while updating urls
contents = [GET_SITE_42_FROM_URL, ADD_SITE_ALIAS_URLS_ERROR]
mocked_post.side_effect = requests_post_mocked_replies(contents)
with pytest.raises(MatomoException):
upgrade_site(matomo, "hobo.dev.publik.love", urls)
upgrade_site(matomo, 'hobo.dev.publik.love', urls)
# error while adding new site
contents = [GET_NO_SITE_FROM_URL, MATOMO_ERROR]
mocked_post.side_effect = requests_post_mocked_replies(contents)
with pytest.raises(MatomoException):
upgrade_site(matomo, "hobo.dev.publik.love", urls)
upgrade_site(matomo, 'hobo.dev.publik.love', urls)
# error while looking for site already there
contents = [MATOMO_ERROR]
mocked_post.side_effect = requests_post_mocked_replies(contents)
with pytest.raises(MatomoException, match='here is the error message'):
upgrade_site(matomo, "hobo.dev.publik.love", urls)
upgrade_site(matomo, 'hobo.dev.publik.love', urls)
@mock.patch('requests.post')
@ -755,7 +755,7 @@ def test_get_tracking_js():
var2.delete()
get_variable('cnil_compliant_visits_tracking_js', 'content1')
get_variable('visits_tracking_js', 'content2')
assert get_tracking_js() == "content1content2"
assert get_tracking_js() == 'content1content2'
def test_put_tracking_js():
@ -862,7 +862,7 @@ def test_auto_configure_matomo_error(mocked_post):
JAVASCRIPT_TAG_BAD_RESPONSE,
]
mocked_post.side_effect = requests_post_mocked_replies(contents)
with pytest.raises(MatomoException, match="get_javascript_tag fails"):
with pytest.raises(MatomoException, match='get_javascript_tag fails'):
matomo = MatomoWS()
auto_configure_matomo(matomo)
tracking_js_var = get_variable('visits_tracking_js')

View File

@ -65,7 +65,7 @@ def test_home(app, admin_user):
def test_allow(app, admin_user):
login(app)
variable = get_variable('robots_txt')
variable.value = "some content"
variable.value = 'some content'
variable.save()
resp = app.get('/seo/allow', status=302)
assert resp.location.endswith('/seo/')
@ -75,7 +75,7 @@ def test_allow(app, admin_user):
def test_disallow(app, admin_user):
login(app)
variable = get_variable('robots_txt')
variable.value = "some content"
variable.value = 'some content'
variable.save()
resp = app.get('/seo/disallow', status=302)
assert resp.location.endswith('/seo/')
@ -87,7 +87,7 @@ def test_disallow(app, admin_user):
def test_custom(app, admin_user):
login(app)
variable = get_variable('robots_txt')
variable.value = "some content"
variable.value = 'some content'
variable.save()
resp = app.get('/seo/customize', status=200)
assert resp.html.textarea['name'] == 'content'

View File

@ -19,7 +19,7 @@ def test_theme_view(mocked_random, app, admin_user, fake_themes):
assert Variable.objects.filter(name='foo')[0].value == 'bar'
assert resp.location == '/theme/'
resp = resp.follow()
assert "The theme has been changed" in str(resp.html)
assert 'The theme has been changed' in str(resp.html)
assert resp.form['theme'].value == 'alfortville'
resp.form['theme'].value = 'publik'

View File

@ -87,7 +87,7 @@ def tenant_factory(transactional_db, tenant_base, settings):
for tenant in tenants:
with tenant_context(tenant):
call_command(
"flush",
'flush',
verbosity=0,
interactive=False,
database='default',

View File

@ -370,7 +370,7 @@ def test_multipublik(tenants, mocker):
assert service['legacy_urls'][0]['base_url'] == 'https://combo1.example.net/'
break
else:
assert False, "no portal found"
assert False, 'no portal found'
# inform coll2 about interco environment
HoboDeployCommand().handle(hobo2.base_url, get_hobo_json_filename(hobo1))
@ -408,7 +408,7 @@ def test_multipublik(tenants, mocker):
assert service['legacy_urls'][0]['base_url'] == 'https://combo2.example.net/'
break
else:
assert False, "no portal found"
assert False, 'no portal found'
# inform interco about coll2 environment
HoboDeployCommand().handle(hobo1.base_url, get_hobo_json_filename(hobo2))

View File

@ -34,10 +34,10 @@ def make_tenant(tmp_path, transactional_db, settings, request):
'theme': 'publik',
'SETTING_GLOBAL1': True,
'SETTING_GLOBAL2.extend': [2, 3, 4],
'SETTING_GLOBAL3.update': {"x": 1, "y": 2},
'SETTING_GLOBAL3.update': {'x': 1, 'y': 2},
'SETTING_OVERRIDE1': False,
'SETTING_OVERRIDE2.extend': [6, 7, 8],
'SETTING_OVERRIDE3.update': {"a": 1, "b": 2},
'SETTING_OVERRIDE3.update': {'a': 1, 'b': 2},
},
'services': [
{
@ -52,10 +52,10 @@ def make_tenant(tmp_path, transactional_db, settings, request):
'other_variable': 'bar',
'SETTING_OVERRIDE1': True,
'SETTING_OVERRIDE2.extend': [name, 7, 8],
'SETTING_OVERRIDE3.update': {"a": name, "b": 2},
'SETTING_OVERRIDE3.update': {'a': name, 'b': 2},
'SETTING_LOCAL1': False,
'SETTING_LOCAL2.extend': [name, 7, 8],
'SETTING_LOCAL3.update': {"a": name, "b": 2},
'SETTING_LOCAL3.update': {'a': name, 'b': 2},
},
},
{

View File

@ -95,8 +95,8 @@ TENANT_SETTINGS_LOADERS = (
GLOBAL1 = 0
GLOBAL2 = [1, 2, 3]
GLOBAL3 = {"z": 1}
GLOBAL3 = {'z': 1}
OVERRIDE1 = 0
OVERRIDE2 = [1, 2, 3]
OVERRIDE3 = {"z": 1}
OVERRIDE3 = {'z': 1}

View File

@ -97,7 +97,7 @@ def test_debug_log(tenants, settings, app, rf, debug_log, freezer):
'level': 'INFO',
'tenant': 'tenant1.example.net',