From f19d678bcf9c9424c2c2cb966f502a807031debd Mon Sep 17 00:00:00 2001 From: kirk Date: Mon, 4 Nov 2024 13:45:29 -0500 Subject: [PATCH] real stuff --- src/fideslang/models.py | 4 -- tests/fideslang/test_validation.py | 82 ++++++++++++++++-------------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/fideslang/models.py b/src/fideslang/models.py index bb15f25..834b16b 100644 --- a/src/fideslang/models.py +++ b/src/fideslang/models.py @@ -494,10 +494,6 @@ def validate_object_fields( f"The data type '{data_type}' on field '{field_name}' is not compatible with specified sub-fields. Convert to an 'object' field." ) - if (fields or declared_data_type == "object") and self.data_categories: - raise ValueError( - f"Object field '{field_name}' cannot have specified data_categories. Specify category on sub-field instead" - ) return self diff --git a/tests/fideslang/test_validation.py b/tests/fideslang/test_validation.py index d14c145..1e9a672 100644 --- a/tests/fideslang/test_validation.py +++ b/tests/fideslang/test_validation.py @@ -717,59 +717,63 @@ def test_return_all_elements_on_array_field(self): ) def test_data_categories_at_object_level(self): - with pytest.raises(ValidationError) as exc: - DatasetField( - name="test_field", - data_categories=["user"], - fides_meta=FidesMeta( - references=None, - identify=None, - primary_key=False, - data_type="object", - length=None, - return_all_elements=None, - read_only=None, - ), - fields=[DatasetField(name="nested_field")], - ) - assert_error_message_includes( - exc, "Object field 'test_field' cannot have specified data_categories" - ) - def test_object_field_conflicting_types(self): - with pytest.raises(ValidationError) as exc: - DatasetField( - name="test_field", - data_categories=["user"], - fides_meta=FidesMeta( - references=None, - identify=None, - primary_key=False, - data_type="string", - length=None, - return_all_elements=None, - read_only=None, - ), - fields=[DatasetField(name="nested_field")], - ) - assert_error_message_includes( - exc, "The data type 'string' on field 'test_field' is not compatible with" + field = DatasetField( + name="test_field", + data_categories=["user"], + fides_meta=FidesMeta( + references=None, + identify=None, + primary_key=False, + data_type="object", + length=None, + return_all_elements=None, + read_only=None, + ), + fields=[DatasetField(name="nested_field")], ) + assert field + assert field.data_categories == ["user"] + assert field.fides_meta.data_type == "object" + + def test_data_categories_on_nested_fields(self): - DatasetField( - name="test_field", + + field = DatasetField( + name="test_for_nest", + data_categories=["user"], fides_meta=FidesMeta( references=None, identify=None, primary_key=False, data_type="object", length=None, + return_all_elements=None, read_only=None, ), - fields=[DatasetField(name="nested_field", data_categories=["user"])], + fields=[ + DatasetField( + name="nested_field", + data_categories=["user"], + fides_meta=FidesMeta( + references=None, + identify=None, + primary_key=False, + data_type="string", + length=None, + read_only=None, + data_categories=["user"], + ), + ) + ], ) + assert field + assert field.data_categories == ["user"] + assert field.fields[0].data_categories == ["user"] + + class TestCollectionMeta: def test_invalid_collection_key(self):