misc: apply double-quote-string-fixer (#79788)

This commit is contained in:
Valentin Deniaud 2023-08-16 11:52:13 +02:00
parent 5d5f0049dc
commit 6931c3cee1
9 changed files with 27 additions and 27 deletions

View File

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

View File

@ -10,7 +10,7 @@ url = (
sys.argv[1]
if len(sys.argv) > 1
else (
"http://127.0.0.1:9040/api/ants/availableTimeSlots?meeting_point_ids=1&meeting_point_ids=2&meeting_point_ids=3&start_date=2023-04-13&end_date=2023-04-17"
'http://127.0.0.1:9040/api/ants/availableTimeSlots?meeting_point_ids=1&meeting_point_ids=2&meeting_point_ids=3&start_date=2023-04-13&end_date=2023-04-17'
)
)
@ -24,7 +24,7 @@ async def make_request(i):
response = await client.get(
url,
headers={
"X-HUB-RDV-AUTH-TOKEN": "5c55f859e66e2f6dee41a55c6ebd8b04f9dd88f4b22dd451b2663797edff7fc3"
'X-HUB-RDV-AUTH-TOKEN': '5c55f859e66e2f6dee41a55c6ebd8b04f9dd88f4b22dd451b2663797edff7fc3'
},
)
except Exception:
@ -48,4 +48,4 @@ async def main():
start = time.time()
asyncio.run(main())
duration = time.time() - start
print("Did", requests, "requests in", duration, "seconds RPS:", requests / duration)
print('Did', requests, 'requests in', duration, 'seconds RPS:', requests / duration)

View File

@ -60,7 +60,7 @@ class sdist(_sdist):
sub_commands = [('compile_translations', None)] + _sdist.sub_commands
def run(self):
print("creating VERSION file")
print('creating VERSION file')
if os.path.exists('VERSION'):
os.remove('VERSION')
version = get_version()
@ -68,7 +68,7 @@ class sdist(_sdist):
version_file.write(version)
version_file.close()
_sdist.run(self)
print("removing VERSION file")
print('removing VERSION file')
if os.path.exists('VERSION'):
os.remove('VERSION')
@ -112,15 +112,15 @@ with open('README') as fd:
long_description = fd.read()
setup(
name="ants-hub",
name='ants-hub',
version=get_version(),
license="AGPLv3+",
license='AGPLv3+',
description='ANTS-Hub',
long_description=long_description,
url="http://dev.entrouvert.org/projects/ants-hub/",
url='http://dev.entrouvert.org/projects/ants-hub/',
author="Entr'ouvert",
maintainer="Benjamin Dauvergne",
maintainer_email="bdauvergne@entrouvert.com",
maintainer='Benjamin Dauvergne',
maintainer_email='bdauvergne@entrouvert.com',
scripts=('manage.py',),
packages=find_packages('src'),
package_dir={
@ -133,9 +133,9 @@ setup(
'requests',
],
classifiers=[
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Operating System :: OS Independent",
"Programming Language :: Python",
'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)',
'Operating System :: OS Independent',
'Programming Language :: Python',
],
cmdclass={
'build': build,

View File

@ -48,7 +48,7 @@ def authenticate(func):
header = request.headers.get('X-Hub-Rdv-Auth-Token', '')
if not header:
logger.warning('authentication failed, missing header X-HUB-RDV-AUTH-TOKEN')
return JsonResponse("Missing X-HUB-RDV-AUTH-TOKEN header", status=401, safe=False)
return JsonResponse('Missing X-HUB-RDV-AUTH-TOKEN header', status=401, safe=False)
if AUTH_TOKEN_TIME and time.time() - AUTH_TOKEN_TIME < 60 and 'pytest' not in sys.modules:
auth_token = AUTH_TOKEN
else:
@ -56,10 +56,10 @@ def authenticate(func):
AUTH_TOKEN_TIME, AUTH_TOKEN = time.time(), auth_token
if not auth_token:
logger.error('authentication failed, REQUEST_FROM_ANTS_AUTH_TOKEN is not configured')
return JsonResponse("X-HUB-RDV-AUTH-TOKEN not configured", status=401, safe=False)
return JsonResponse('X-HUB-RDV-AUTH-TOKEN not configured', status=401, safe=False)
if not secrets.compare_digest(header, auth_token):
logger.warning('authentication failed, bad authentication token "%s"', header)
return JsonResponse("X-HUB-RDV-AUTH-TOKEN header invalid", status=401, safe=False)
return JsonResponse('X-HUB-RDV-AUTH-TOKEN header invalid', status=401, safe=False)
return func(request, *args, **kwargs)
return wrapper

View File

@ -53,18 +53,18 @@ def authenticate(func):
header = request.headers.get('Authorization', '').encode()
if not header:
logger.warning('authentication failed, missing Authorization header')
return Http401("Missing Authorization header")
return Http401('Missing Authorization header')
auth = header.split(maxsplit=1)
if not auth or auth[0].lower() not in [b'basic', b'bearer'] or len(auth) != 2:
logger.warning('authentication failed, invalid Authorization header')
return Http401("Invalid Authorization header")
return Http401('Invalid Authorization header')
if auth[0].lower() == b'basic':
try:
auth_decoded = base64.b64decode(auth[1]).decode()
except (TypeError, UnicodeDecodeError, binascii.Error):
logger.warning('authentication failed, invalid Authorization header')
return Http401("Invalid Authorization header")
return Http401('Invalid Authorization header')
apikey = auth_decoded.split(':', 1)[0]
else:
@ -73,12 +73,12 @@ def authenticate(func):
apikey = auth[1].decode()
except UnicodeDecodeError:
logger.warning('authentication failed, invalid Authorization header')
return Http401("Invalid Authorization header")
return Http401('Invalid Authorization header')
raccordement = Raccordement.objects.get_by_apikey(apikey)
if not raccordement:
logger.warning('authentication failed, unknown API key "%s"', apikey)
return Http401("Unknown API key")
return Http401('Unknown API key')
request.raccordement = raccordement
return func(request, *args, **kwargs)

View File

@ -166,7 +166,7 @@ class Raccordement(models.Model):
help_text='Écrire "NEW" pour en générer une nouvelle.',
)
apikey_digest = models.UUIDField(verbose_name='Condensat de l\'API key', db_index=True, editable=False)
notes = models.TextField(verbose_name="Notes", blank=True)
notes = models.TextField(verbose_name='Notes', blank=True)
created = models.DateTimeField(verbose_name='Création', auto_now_add=True)
last_update = models.DateTimeField(verbose_name='Dernière mise à jour', auto_now=True)

View File

@ -4,5 +4,5 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "ants_hub.settings"
os.environ['DJANGO_SETTINGS_MODULE'] = 'ants_hub.settings'
application = get_wsgi_application()

View File

@ -221,7 +221,7 @@ class TestEndpoints:
def test_search_application_ids(self, db, django_app, lieu):
RendezVous.objects.create(
uuid="7621a90a-2dd3-44e5-9df7-879abddeaad5",
uuid='7621a90a-2dd3-44e5-9df7-879abddeaad5',
lieu=lieu,
identifiant_predemande='123456',
date=datetime.datetime.fromisoformat('2023-04-11T11:00:00+02:00'),

View File

@ -373,7 +373,7 @@ def test_predemandes(db, django_app):
rdv_api_url,
json=document,
status=200,
match=[responses.matchers.header_matcher({"x-hub-rdv-auth-token": 'xyz'})],
match=[responses.matchers.header_matcher({'x-hub-rdv-auth-token': 'xyz'})],
)
response = django_app.get('/api/chrono/predemandes/', params={'identifiant_predemande': 'xyz'})