From 6322ba85a94b06eb61a8f0817209b6b050e49d83 Mon Sep 17 00:00:00 2001
From: Tore Brede <Tore.Brede@uib.no>
Date: Tue, 7 Dec 2021 10:35:14 +0100
Subject: [PATCH] GREG-123: Fixing test and small refactoring

---
 .../management/commands/import_from_orgreg.py | 45 ++++++++++---------
 .../management/test_import_from_orgreg.py     |  4 +-
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/greg/management/commands/import_from_orgreg.py b/greg/management/commands/import_from_orgreg.py
index e0033a1b..cc5d35a5 100644
--- a/greg/management/commands/import_from_orgreg.py
+++ b/greg/management/commands/import_from_orgreg.py
@@ -46,27 +46,30 @@ class Command(BaseCommand):
 
         # Acronyms can also be used as identifiers
         for acronym in settings.ORGREG_ACRONYMS:
-            if acronym == "nob" and ou.acronym.nob is not None:
-                self._upsert_identifier(
-                    settings.ORGREG_SOURCE,
-                    "acronym_" + acronym,
-                    ou.acronym.nob,
-                    ou.ou_id,
-                )
-            if acronym == "eng" and ou.acronym.eng is not None:
-                self._upsert_identifier(
-                    settings.ORGREG_SOURCE,
-                    "acronym_" + acronym,
-                    ou.acronym.eng,
-                    ou.ou_id,
-                )
-            if acronym == "nno" and ou.acronym.nno is not None:
-                self._upsert_identifier(
-                    settings.ORGREG_SOURCE,
-                    "acronym_" + acronym,
-                    ou.acronym.nno,
-                    ou.ou_id,
-                )
+            self.handle_acronym_identifier(acronym, ou)
+
+    def handle_acronym_identifier(self, acronym, ou):
+        if acronym == "nob" and ou.acronym.nob is not None:
+            self._upsert_identifier(
+                settings.ORGREG_SOURCE,
+                "acronym_" + acronym,
+                ou.acronym.nob,
+                ou.ou_id,
+            )
+        if acronym == "eng" and ou.acronym.eng is not None:
+            self._upsert_identifier(
+                settings.ORGREG_SOURCE,
+                "acronym_" + acronym,
+                ou.acronym.eng,
+                ou.ou_id,
+            )
+        if acronym == "nno" and ou.acronym.nno is not None:
+            self._upsert_identifier(
+                settings.ORGREG_SOURCE,
+                "acronym_" + acronym,
+                ou.acronym.nno,
+                ou.ou_id,
+            )
 
     @staticmethod
     def _get_external_key_from_ou(
diff --git a/greg/tests/management/test_import_from_orgreg.py b/greg/tests/management/test_import_from_orgreg.py
index 8a78a499..1c132b43 100644
--- a/greg/tests/management/test_import_from_orgreg.py
+++ b/greg/tests/management/test_import_from_orgreg.py
@@ -43,7 +43,7 @@ def orgreg_response():
                 parent=2,
                 name={"nob": "bar"},
                 external_keys=[],
-                acronym={"nob": "foo_acronym2"},
+                acronym={"nob": "foo_acronym3"},
             ),
             OrgUnit(
                 ou_id=2,
@@ -51,7 +51,7 @@ def orgreg_response():
                 parent=1,
                 name={"eng": "baz"},
                 external_keys=[],
-                acronym={"nob": "foo_acronym3"},
+                acronym={"nob": "foo_acronym2"},
             ),
         ]
     )
-- 
GitLab