misc: fix consider-using-dict-items pylint error (#62099)

This commit is contained in:
Lauréline Guérin 2022-03-18 16:12:29 +01:00
parent ceb7bff14d
commit 00ea35fa59
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
5 changed files with 12 additions and 15 deletions

View File

@ -266,11 +266,11 @@ class Resource(BaseResource):
if len(doc_files) != 1:
return False, 'too many/few doc files found: %s' % doc_files
for key in attachments:
if len(attachments[key]) > 1:
return False, 'too many attachments of kind %s: %r' % (key, attachments[key])
name = attachments[key][0]
with archive.open(attachments[key][0]) as zip_fd:
for key, attachment in attachments.items():
if len(attachment) > 1:
return False, 'too many attachments of kind %s: %r' % (key, attachment)
name = attachment[0]
with archive.open(name) as zip_fd:
content = zip_fd.read()
attachments[key] = {
'filename': name,

View File

@ -433,8 +433,8 @@ class BaseResource(models.Model):
}
init_kwargs.update(kwargs)
if instance:
for key in init_kwargs:
setattr(instance, key, init_kwargs[key])
for key, value in init_kwargs.items():
setattr(instance, key, value)
else:
instance = cls(**init_kwargs)
concrete_fields = [

View File

@ -68,7 +68,7 @@ class TypeInterventionAsBlocks(DetailView):
response = HttpResponse(content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename=blocks.zip'
with zipfile.ZipFile(response, mode='w') as zip_file:
for name in files:
zip_file.writestr(name, files[name])
for name, f in files.items():
zip_file.writestr(name, f)
return response

View File

@ -128,8 +128,7 @@ def flatten_json_schema(schema, separator=FLATTEN_SEPARATOR):
for subschema in schema['oneOf']:
for key, schema in helper(prefix, subschema):
schemas_by_keys.setdefault(key, []).append(schema)
for key in schemas_by_keys:
schemas = schemas_by_keys[key]
for key, schemas in schemas_by_keys.items():
if len(schemas) > 1:
yield key, {'oneOf': schemas}
else:

View File

@ -349,7 +349,7 @@ def test_solis_apa_link_infos_unlink(app, solis):
assert SolisAPALink.objects.get(name_id=NAMEID, user_id='42').text == 'Mme Pecile PEPONE (NPYNEZ)'
# get all kind of informations
for apa_endpoint in APAINFOS:
for apa_endpoint, content in APAINFOS.items():
with mock.patch('passerelle.utils.Request.get') as requests_get:
with mock.patch('passerelle.utils.Request.post') as requests_post:
requests_post.return_value = tests.utils.FakedResponse(content=APATOKEN, status_code=200)
@ -359,9 +359,7 @@ def test_solis_apa_link_infos_unlink(app, solis):
assert resp.json['err'] == 1
endpoint = endpoint_base + '?name_id=%s&user_id=53&information=%s' % (NAMEID, apa_endpoint)
requests_get.return_value = tests.utils.FakedResponse(
content=APAINFOS[apa_endpoint], status_code=200
)
requests_get.return_value = tests.utils.FakedResponse(content=content, status_code=200)
resp = app.get(endpoint, status=200)
assert requests_post.call_count == 1 # get a token
assert requests_get.call_count == 1 # get informations