Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/finish-db-models #7

Merged
merged 15 commits into from
Nov 7, 2020
Prev Previous commit
Next Next commit
Add tests for checking primary keys and indexes
  • Loading branch information
JacksonMaxfield committed Oct 30, 2020
commit 62e16b2fe0699b2fee311479211cbbd2ebcc2322
4 changes: 2 additions & 2 deletions cdp_backend/bin/create_cdp_database_uml.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _construct_dot_file(output_file: str):

# First pass: create nodes for each model
for model_name, cls in inspect.getmembers(models, inspect.isclass):
if model_name not in ["Model", "datetime"]:
if model_name not in models.TESTING_IGNORE_CLASSES:
# Attach fields for each model by using the Example
fields = []
m = cls.Example()
Expand Down Expand Up @@ -106,7 +106,7 @@ def _construct_dot_file(output_file: str):

# Second pass: Create DAG
for model_name, cls in inspect.getmembers(models, inspect.isclass):
if model_name not in ["Model", "datetime"]:
if model_name not in models.TESTING_IGNORE_CLASSES:
# Attach fields for each model by using the Example
m = cls.Example()

Expand Down
11 changes: 11 additions & 0 deletions cdp_backend/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

from . import validators
from ..utils import file_utils
from .types import IndexedField, IndexedFieldSet, Order

###############################################################################

TESTING_IGNORE_CLASSES = [
"Model",
"datetime",
"IndexedField",
"IndexedFieldSet",
"Order",
]

###############################################################################

Expand Down
11 changes: 10 additions & 1 deletion cdp_backend/tests/database/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def test_validate_model_definitions():
for model_name, cls in inspect.getmembers(models, inspect.isclass):
if model_name not in ["Model", "datetime"]:
if model_name not in models.TESTING_IGNORE_CLASSES:
assert hasattr(cls, "Example")
assert hasattr(cls, "_PRIMARY_KEYS")
assert hasattr(cls, "_INDEXES")
Expand All @@ -27,6 +27,15 @@ def test_validate_model_definitions():
if isinstance(field, ReferenceField):
assert field_name.endswith("_ref")

# Check that all primary keys are valid attributes of the model
for pk in cls._PRIMARY_KEYS:
assert hasattr(m, pk)

# Check that all index fields are valid attributes of the model
for idx_field_set in cls._INDEXES:
for idx_field in idx_field_set.fields:
assert hasattr(m, idx_field.name)


def test_cdp_database_model_has_no_cyclic_dependencies(tmpdir):
# Minor edits to:
Expand Down