Skip to content

Commit

Permalink
Add a test to verify that duplicate IDs in a schema will raise an error
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyMcCormick committed Jan 19, 2024
1 parent 0466b03 commit 3085445
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tests/test_datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,32 @@ def test_validation(self) -> None:
with self.assertRaises(ValidationError):
Schema(name="testSchema", id="#test_id", tables=[test_tbl, test_tbl])

# Creating a schema containing duplicate IDs should raise an error.
with self.assertRaises(ValidationError):
Schema(
name="testSchema",
id="#test_sch_id",
tables=[
Table(
name="testTable",
id="#test_tbl_id",
columns=[
Column(name="testColumn", id="#test_col_id", datatype="string"),
Column(name="testColumn2", id="#test_col_id", datatype="string"),
],
)
],
)

def test_id_map(self) -> None:
"""Test that the id_map is properly populated."""
test_col = Column(name="testColumn", id="#test_col_id", datatype="string")
test_tbl = Table(name="testTable", id="#test_table_id", columns=[test_col])
sch = Schema(name="testSchema", id="#test_schema_id", tables=[test_tbl])

# print(f"id map:\n {sch.id_map}")

for id in ["#test_col_id", "#test_table_id", "#test_schema_id"]:
self.assertTrue(id in sch.id_map, f"ID {id} is missing from id_map")
# Test that the id_map contains the expected id.
sch.get_object_by_id(id)


class SchemaVersionTest(unittest.TestCase):
Expand Down

0 comments on commit 3085445

Please sign in to comment.