Skip to content

Commit

Permalink
Added integration test for repseudo from stable id to default encrypt…
Browse files Browse the repository at this point in the history
…ion (#368)

* Added integration test for repseudo from stable id to default encryption
* Bump new version

---------

Co-authored-by: Bjørn-Andre Skaar <[email protected]>
  • Loading branch information
RupinderKaurSSB and bjornandre authored Apr 4, 2024
1 parent a64af93 commit aa50dc7
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 98 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dapla-toolbelt-pseudo"
version = "1.4.0"
version = "1.5.0"
description = "Pseudonymization extensions for Dapla"
authors = ["Dapla Developers <[email protected]>"]
license = "MIT"
Expand Down
18 changes: 8 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ def df_personer_fnr_ff31_encrypted() -> pl.DataFrame:


@pytest.fixture
def df_personer_daead_encrypted_ssb_common_key_2() -> pl.DataFrame:
CSV_FILE = (
"tests/data/personer_pseudonymized_default_encryption_ssb_common_key_2.csv"
)
return pl.read_csv(
CSV_FILE,
def df_personer_daead_encrypted_ssb_common_key_1() -> pl.DataFrame:
JSON_FILE = "tests/data/personer_pseudonymized_daead_ssb_common_key_1.json"
return pl.read_json(
JSON_FILE,
schema={
"fnr": pl.String,
"fornavn": pl.String,
Expand All @@ -103,8 +101,8 @@ def df_personer_daead_encrypted_ssb_common_key_2() -> pl.DataFrame:


@pytest.fixture
def df_personer_pseudo_stable_id() -> pl.DataFrame:
JSON_FILE = "tests/data/person_3_sid_deid.json"
def df_personer_daead_encrypted_ssb_common_key_2() -> pl.DataFrame:
JSON_FILE = "tests/data/personer_pseudonymized_daead_ssb_common_key_2.json"
return pl.read_json(
JSON_FILE,
schema={
Expand All @@ -118,8 +116,8 @@ def df_personer_pseudo_stable_id() -> pl.DataFrame:


@pytest.fixture
def df_personer_depseudo_stable_id() -> pl.DataFrame:
JSON_FILE = "tests/data/person_3_sid.json"
def df_personer_pseudo_stable_id_daead_encrypted_ssb_common_key_2() -> pl.DataFrame:
JSON_FILE = "tests/data/personer_pseudonymized_sid_daead_ssb_common_key_2.json"
return pl.read_json(
JSON_FILE,
schema={
Expand Down
26 changes: 0 additions & 26 deletions tests/data/kontaktopplysninger.json

This file was deleted.

23 changes: 0 additions & 23 deletions tests/data/person_3_sid.json

This file was deleted.

23 changes: 0 additions & 23 deletions tests/data/person_3_sid_deid.json

This file was deleted.

23 changes: 23 additions & 0 deletions tests/data/personer_pseudonymized_daead_ssb_common_key_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"fnr": "AWIRfKLSNfR0ID+wBzogEcUT7JQPayk7Gosij6SXr8s=",
"fornavn": "AWIRfKKWWRC1hURqsYw4S/h/NitvuP6bO/R7",
"etternavn": "AWIRfKIKAGiRoGTd/Cid5gxsIDx4H1ya6w==",
"kjonn": "M",
"fodselsdato": "020995"
},
{
"fnr": "AWIRfKKLagk0LqYCKpiC4xfPkHqIWGVfc3wg5gUwRNE=",
"fornavn": "AWIRfKJuYBaBQIXIprRO9UFDXNLd4YXcHtY=",
"etternavn": "AWIRfKLzOfzOw+Bdo9zIa4savOOeAiEr",
"kjonn": "M",
"fodselsdato": "060970"
},
{
"fnr": "AWIRfKIzL1T9iZqt+pLjNbHMsLa0aKSszsRrLiLSAAg=",
"fornavn": "AWIRfKKsIDQgWLnpsSln38z1RSfHjjL8FS4=",
"etternavn": "AWIRfKIKAGiRoGTd/Cid5gxsIDx4H1ya6w==",
"kjonn": "M",
"fodselsdato": "180999"
}
]
23 changes: 23 additions & 0 deletions tests/data/personer_pseudonymized_daead_ssb_common_key_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"fnr": "AXzg5m91ZV4nzWpqYtdo+jfHIE40fLbDxug3Lr8Tamg=",
"fornavn": "AXzg5m+lFA0OcH5L1eONOgzZCItnUaXIUshA",
"etternavn": "AXzg5m+e0GDK5mhcOknMY71YcP3BxMlnOA==",
"kjonn": "M",
"fodselsdato": "020995"
},
{
"fnr": "AXzg5m9Ec/KlRWJBHfpwIsksDwmA7F/jhojyhBU8pec=",
"fornavn": "AXzg5m/zZww19slv39H+s/wiILYBaeYqPEk=",
"etternavn": "AXzg5m9FgnhAZErrWTmEQaRZCm4/t1AG",
"kjonn": "M",
"fodselsdato": "060970"
},
{
"fnr": "AXzg5m/FALW/hNStYCElfyMR7/9rD398dEolAsISK6A=",
"fornavn": "AXzg5m92Bx8qcV7AEXa7m4IAbvUyk2iPaD4=",
"etternavn": "AXzg5m+e0GDK5mhcOknMY71YcP3BxMlnOA==",
"kjonn": "M",
"fodselsdato": "180999"
}
]
23 changes: 23 additions & 0 deletions tests/data/personer_pseudonymized_sid_daead_ssb_common_key_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"fnr": "jJuuj0i",
"fornavn": "AXzg5m+lFA0OcH5L1eONOgzZCItnUaXIUshA",
"etternavn": "AXzg5m+e0GDK5mhcOknMY71YcP3BxMlnOA==",
"kjonn": "M",
"fodselsdato": "020995"
},
{
"fnr": "ylc9488",
"fornavn": "AXzg5m/zZww19slv39H+s/wiILYBaeYqPEk=",
"etternavn": "AXzg5m9FgnhAZErrWTmEQaRZCm4/t1AG",
"kjonn": "M",
"fodselsdato": "060970"
},
{
"fnr": "yeLfkaL",
"fornavn": "AXzg5m92Bx8qcV7AEXa7m4IAbvUyk2iPaD4=",
"etternavn": "AXzg5m+e0GDK5mhcOknMY71YcP3BxMlnOA==",
"kjonn": "M",
"fodselsdato": "180999"
}
]
11 changes: 7 additions & 4 deletions tests/integration/test_integration_deseudonymize.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ def test_depseudonymize_default_encryption(
@integration_test()
def test_depseudonymize_sid(
setup: Generator[None, None, None],
df_personer_pseudo_stable_id_daead_encrypted_ssb_common_key_2: pl.DataFrame,
df_personer: pl.DataFrame,
df_personer_pseudo_stable_id: pl.DataFrame,
df_personer_depseudo_stable_id: pl.DataFrame,
) -> None:
result = (
Depseudonymize.from_polars(df_personer_pseudo_stable_id)
Depseudonymize.from_polars(
df_personer_pseudo_stable_id_daead_encrypted_ssb_common_key_2
)
.on_fields("fnr")
.with_stable_id()
.on_fields("fornavn", "etternavn")
.with_default_encryption(custom_key="ssb-common-key-2")
.run()
.to_polars()
)
assert result.equals(df_personer_depseudo_stable_id)
assert result.equals(df_personer)
8 changes: 0 additions & 8 deletions tests/integration/test_integration_pseudonymize.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import inspect
import json
import typing as t
from collections.abc import Generator
from functools import partial
from pathlib import Path
from unittest.mock import ANY

import pandas as pd
import polars as pl
import pytest

from dapla_pseudo import Pseudonymize
from tests.integration.utils import get_calling_function_name
Expand Down
33 changes: 30 additions & 3 deletions tests/integration/test_integration_repseudonymize.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,48 @@ def test_repseudonymize_from_default_encryption_to_fpe(
.run()
.to_polars()
)

assert result_df.equals(df_personer_fnr_ff31_encrypted)


@integration_test()
def test_repseudonymize_change_keys(
setup: Generator[None, None, None],
df_personer_daead_encrypted_ssb_common_key_2: pl.DataFrame,
df_personer_fnr_daead_encrypted: pl.DataFrame,
df_personer_daead_encrypted_ssb_common_key_1: pl.DataFrame,
) -> None:
result = (
Repseudonymize.from_polars(df_personer_fnr_daead_encrypted)
.on_fields("fnr")
Repseudonymize.from_polars(df_personer_daead_encrypted_ssb_common_key_1)
.on_fields("fnr", "fornavn", "etternavn")
.from_default_encryption()
.to_default_encryption(custom_key="ssb-common-key-2")
.run()
.to_polars()
)

assert result.equals(df_personer_daead_encrypted_ssb_common_key_2)


@integration_test()
def test_repseudonymize_from_sid_to_daead(
setup: Generator[None, None, None],
df_personer: pl.DataFrame,
df_personer_daead_encrypted_ssb_common_key_1: pl.DataFrame,
df_personer_daead_encrypted_ssb_common_key_2: pl.DataFrame,
df_personer_pseudo_stable_id_daead_encrypted_ssb_common_key_2: pl.DataFrame,
) -> None:
result = (
Repseudonymize.from_polars(
df_personer_pseudo_stable_id_daead_encrypted_ssb_common_key_2
)
.on_fields("fnr")
.from_stable_id()
.to_default_encryption()
.on_fields("fornavn", "etternavn")
.from_default_encryption(custom_key="ssb-common-key-2")
.to_default_encryption(custom_key="ssb-common-key-1")
.run()
.to_polars()
)

assert result.equals(df_personer_daead_encrypted_ssb_common_key_1)

0 comments on commit aa50dc7

Please sign in to comment.