Skip to content
Snippets Groups Projects
Verified Commit e6240f6b authored by Marte Fossum's avatar Marte Fossum Committed by Andreas Ellewsen
Browse files

Upgrade orgreg client

The old version of the client did not fetch short name correctly from
the api response. This new one does, but shortname is now called
short_name, forcing some small adjustments of the tests and their
settings.
parent 88c6df5c
No related branches found
No related tags found
1 merge request!359Upgrade orgreg client
Pipeline #168997 passed
...@@ -12,7 +12,7 @@ orgreg/v3/ as the url argument (note the trailing slash). ...@@ -12,7 +12,7 @@ orgreg/v3/ as the url argument (note the trailing slash).
""" """
import datetime import datetime
import logging import logging
from typing import Mapping, Optional, Union from typing import Mapping, Optional, Union, Any
from django.conf import settings from django.conf import settings
import orgreg_client import orgreg_client
...@@ -167,7 +167,9 @@ class OrgregImporter: ...@@ -167,7 +167,9 @@ class OrgregImporter:
) )
def _get_or_create_and_set_values( def _get_or_create_and_set_values(
self, ou: OrgUnit, values: Mapping[str, Union[str, int, bool]] self,
ou: OrgUnit,
values: Mapping[str, Union[str, int, bool, OrganizationalUnit]],
): ):
"""Upsert ou with latest values and store in processed dict.""" """Upsert ou with latest values and store in processed dict."""
...@@ -215,8 +217,7 @@ class OrgregImporter: ...@@ -215,8 +217,7 @@ class OrgregImporter:
# parent) # parent)
if ou.ou_id in self.processed: if ou.ou_id in self.processed:
return return
values: dict[str, Any] = {"deleted": False}
values = {"deleted": False}
# add names if present # add names if present
if ou.name: if ou.name:
if ou.name.nob: if ou.name.nob:
......
...@@ -4,7 +4,7 @@ import pytest ...@@ -4,7 +4,7 @@ import pytest
from django.core.management import call_command from django.core.management import call_command
from django.test import override_settings from django.test import override_settings
from django_q.models import Schedule from django_q.models import Schedule
from orgreg_client.models import OrgUnit from orgreg_client.models import OrgUnit, ExternalKey, LocalisedValue
from greg.importers.orgreg import OrgregImporter, OrganizationalUnit from greg.importers.orgreg import OrgregImporter, OrganizationalUnit
from greg.models import OuIdentifier from greg.models import OuIdentifier
...@@ -16,9 +16,21 @@ def org_unit(): ...@@ -16,9 +16,21 @@ def org_unit():
ou_id=1, ou_id=1,
valid_from=datetime.date(year=2020, month=2, day=6), valid_from=datetime.date(year=2020, month=2, day=6),
external_keys=[ external_keys=[
{"type": "legacy_stedkode", "source_system": "sapuio", "value": "1"} ExternalKey(type="legacy_stedkode", source_system="sapuio", value="1")
], ],
shortname={"nob": "FOO"}, short_name=LocalisedValue(nob="FOO", sme=None, nno=None, eng=None),
start_date=None,
category=None,
valid_to=None,
end_date=None,
email=None,
note=None,
postal_address=None,
visit_address=None,
building=None,
phone=None,
fax=None,
parent=None,
) )
return org_unit return org_unit
...@@ -37,6 +49,7 @@ def test_upsert_extra_identities(org_unit): ...@@ -37,6 +49,7 @@ def test_upsert_extra_identities(org_unit):
organizational_unit = OrganizationalUnit.objects.create( organizational_unit = OrganizationalUnit.objects.create(
name_nb="foo_nb", name_en="foo_en" name_nb="foo_nb", name_en="foo_en"
) )
org_importer = OrgregImporter() org_importer = OrgregImporter()
org_importer.processed[org_unit.ou_id] = organizational_unit org_importer.processed[org_unit.ou_id] = organizational_unit
org_importer.upsert_extra_identities(org_unit) org_importer.upsert_extra_identities(org_unit)
......
...@@ -23,7 +23,7 @@ ORGREG_CLIENT = { ...@@ -23,7 +23,7 @@ ORGREG_CLIENT = {
"headers": {"X-Gravitee-Api-Key": "foo"}, "headers": {"X-Gravitee-Api-Key": "foo"},
} }
ORGREG_EXTRA_IDS = [ ORGREG_EXTRA_IDS = [
{"fieldname": "shortname", "subfield": "nob"}, {"fieldname": "short_name", "subfield": "nob"},
{"type": "legacy_stedkode", "source": "sapuio"}, {"type": "legacy_stedkode", "source": "sapuio"},
] ]
ORGREG_ACRONYMS = [] ORGREG_ACRONYMS = []
...@@ -85,7 +85,7 @@ def unit_bar() -> OrganizationalUnit: ...@@ -85,7 +85,7 @@ def unit_bar() -> OrganizationalUnit:
def unit_foo3() -> OrganizationalUnit: def unit_foo3() -> OrganizationalUnit:
ou = OrganizationalUnit.objects.create(name_en="foo_unit3") ou = OrganizationalUnit.objects.create(name_en="foo_unit3")
OuIdentifier.objects.create( OuIdentifier.objects.create(
source="orgreg", name="shortname", value="FOO", orgunit=ou source="orgreg", name="short_name", value="FOO", orgunit=ou
) )
OuIdentifier.objects.create( OuIdentifier.objects.create(
source="sapuio", name="legacy_stedkode", value="123456", orgunit=ou source="sapuio", name="legacy_stedkode", value="123456", orgunit=ou
......
This diff is collapsed.
...@@ -15,7 +15,7 @@ djangorestframework = "*" ...@@ -15,7 +15,7 @@ djangorestframework = "*"
drf-spectacular = "*" drf-spectacular = "*"
pika-context-manager = {git = "https://git.app.uib.no/it-bott-integrasjoner/pika-context-manager.git", rev = "v1.2.0"} pika-context-manager = {git = "https://git.app.uib.no/it-bott-integrasjoner/pika-context-manager.git", rev = "v1.2.0"}
psycopg2-binary = "*" psycopg2-binary = "*"
orgreg-client = {git = "https://git.app.uib.no/it-bott-integrasjoner/orgreg-client.git", rev = "v0.2.3" } orgreg-client = {git = "https://git.app.uib.no/it-bott-integrasjoner/orgreg-client.git", rev = "v2.0.1" }
python = "^3.9" python = "^3.9"
python-json-logger = "*" python-json-logger = "*"
sentry-sdk = "*" sentry-sdk = "*"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment