|
| 1 | +from asynctest import TestCase as AsyncTestCase |
| 2 | + |
| 3 | +from ..data_agreement_model import DataAgreementV1Schema, DataAgreementV1 |
| 4 | +from marshmallow.exceptions import ValidationError |
| 5 | + |
| 6 | + |
| 7 | +class TestDataAgreementV1Model(AsyncTestCase): |
| 8 | + |
| 9 | + def test_data_agreement_model(self): |
| 10 | + data_agreement_dict = { |
| 11 | + "@context": "https://raw.githubusercontent.com/decentralised-dataexchange/automated-data-agreements/main/interface-specs/data-agreement-schema/v1/data-agreement-schema-context.jsonld", |
| 12 | + "data_controller_name": "XYZ Corp", |
| 13 | + "data_controller_url": "https://xyz.com", |
| 14 | + "purpose": "Issuance of parking permit", |
| 15 | + "purpose_description": "Issuance of parking permit", |
| 16 | + "lawful_basis": "consent", |
| 17 | + "method_of_use": "data-source", |
| 18 | + "data_policy": { |
| 19 | + "data_retention_period": 365, |
| 20 | + "policy_URL": "https://clarifyhealth.com/privacy-policy/", |
| 21 | + "jurisdiction": "EU", |
| 22 | + "industry_sector": "Retail", |
| 23 | + "geographic_restriction": "EU", |
| 24 | + "storage_location": "EU" |
| 25 | + }, |
| 26 | + "personal_data": [ |
| 27 | + { |
| 28 | + "attribute_name": "First Name", |
| 29 | + "attribute_sensitive": True, |
| 30 | + "attribute_category": "Biographic", |
| 31 | + "attribute_description": "First name of the person" |
| 32 | + } |
| 33 | + ], |
| 34 | + "dpia": { |
| 35 | + "dpia_date": "2022-02-13T15:25:18.117255+00:00", |
| 36 | + "dpia_summary_url": "https://org.com/dpia_results.html" |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + data_agreement: DataAgreementV1 = DataAgreementV1Schema().load(data_agreement_dict) |
| 41 | + |
| 42 | + assert data_agreement.pii_controller_name == "XYZ Corp" |
| 43 | + |
| 44 | + assert len(data_agreement.personal_data) == 1 |
| 45 | + |
| 46 | + self.assertIsNone( |
| 47 | + data_agreement.personal_data[0].attribute_id, "Attribute ID should be None") |
| 48 | + |
| 49 | + data_agreement_dict.pop("data_controller_name") |
| 50 | + with self.assertRaises(ValidationError) as ctx: |
| 51 | + data_agreement: DataAgreementV1 = DataAgreementV1Schema().load(data_agreement_dict) |
| 52 | + |
| 53 | + self.assertTrue( |
| 54 | + "Missing data for required field." in str(ctx.exception)) |
0 commit comments