diff --git a/tests/model/test_carte_table_model.py b/tests/model/test_carte_table_model.py index 1c3502f..34f9a86 100644 --- a/tests/model/test_carte_table_model.py +++ b/tests/model/test_carte_table_model.py @@ -3,18 +3,16 @@ from flyover.model.carte_table_model import TableMetadata, ColumnMetadata, TableType from databuilder.models.table_metadata import ColumnMetadata as DatabuilderColumn -from databuilder.models.table_metadata import DescriptionMetadata as DatabuilderDescription +from databuilder.models.table_metadata import ( + DescriptionMetadata as DatabuilderDescription, +) from databuilder.models.table_metadata import TableMetadata as DatabuilderTable - class TestColumnMetadata(unittest.TestCase): def test_from_databuilder(self): source_metadata = DatabuilderColumn( - "test-name", - "test-description", - "test-type", - 1 + "test-name", "test-description", "test-type", 1 ) result = ColumnMetadata.from_databuilder(source_metadata) @@ -27,7 +25,7 @@ def test_from_frontmatter(self): source_metadata = { "name": "test-name", "description": "test-description", - "type": "test-type" + "type": "test-type", } result = ColumnMetadata.from_frontmatter(source_metadata) @@ -37,9 +35,7 @@ def test_from_frontmatter(self): assert result.column_type == "test-type" def test_from_frontmatter_no_values(self): - source_metadata = { - "name": "test-name" - } + source_metadata = {"name": "test-name"} result = ColumnMetadata.from_frontmatter(source_metadata) @@ -52,9 +48,7 @@ def test_from_frontmatter_raises_with_no_name(self): def test_to_frontmatter(self): source = ColumnMetadata( - name="test-name", - column_type="test-type", - description="test-description" + name="test-name", column_type="test-type", description="test-description" ) result = source.to_frontmatter() @@ -62,9 +56,10 @@ def test_to_frontmatter(self): assert result == { "name": "test-name", "type": "test-type", - "description": "test-description" + "description": "test-description", } + class TestTableMetadata(unittest.TestCase): def test_from_databuilder(self): source_metadata = DatabuilderTable( @@ -77,7 +72,7 @@ def test_from_databuilder(self): DatabuilderColumn("test-col-1", "test-descr1", "test-type1", 1), DatabuilderColumn("test-col-2", "test-descr2", "test-type2", 2), ], - False + False, ) result = TableMetadata.from_databuilder(source_metadata) @@ -86,18 +81,68 @@ def test_from_databuilder(self): assert result.location == "test-connection://test-cluster.test-db/test-name" assert result.connection == "test-connection" assert len(result.columns) == 2 - assert result.columns[0].__repr__() == ColumnMetadata(name="test-col-1", description="test-descr1", column_type="test-type1").__repr__() - assert result.columns[1].__repr__() == ColumnMetadata(name="test-col-2", description="test-descr2", column_type="test-type2").__repr__() + assert ( + result.columns[0].__repr__() + == ColumnMetadata( + name="test-col-1", description="test-descr1", column_type="test-type1" + ).__repr__() + ) + assert ( + result.columns[1].__repr__() + == ColumnMetadata( + name="test-col-2", description="test-descr2", column_type="test-type2" + ).__repr__() + ) assert result.table_type == TableType.TABLE def test_from_frontmatter(self): - pass + source_metadata = { + "title": "test-name", + "database": "test-db", + "location": "test-location", + "connection": "test-connection", + "columns": [], + "table_type": "table", + } + + result = TableMetadata.from_frontmatter(source_metadata, "test-description") + + assert result.name == "test-name" + assert result.database == "test-db" + assert result.location == "test-location" + assert result.connection == "test-connection" + assert result.columns == [] + assert result.table_type == TableType.TABLE def test_from_frontmatter_no_values(self): - pass + source_metadata = {"title": "test-name"} + + result = TableMetadata.from_frontmatter(source_metadata, None) + + assert result.name == "test-name" + assert result.description is None + assert result.columns == [] def test_from_frontmatter_raises_with_no_name(self): - pass + self.assertRaises(KeyError, TableMetadata.from_frontmatter, {}, None) def test_to_frontmatter(self): - pass + source = TableMetadata( + name="test-name", + database="test-db", + description="test-description", + location="test-location", + connection="test-connection", + columns=[], + table_type=TableType.VIEW, + ) + + metadata, content = source.to_frontmatter() + + assert content == "test-description" + assert metadata["title"] == "test-name" + assert metadata["connection"] == "test-connection" + assert metadata["location"] == "test-location" + assert metadata["database"] == "test-db" + assert metadata["columns"] == [] + assert metadata["table_type"] == "view"