Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thingscouldbeworse committed Nov 4, 2024
2 parents a445b8b + f19d678 commit 21eb174
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/fideslang/default_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
2. Copy/Paste the JSON response below
"""


COUNTRY_CODES = [
{"name": "Afghanistan", "alpha3Code": "AFG"},
{"name": "Åland Islands", "alpha3Code": "ALA"},
Expand Down
4 changes: 2 additions & 2 deletions src/fideslang/default_taxonomy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from .data_uses import DEFAULT_DATA_USES
from .organizations import DEFAULT_ORGANIZATIONS

sort_data_types = (
lambda x: x.parent_key if hasattr(x, "parent_key") and x.parent_key else x.fides_key
sort_data_types = lambda x: (
x.parent_key if hasattr(x, "parent_key") and x.parent_key else x.fides_key
)

DEFAULT_TAXONOMY = Taxonomy(
Expand Down
1 change: 1 addition & 0 deletions src/fideslang/manifests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module handles anything related to working with raw manifest files."""

import glob
from functools import reduce
from typing import Dict, List, Set, Union
Expand Down
4 changes: 3 additions & 1 deletion src/fideslang/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def valid_meta(cls, meta_values: Optional[FidesMeta]) -> Optional[FidesMeta]:
"The 'return_all_elements' attribute can only be specified on array fields."
)
return meta_values

@model_validator(mode="after")
def validate_object_fields(
self,
Expand All @@ -493,6 +493,8 @@ 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."
)

return self


# this is required for the recursive reference in the pydantic model:
DatasetField.model_rebuild()
Expand Down
1 change: 1 addition & 0 deletions src/fideslang/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module handles everything related to parsing resources into Pydantic models,
either from local files or the server.
"""

from typing import Dict, List

from fideslang import FidesModel, Taxonomy, model_map
Expand Down
1 change: 1 addition & 0 deletions src/fideslang/validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Contains all of the additional validation for the resource models.
"""

import re
from collections import Counter
from typing import Annotated, Dict, List, Optional, Pattern, Set, Tuple
Expand Down
19 changes: 11 additions & 8 deletions tests/fideslang/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,21 +717,26 @@ def test_return_all_elements_on_array_field(self):
)

def test_data_categories_at_object_level(self):
# Data categories at the object level ARE allowed now
DatasetField(

field = DatasetField(
name="test_field",
data_categories=["user"],
fides_meta=FidesMeta(
references=None,
identity=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):

field = DatasetField(
Expand All @@ -756,17 +761,15 @@ def test_data_categories_on_nested_fields(self):
primary_key=False,
data_type="string",
length=None,
return_all_elements=None,
read_only=None,
data_categories=["user"],
),
)
],
)

assert field
assert field.fields
print(f"fields: {field.fields}")
print(f"field: {vars(field)}")
assert field.data_categories == ["user"]
assert field.fields[0].data_categories == ["user"]


Expand Down

0 comments on commit 21eb174

Please sign in to comment.