aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_core.py
diff options
context:
space:
mode:
authorAlex Schofield <git@ajschof.me>2025-02-26 19:58:35 +0000
committerAlex Schofield <git@ajschof.me>2025-02-26 19:58:35 +0000
commit5b8a40ff7d67c14384aceae4eb08112d4d337a4f (patch)
tree8997cf5cadc19231eb5c566fa1d7b645b156a12c /test/test_core.py
parentef762aa201d662ab0bfa3a40fcf1959d91914952 (diff)
downloadgdpr-obfuscator-5b8a40ff7d67c14384aceae4eb08112d4d337a4f.tar.gz
gdpr-obfuscator-5b8a40ff7d67c14384aceae4eb08112d4d337a4f.zip
add test to ensure that output byte stream is put_object compatible
Diffstat (limited to 'test/test_core.py')
-rw-r--r--test/test_core.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test_core.py b/test/test_core.py
index bb28607..701a586 100644
--- a/test/test_core.py
+++ b/test/test_core.py
@@ -72,3 +72,32 @@ def test_imported_module_completes_in_under_one_minute():
end = time.time()
assert end - start < 60
+
+
+def test_output_compatible_with_s3_put_object():
+ with mock_aws():
+ s3 = boto3.client("s3", region_name="eu-west-2")
+ bucket = "test-bucket"
+ key = "data/mock.csv"
+ output_key = "data/obfuscated.csv"
+
+ with open("test/data/mock_data.csv", "r") as f:
+ csv_content = f.read()
+
+ setup_s3(s3, bucket, key, csv_content)
+ path = f"s3://{bucket}/{key}"
+
+ json_input = json.dumps({"file_path": path, "pii_fields": ["name"]})
+ result_bytes = obfuscator.process_s3(json_input)
+
+ try:
+ response = s3.put_object(Bucket=bucket, Key=output_key, Body=result_bytes)
+ assert response["ResponseMetadata"]["HTTPStatusCode"] == 200
+
+ get_response = s3.get_object(Bucket=bucket, Key=output_key)
+ retrieved_content = get_response["Body"].read()
+
+ assert retrieved_content == result_bytes
+
+ except Exception as e:
+ pytest.fail(f"put_object did not like the output from process_s3: {e}")
git.ajschof.me — hosted by ajschofield — powered by cgit