From d7d6cfd2afe12be67e7afee86b30c82b13a2ce17 Mon Sep 17 00:00:00 2001
From: Lasse Fredheim <lass@uio.no>
Date: Tue, 24 Jan 2023 10:52:07 +0100
Subject: [PATCH] Fix backend lint issues

---
 greg/models.py                                |  3 +-
 greg/tests/api/test_person.py                 |  1 -
 greg/utils.py                                 |  2 -
 gregui/api/serializers/guest.py               |  1 -
 gregui/api/views/identity.py                  |  1 -
 gregui/authentication/auth_backends.py        |  4 -
 gregui/migrations/0001_initial.py             |  1 -
 gregui/migrations/0002_emailtemplate.py       |  1 -
 .../0003_add_email_template_type.py           |  1 -
 .../0004_add_email_template_type.py           |  1 -
 gregui/tests/conftest.py                      | 23 ++++--
 iga/tests/test_uib.py                         | 73 ++++++++-----------
 iga/uib.py                                    | 24 ++++--
 13 files changed, 64 insertions(+), 72 deletions(-)

diff --git a/greg/models.py b/greg/models.py
index 1f3b6c4f..a7ad8f95 100644
--- a/greg/models.py
+++ b/greg/models.py
@@ -80,7 +80,8 @@ class Person(BaseModel):
     @property
     def passport(self) -> Optional["Identity"]:
         """The person's passport if they have one registered.
-        This property was introduced to make updating of passport easier when the guest registers himself."""
+        This property was introduced to make updating of passport easier when the guest registers himself.
+        """
         return self.identities.filter(
             type=Identity.IdentityType.PASSPORT_NUMBER
         ).first()
diff --git a/greg/tests/api/test_person.py b/greg/tests/api/test_person.py
index 6d38d206..12596549 100644
--- a/greg/tests/api/test_person.py
+++ b/greg/tests/api/test_person.py
@@ -544,7 +544,6 @@ def test_filter_role_type(
     sponsor_guy: Sponsor,
     unit_foo: OrganizationalUnit,
 ):
-
     date_today = datetime.date.today()
 
     best_test_guest = RoleType.objects.create(
diff --git a/greg/utils.py b/greg/utils.py
index fa61a818..bc108f35 100644
--- a/greg/utils.py
+++ b/greg/utils.py
@@ -171,9 +171,7 @@ def create_objects_for_invitation(
     role_data: dict,
     sponsor: typing.Union[Sponsor, str],
 ) -> Person:
-
     with transaction.atomic():
-
         # If only sponsor's feide_id is provided create the sponsor
         if isinstance(sponsor, str):
             sponsor = Sponsor.objects.create(feide_id=sponsor)
diff --git a/gregui/api/serializers/guest.py b/gregui/api/serializers/guest.py
index ca63e30d..851adcf6 100644
--- a/gregui/api/serializers/guest.py
+++ b/gregui/api/serializers/guest.py
@@ -331,7 +331,6 @@ class FrontPageGuestSerializer(serializers.ModelSerializer):
     def get_invitation_status(
         self, obj: Person
     ) -> Literal["active", "expired", "invalidEmail", "none"]:
-
         private_email = next(
             iter(
                 [
diff --git a/gregui/api/views/identity.py b/gregui/api/views/identity.py
index 1d9bf805..e9593e82 100644
--- a/gregui/api/views/identity.py
+++ b/gregui/api/views/identity.py
@@ -36,7 +36,6 @@ class IdentityViewSet(
 
 
 class IdentityCheckView(APIView):
-
     authentication_classes = [SessionAuthentication, BasicAuthentication]
     permission_classes = [IsAuthenticated, IsSponsor]
 
diff --git a/gregui/authentication/auth_backends.py b/gregui/authentication/auth_backends.py
index ac0942cc..f23e4b64 100644
--- a/gregui/authentication/auth_backends.py
+++ b/gregui/authentication/auth_backends.py
@@ -83,7 +83,6 @@ ID_REGEX = re.compile(r"^(?P<id_type>[^:]+):(?P<id_value>.+)$")
 
 
 def extract_userinfo(claims: dict) -> dict:
-
     ids = [x.split(":")[0] for x in claims["dataporten-userid_sec"] if ":" in x]
     if len(ids) == 1 and "nin" in ids:
         # IDPorten login
@@ -481,7 +480,6 @@ class GregOIDCBackend(ValidatingOIDCBackend):
     def _update_person_name(
         self, person: Person, first_name: str, last_name: str
     ) -> None:
-
         new_combined_name = f"{first_name} {last_name}"
         existing_combined_name = f"{person.first_name} {person.last_name}"
 
@@ -533,7 +531,6 @@ class GregOIDCBackend(ValidatingOIDCBackend):
     def _update_user_profile(
         self, userinfo: dict, user_profile: GregUserProfile, person: Person
     ) -> GregUserProfile:
-
         sponsor = self._get_sponsor_from_userinfo(userinfo)
         self._update_sponsor_from_userinfo(userinfo, sponsor)
 
@@ -554,7 +551,6 @@ class GregOIDCBackend(ValidatingOIDCBackend):
     def _create_user_profile(
         self, userinfo: dict, user: UserModel, person: Person
     ) -> GregUserProfile:
-
         sponsor = self._get_sponsor_from_userinfo(userinfo)
         self._update_sponsor_from_userinfo(userinfo, sponsor)
 
diff --git a/gregui/migrations/0001_initial.py b/gregui/migrations/0001_initial.py
index 71c6ce2c..8b922888 100644
--- a/gregui/migrations/0001_initial.py
+++ b/gregui/migrations/0001_initial.py
@@ -7,7 +7,6 @@ import django.db.models.deletion
 
 
 class Migration(migrations.Migration):
-
     initial = True
 
     dependencies = [
diff --git a/gregui/migrations/0002_emailtemplate.py b/gregui/migrations/0002_emailtemplate.py
index 15c4b7b6..568fe153 100644
--- a/gregui/migrations/0002_emailtemplate.py
+++ b/gregui/migrations/0002_emailtemplate.py
@@ -5,7 +5,6 @@ from django.db import migrations, models
 
 
 class Migration(migrations.Migration):
-
     dependencies = [
         ("gregui", "0001_initial"),
     ]
diff --git a/gregui/migrations/0003_add_email_template_type.py b/gregui/migrations/0003_add_email_template_type.py
index 77800099..efe5078c 100644
--- a/gregui/migrations/0003_add_email_template_type.py
+++ b/gregui/migrations/0003_add_email_template_type.py
@@ -4,7 +4,6 @@ from django.db import migrations, models
 
 
 class Migration(migrations.Migration):
-
     dependencies = [
         ("gregui", "0002_emailtemplate"),
     ]
diff --git a/gregui/migrations/0004_add_email_template_type.py b/gregui/migrations/0004_add_email_template_type.py
index 4c3c0fce..ec99d25f 100644
--- a/gregui/migrations/0004_add_email_template_type.py
+++ b/gregui/migrations/0004_add_email_template_type.py
@@ -4,7 +4,6 @@ from django.db import migrations, models
 
 
 class Migration(migrations.Migration):
-
     dependencies = [
         ("gregui", "0003_add_email_template_type"),
     ]
diff --git a/gregui/tests/conftest.py b/gregui/tests/conftest.py
index 9ab9da81..0ba81984 100644
--- a/gregui/tests/conftest.py
+++ b/gregui/tests/conftest.py
@@ -252,9 +252,9 @@ def user_person(person_foo: Sponsor, create_user) -> User:
 
 
 @pytest.fixture
-def create_greg_user_profile() -> Callable[
-    [UserModel, Optional[Person], Optional[Sponsor]], GregUserProfile
-]:
+def create_greg_user_profile() -> (
+    Callable[[UserModel, Optional[Person], Optional[Sponsor]], GregUserProfile]
+):
     user_model = get_user_model()
 
     def create_greg_user_profile(
@@ -364,9 +364,20 @@ def invitation_link_expired(
 
 
 @pytest.fixture
-def create_person() -> Callable[
-    [str, str, str, Optional[str], Optional[str], Optional[str], Optional[datetime.date]], Person
-]:
+def create_person() -> (
+    Callable[
+        [
+            str,
+            str,
+            str,
+            Optional[str],
+            Optional[str],
+            Optional[str],
+            Optional[datetime.date],
+        ],
+        Person,
+    ]
+):
     # TODO fix the typing...
     def create_person(
         first_name: str,
diff --git a/iga/tests/test_uib.py b/iga/tests/test_uib.py
index d6c57f34..a666aa54 100644
--- a/iga/tests/test_uib.py
+++ b/iga/tests/test_uib.py
@@ -5,55 +5,40 @@ from ..iga import IgaPerson
 from ..uib import UibRiScim
 
 UIB_SEARCH = {
-  "schemas": [
-    "urn:ietf:params:scim:api:messages:2.0:ListResponse"
-  ],
-  "totalResults": 1,
-  "startIndex": 1,
-  "itemsPerPage": 1,
-  "Resources": [
-    {
-      "schemas": [
-        "urn:ietf:params:scim:schemas:core:2.0:User",
-        "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
-        "no:edu:scim:user"
-      ],
-      "id": "",
-      "externalId": "",
-      "userName": "",
-      "displayName": "Ruth Pedersen",
-      "profileUrl": "",
-      "title": "",
-      "userType": "Employee",
-      "preferredLanguage": None,
-      "active": True,
-      "emails": [
+    "schemas": ["urn:ietf:params:scim:api:messages:2.0:ListResponse"],
+    "totalResults": 1,
+    "startIndex": 1,
+    "itemsPerPage": 1,
+    "Resources": [
         {
-          "value": "",
-          "type": "work"
+            "schemas": [
+                "urn:ietf:params:scim:schemas:core:2.0:User",
+                "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
+                "no:edu:scim:user",
+            ],
+            "id": "",
+            "externalId": "",
+            "userName": "",
+            "displayName": "Ruth Pedersen",
+            "profileUrl": "",
+            "title": "",
+            "userType": "Employee",
+            "preferredLanguage": None,
+            "active": True,
+            "emails": [{"value": "", "type": "work"}],
+            "phoneNumbers": [],
+            "roles": [{"value": "iam:employee"}, {"value": "iam:operation"}],
+            "no:edu:scim:user": {
+                "accountType": "primary",
+                "employeeNumber": "102160",
+                "eduPersonPrincipalName": "ruped001@uib.no",
+                "userPrincipalName": "Ruth.Pedersen@uibtest.no",
+            },
         }
-      ],
-      "phoneNumbers": [],
-      "roles": [
-        {
-          "value": "iam:employee"
-        },
-        {
-          "value": "iam:operation"
-        }
-      ],
-      "no:edu:scim:user": {
-        "accountType": "primary",
-        "employeeNumber": "102160",
-        "eduPersonPrincipalName": "ruped001@uib.no",
-        "userPrincipalName": "Ruth.Pedersen@uibtest.no",
-      },
-    }
-  ]
+    ],
 }
 
 
-
 def test_uib_search(requests_mock):
     """Regular search works as expected"""
     uib_search_wname = copy.deepcopy(UIB_SEARCH)
diff --git a/iga/uib.py b/iga/uib.py
index 2e923e8f..a4cebe39 100644
--- a/iga/uib.py
+++ b/iga/uib.py
@@ -15,15 +15,19 @@ class UibRiScim(IgaImplementation):
         self.client: IgaClient = IgaAbstract.get_iga_client(
             "scim-ri@uib",
             endpoints={"base_url": config["url"]},
-            headers=config["headers"])
+            headers=config["headers"],
+        )
         self.idtype_methodmap = {
             Identity.IdentityType.NORWEGIAN_NATIONAL_ID_NUMBER: lambda nor_edu_person_nin: self.client.client(
-                user_query_request(extra_parameters={"norEduPersonNIN": nor_edu_person_nin})).payload,
+                user_query_request(
+                    extra_parameters={"norEduPersonNIN": nor_edu_person_nin}
+                )
+            ).payload,
             Identity.IdentityType.PASSPORT_NUMBER: None,  # not supported by uib scim
         }
 
     def extid_search(
-            self, id_type: Identity.IdentityType, extid: str
+        self, id_type: Identity.IdentityType, extid: str
     ) -> Optional[IgaPerson]:
         search = self.idtype_methodmap.get(id_type)
 
@@ -35,12 +39,16 @@ class UibRiScim(IgaImplementation):
 
         if len(user.resources) > 1:
             # Not expected that this should happen
-            logger.warning("Multiple hits found when searching in RI SCIM for {}".format(extid))
+            logger.warning(
+                "Multiple hits found when searching in RI SCIM for {}".format(extid)
+            )
 
         # Return the first user found
         return IgaPerson(
-            first=user.resources[0].name.given_name if user.resources[0].name and user.resources[
-                0].name.given_name else None,
-            last=user.resources[0].name.family_name if user.resources[0].name and user.resources[
-                0].name.family_name else None,
+            first=user.resources[0].name.given_name
+            if user.resources[0].name and user.resources[0].name.given_name
+            else None,
+            last=user.resources[0].name.family_name
+            if user.resources[0].name and user.resources[0].name.family_name
+            else None,
         )
-- 
GitLab