Skip to content
Snippets Groups Projects
Verified Commit f7135da4 authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Fix orgreg import not seeing duplicates

The import script checked the source instead of the value when looking
for existing values. This caused the unique constraint on the
name+values combination to fail. We now check the value and name instead
of value and source.
parent 063dc771
No related branches found
No related tags found
2 merge requests!361Fix orgreg import not seeing duplicates,!360Fix orgreg import not seeing duplicates
Pipeline #169014 passed
......@@ -134,7 +134,7 @@ class OrgregImporter:
identify_in_db = (
self.processed[ou_id]
.identifiers.filter(
source=source,
value=identity_in_orgreg_value,
name=identity_type,
)
.first()
......
......@@ -66,3 +66,25 @@ def test_upsert_wrong_extra_identities(org_unit):
org_importer.processed[org_unit.ou_id] = organizational_unit
org_importer.upsert_extra_identities(org_unit)
assert OuIdentifier.objects.all().count() == 0
@pytest.mark.django_db
def test_upsert_extra_identities_update(org_unit):
"""
Verify that already imported values are updated
"""
organizational_unit = OrganizationalUnit.objects.create(
name_nb="foo_nb", name_en="foo_en"
)
OuIdentifier.objects.create(
name="short_name", value="FOO", orgunit=organizational_unit
)
OuIdentifier.objects.create(
name="legacy_stedkode", value="1", orgunit=organizational_unit, source="sapuio"
)
assert OuIdentifier.objects.all().count() == 2
org_importer = OrgregImporter()
org_importer.processed[org_unit.ou_id] = organizational_unit
org_importer.upsert_extra_identities(org_unit)
assert OuIdentifier.objects.all().count() == 2
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