aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_core.py
diff options
context:
space:
mode:
authorAlex Schofield <git@ajschof.me>2025-02-21 03:20:12 +0000
committerAlex Schofield <git@ajschof.me>2025-02-21 03:20:12 +0000
commitc3a0d2f04d5338a3ffc115de37fcd56dc85a092c (patch)
tree13acc6e7797720bc173cea6c3622bc3039d38d4f /test/test_core.py
parentdcb40cd87546619c48055b4cc6440ccea6bb1ab1 (diff)
downloadgdpr-obfuscator-c3a0d2f04d5338a3ffc115de37fcd56dc85a092c.tar.gz
gdpr-obfuscator-c3a0d2f04d5338a3ffc115de37fcd56dc85a092c.zip
update main unit test for core functionality
Diffstat (limited to 'test/test_core.py')
-rw-r--r--test/test_core.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/test_core.py b/test/test_core.py
new file mode 100644
index 0000000..b472e59
--- /dev/null
+++ b/test/test_core.py
@@ -0,0 +1,47 @@
+from gdpr_obfuscator import Obfuscator
+import pytest
+from moto import mock_aws
+import boto3
+import csv
+import random
+
+
+def setup_s3(s3_client, bucket: str, key: str, content: str):
+ s3_client.create_bucket(
+ Bucket=bucket,
+ CreateBucketConfiguration={"LocationConstraint": "eu-west-2"},
+ )
+ s3_client.put_object(Bucket=bucket, Key=key, Body=content)
+
+
+@pytest.fixture(autouse=True)
+def s3_client():
+ with mock_aws():
+ yield boto3.client("s3", "eu-west-2")
+
+
+obfuscator = Obfuscator()
+
+
+def test_main_integration():
+ with mock_aws():
+ s3 = boto3.client("s3", region_name="eu-west-2")
+ bucket = "test-bucket"
+ key = "data/mock.csv"
+
+ with open("mock_data.csv", "r") as f:
+ csv_content = f.read()
+
+ with open("mock_data.csv", "r") as f:
+ reader = list(csv.DictReader(f))
+ rand_row = random.randint(0, len(reader) - 1)
+ rand_name = reader[rand_row]["name"]
+
+ setup_s3(s3, bucket, key, csv_content)
+
+ path = f"s3://{bucket}/{key}"
+
+ result = obfuscator.process_s3(path, ["name"])
+ result_str = result.decode("utf-8")
+
+ assert rand_name not in result_str
git.ajschof.me — hosted by ajschofield — powered by cgit