From 8b9552569069cac4fc0a709b3eb72d0f1dfcb399 Mon Sep 17 00:00:00 2001 From: Magnus Theodor Engh Date: Tue, 7 May 2024 07:48:25 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Fikser=20s=C3=A5=20statbank=5Fgrupper=20bli?= =?UTF-8?q?r=20attributter=20og=20ikke=20overskriver=20tidligere=20kode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../produksjonstilskudd.py | 13 ++++++++----- tests/test_produksjonstilskudd.py | 13 ++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/ssb_jordbruk_fagfunksjoner/produksjonstilskudd.py b/src/ssb_jordbruk_fagfunksjoner/produksjonstilskudd.py index c8c78dc..a379626 100644 --- a/src/ssb_jordbruk_fagfunksjoner/produksjonstilskudd.py +++ b/src/ssb_jordbruk_fagfunksjoner/produksjonstilskudd.py @@ -253,11 +253,11 @@ class Produksjonstilskudd: } statbank_groups: ClassVar[dict[str, list[str]]] = { - "storfe": ["119", "120", "121"], - "ku": ["120", "121"], - "sau": ["145", "146", "139"], - "avlssvin": ["155", "156", "158", "159"], - "svin": ["154", "155", "156", "157", "158", "159"], + "statbank_storfe": ["119", "120", "121"], + "statbank_ku": ["120", "121"], + "statbank_sau": ["145", "146", "139"], + "statbank_avlssvin": ["155", "156", "158", "159"], + "statbank_svin": ["154", "155", "156", "157", "158", "159"], } def __init__(self) -> None: @@ -286,6 +286,9 @@ def _setup_dynamic_attributes(self) -> None: combined_dict.update(getattr(self, group, {})) setattr(self, combo_name, combined_dict) + for statbank_name, codes in self.statbank_groups.items(): + setattr(self, statbank_name, self._extract_from_codelist(codes)) + def _extract_from_codelist(self, numbers: list[str]) -> dict[str, str]: result = {} for code in numbers: diff --git a/tests/test_produksjonstilskudd.py b/tests/test_produksjonstilskudd.py index 58d3326..5ca4559 100644 --- a/tests/test_produksjonstilskudd.py +++ b/tests/test_produksjonstilskudd.py @@ -57,5 +57,16 @@ def test_dynamic_combinations_creation( ), "Instance should have 'frukt' combination attribute" combination = produksjonstilskudd_instance.frukt assert ( - "001" in combination or "271" in combination + "001" in combination and "271" in combination ), "'frukt' combination should contain codes from its groups" + + +def test_dynamic_statbank_creation( + produksjonstilskudd_instance: Produksjonstilskudd, +) -> None: + assert hasattr( + produksjonstilskudd_instance, "statbank_storfe" + ), "Instance should have 'statbank_storfe' attribute" + assert isinstance( + produksjonstilskudd_instance.statbank_storfe, dict + ), "'statbank_storfe' should be a dictionary" From 3b957fc5a99f4e342c034388578d24d2cc953d94 Mon Sep 17 00:00:00 2001 From: Magnus Theodor Engh Date: Tue, 7 May 2024 07:50:31 +0200 Subject: [PATCH 2/2] bump version number --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 28fdff3..34f69e3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ssb-jordbruk-fagfunksjoner" -version = "0.2.0" +version = "0.2.1" description = "SSB Jordbruk Fagfunksjoner" authors = ["Magnus Theodor Engh "] license = "MIT"