From 4a9aa42f8144f66cd1556277381b111b556c21f5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Fri, 18 Mar 2022 16:12:29 +0100
Subject: [PATCH 21/65] misc: fix consider-using-dict-items pylint error
 (#62099)

---
 passerelle/apps/sp_fr/models.py            | 10 +++++-----
 passerelle/base/models.py                  |  4 ++--
 passerelle/contrib/toulouse_smart/views.py |  4 ++--
 passerelle/utils/json.py                   |  3 +--
 tests/test_solis.py                        |  6 ++----
 5 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/passerelle/apps/sp_fr/models.py b/passerelle/apps/sp_fr/models.py
index c0762871..bf3a84eb 100644
--- a/passerelle/apps/sp_fr/models.py
+++ b/passerelle/apps/sp_fr/models.py
@@ -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,
diff --git a/passerelle/base/models.py b/passerelle/base/models.py
index ae8cd4d8..042c4a93 100644
--- a/passerelle/base/models.py
+++ b/passerelle/base/models.py
@@ -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 = [
diff --git a/passerelle/contrib/toulouse_smart/views.py b/passerelle/contrib/toulouse_smart/views.py
index e4524df5..160efed6 100644
--- a/passerelle/contrib/toulouse_smart/views.py
+++ b/passerelle/contrib/toulouse_smart/views.py
@@ -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
diff --git a/passerelle/utils/json.py b/passerelle/utils/json.py
index a9b0751d..c7a300c3 100644
--- a/passerelle/utils/json.py
+++ b/passerelle/utils/json.py
@@ -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:
diff --git a/tests/test_solis.py b/tests/test_solis.py
index 69cfde45..582273b7 100644
--- a/tests/test_solis.py
+++ b/tests/test_solis.py
@@ -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
-- 
2.34.1

