From 7456aac35f7026cdf0daa2dd0f227469ad87c694 Mon Sep 17 00:00:00 2001 From: Tore Brede <Tore.Brede@uib.no> Date: Wed, 16 Feb 2022 12:37:30 +0100 Subject: [PATCH] GREG-214: Fixing formatting and updating test --- greg/models.py | 4 ++-- gregui/tests/api/views/test_ous.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/greg/models.py b/greg/models.py index d604e78a..d1fa4b78 100644 --- a/greg/models.py +++ b/greg/models.py @@ -487,8 +487,8 @@ class OrganizationalUnit(BaseModel): """Gets the Norwegian bokmaal acronym if it exists""" return ( self.identifiers.filter(name="acronym_nob") - .values_list("value", flat=True) - .first() + .values_list("value", flat=True) + .first() ) def __repr__(self) -> str: diff --git a/gregui/tests/api/views/test_ous.py b/gregui/tests/api/views/test_ous.py index de64c656..b512e105 100644 --- a/gregui/tests/api/views/test_ous.py +++ b/gregui/tests/api/views/test_ous.py @@ -33,3 +33,33 @@ def test_orgreg_field_empty_if_identifier_not_present( assert len(data) == 1 assert data[0]["orgreg_id"] is None + + +@pytest.mark.django_db +def test_acronym_nob_populated_if_identifier_present( + unit_foo, client, log_in, user_sponsor, sponsor_foo +): + acronym_nob = "test-unit-01" + OuIdentifier.objects.create( + source="orgreg", name="acronym_nob", value=acronym_nob, orgunit=unit_foo + ) + log_in(user_sponsor) + + resp = client.get(reverse("gregui-v1:ou-list")) + data = resp.json() + + assert len(data) == 1 + assert data[0]["acronym_nob"] == acronym_nob + + +@pytest.mark.django_db +def test_acronym_nob_field_empty_if_identifier_not_present( + unit_foo, client, log_in, user_sponsor, sponsor_foo +): + log_in(user_sponsor) + + resp = client.get(reverse("gregui-v1:ou-list")) + data = resp.json() + + assert len(data) == 1 + assert data[0]["acronym_nob"] is None -- GitLab