Skip to content

Commit

Permalink
main: add tests for table model
Browse files Browse the repository at this point in the history
  • Loading branch information
balinthaller committed Dec 10, 2020
1 parent d5505e8 commit 0773fc7
Showing 1 changed file with 66 additions and 21 deletions.
87 changes: 66 additions & 21 deletions tests/model/test_carte_table_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -52,19 +48,18 @@ 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()

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(
Expand All @@ -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)
Expand All @@ -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"

0 comments on commit 0773fc7

Please sign in to comment.