Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,12 @@ class ConfigGroupHostModelPyTest(
def test_method_get_url_returns_str(self, mocker, model_instance):

pytest.xfail( reason = 'This model has no endpoint' )

def test_attribute_page_layout_table_fields(self):
pytest.xfail( reason = 'This model has no endpoint' )

def test_attribute_page_layout_dataset_columns_fields(self):
pytest.xfail( reason = 'This model has no endpoint' )

def test_attribute_page_layout_detail_section_columns(self):
pytest.xfail( reason = 'This model has no endpoint' )
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,12 @@ class ConfigGroupSoftwareModelInheritedCases(
class ConfigGroupSoftwareModelPyTest(
ConfigGroupSoftwareModelTestCases,
):
pass

def test_attribute_page_layout_table_fields(self):
pytest.xfail( reason = 'This model has no endpoint' )

def test_attribute_page_layout_dataset_columns_fields(self):
pytest.xfail( reason = 'This model has no endpoint' )

def test_attribute_page_layout_detail_section_columns(self):
pytest.xfail( reason = 'This model has no endpoint' )
1 change: 0 additions & 1 deletion app/core/models/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ class Actions(models.IntegerChoices):
"table": [
'created',
'action',
'content',
'user',
'nbsp',
[
Expand Down
2 changes: 0 additions & 2 deletions app/core/models/model_tickets.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,12 @@ class Meta:
"columns": [
[
'ticket',
'status_badge',
'created'
]
]
},
"table": [
'ticket',
'status_badge',
'created'
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,12 @@ def test_manager_tenancy_filter_tenant(self):

def test_manager_tenancy_select_related(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_table_fields(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_dataset_columns_fields(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_detail_section_columns(self):
pytest.xfail( reason = 'base model, test is n/a.' )
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,13 @@ def test_method_get_model_history_populates_field_before(self, model_instance):
del model_instance._before

assert model_instance.before == test_value


def test_attribute_page_layout_table_fields(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_dataset_columns_fields(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_detail_section_columns(self):
pytest.xfail( reason = 'base model, test is n/a.' )
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,12 @@ def test_method_clean_fields_calls_super_centurion_mixin(self):

def test_method_clean_fields_calls_super_tenancy_abstract(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_table_fields(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_dataset_columns_fields(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_detail_section_columns(self):
pytest.xfail( reason = 'base model, test is n/a.' )
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import importlib

import pytest

from django.apps import apps
Expand Down Expand Up @@ -183,7 +185,24 @@ def model(self, request):

yield request.cls.model_class



@pytest.fixture( scope = 'class')
def model_serializer(self, model):

serializer_name: str = 'centurionaudit_' + str(model._meta.model_name)[0:( len(model._meta.model_name) - len('audithistory') )]

serializer_module = importlib.import_module(
name = model._meta.app_label + '.serializers.' + str(
serializer_name
)
)


yield {
'view': getattr( serializer_module, 'ViewSerializer' )
}


@pytest.mark.skip( reason = 'ToDo: Figure out how to dynomagic add audit_model instance' )
def test_model_creation(self, model, user):
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,12 @@ def test_method_get_url_returns_str(self, model, model_instance):
"""

pytest.xfail( reason = 'Test not required as model does not have direct endpoint.' )

def test_attribute_page_layout_table_fields(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_dataset_columns_fields(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_detail_section_columns(self):
pytest.xfail( reason = 'base model, test is n/a.' )
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,12 @@ def test_method_clean_fields_calls_super_centurion_mixin(self):

def test_method_clean_fields_calls_super_tenancy_abstract(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_table_fields(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_dataset_columns_fields(self):
pytest.xfail( reason = 'base model, test is n/a.' )

def test_attribute_page_layout_detail_section_columns(self):
pytest.xfail( reason = 'base model, test is n/a.' )
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import importlib

import pytest

from django.apps import apps
Expand Down Expand Up @@ -188,6 +190,24 @@ def model(self, request):
return request.cls.model_class


@pytest.fixture( scope = 'class')
def model_serializer(self, model):

serializer_name: str = 'centurionmodelnote_' + str(model._meta.model_name).replace('centurionmodelnote', '')

serializer_module = importlib.import_module(
name = model._meta.app_label + '.serializers.' + str(
serializer_name
)
)


yield {
'view': getattr( serializer_module, 'ViewSerializer' )
}



@pytest.mark.skip( reason = 'ToDo: Figure out how to dynomagic add note_model instance' )
def test_model_creation(self, model, user):
pass
Expand Down
198 changes: 198 additions & 0 deletions app/core/tests/unit/mixin_centurion/test_unit_centurion_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,204 @@ def get(*args, **kwargs):
# Fail-Safe to ensure test writer fills all fields


def test_attribute_page_layout_table_fields(self, model, model_serializer):
"""Test page_layout key

Ensure that all table columns use valid serializer fields.
"""

if 'table' not in model.page_layout:
pytest.xfail( reason = 'model does not use any layout.' )



allowed_unknown_fields = [
'-action_delete-', # Adds delete button to UI
'nbsp', # blank cell
]

def check(field) -> list:

return_val = []

if model_serializer['view'].Meta.fields == '__all__':

if not hasattr(model, field):

return_val += [ field ]


elif(
not field in model_serializer['view'].Meta.fields
and field not in allowed_unknown_fields
):

return_val += [ field ]

return return_val



unknown_fields = []

for field in model.page_layout['table']:

if isinstance(field, list):

for sub_field in field:

unknown_fields += check(sub_field)

elif isinstance(field, dict):

field = field['field']

unknown_fields += check(field)

else:

unknown_fields += check(field)


assert len(unknown_fields) == 0, f"The following field(s) are not a model field {unknown_fields}"


def test_attribute_page_layout_dataset_columns_fields(self, model, model_serializer):
"""Test page_layout key

Ensure that all dataset columns use valid serializer fields.
"""

if 'dataset' not in model.page_layout:
pytest.xfail( reason = 'model does not use any layout.' )



allowed_unknown_fields = [
'-action_delete-', # Adds delete button to UI
'nbsp', # blank cell
]

def check(field) -> list:

return_val = []

if model_serializer['view'].Meta.fields == '__all__':

if not hasattr(model, field):

return_val += [ field ]


elif(
not field in model_serializer['view'].Meta.fields
and field not in allowed_unknown_fields
):

return_val += [ field ]

return return_val



unknown_fields = []

for column in model.page_layout['dataset']['columns']:

for field in column:

if isinstance(field, list):

for sub_field in field:

unknown_fields += check(sub_field)

elif isinstance(field, dict):

field = field['field']

unknown_fields += check(field)

else:

unknown_fields += check(field)


assert len(unknown_fields) == 0, f"The following field(s) are not a model field {unknown_fields}"



def test_attribute_page_layout_detail_section_columns(self, model, model_serializer):
"""Test page_layout key

Ensure that all detail section columns use valid serializer fields.
"""

if 'detail' not in model.page_layout:
pytest.xfail( reason = 'model does not use any layout.' )



allowed_unknown_fields = [
'-action_delete-', # Adds delete button to UI
'nbsp', # blank cell
]

def check(field) -> list:

return_val = []

if model_serializer['view'].Meta.fields == '__all__':

if not hasattr(model, field):

return_val += [ field ]


elif(
not field in model_serializer['view'].Meta.fields
and field not in allowed_unknown_fields
):

return_val += [ field ]

return return_val



unknown_fields = []

for tab in model.page_layout['detail']:

for section in tab:

for section_layout in ['fields', 'left', 'right']:

if section_layout not in section:
continue

for field in section[section_layout]:

if isinstance(field, list):

for sub_field in field:

unknown_fields += check(sub_field)

elif isinstance(field, dict):

field = field['field']

unknown_fields += check(field)

else:

unknown_fields += check(field)


assert len(unknown_fields) == 0, f"The following field(s) are not a model field {unknown_fields}"



@pytest.mark.module_core
class CenturionMixnPyTest(
Expand Down
Loading
Loading