refactor(base): adjust functional model test to use fixture kwargs

ref: #883 #735
This commit is contained in:
2025-07-24 15:34:15 +09:30
parent 482014004c
commit 6e1d0c747d
3 changed files with 54 additions and 69 deletions

View File

@ -9,24 +9,7 @@ class TenancyAbstractModelTestCases(
ModelTestCases
):
@pytest.fixture( scope = 'class', autouse = True)
def setup_organization(cls, request, model, organization_one, model_kwargs):
request.cls.organization = organization_one
if request.cls.kwargs_create_item:
request.cls.kwargs_create_item.update({
'organization': organization_one,
})
else:
request.cls.kwargs_create_item = {
'organization': organization_one,
}
pass

View File

@ -10,23 +10,21 @@ class ModelTestCases:
This test suite contains all of the functional common tests for **ALL**
Centurion Models.
For this test suite to function the following class attributes must be set
for all classes that inherit from this class:
For this test suite to function the following fixtures must be available
for this class:
- `kwargs_create_item: dict = {}`
- model
_Dict of the models fields and the values required for
`model.objects.create()`_
- model_kwargs
This attribute can either be a variable or a property. This attribute along
with any prefixed `paremetized_` will be merged from each class in the
Attribute prefixed `paremetized_` will be merged from each class in the
inheritence chain. In addition this object must return a dict if defined.
"""
@pytest.fixture( scope = 'function' )
def created_model(self, request, django_db_blocker, model, user):
def created_model(self, django_db_blocker, model, model_kwargs):
if model._meta.abstract:
@ -37,16 +35,14 @@ class ModelTestCases:
with django_db_blocker.unblock():
model_object = model.objects.create(
**request.cls.kwargs_create_item
**model_kwargs
)
yield model_object
yield model_object
with django_db_blocker.unblock():
@property
def kwargs_create_item(self):
return {}
model_object.delete()

View File

@ -123,6 +123,11 @@ All models must contain the core features, being:
_Enables the possibility within markdown fields to use its [tag](../user/core/markdown.md#model-reference--model-tag) to create a link to the model._
### History
Adding [History](./core/model_history.md) to a model is automatic. If there is a desire not to have model history it can be disabled by adding attribute `_audit_enabled` to the model class and setting its value to `False.`
## Validation Methods
Within All of our models including when they are created via an [API serializer](./serializers.md), the models [validators](https://docs.djangoproject.com/en/5.1/ref/models/instances/#validating-objects) are called. The models validators are responsible for ensuring that no data goes into the database that may create an inconsistancy.
@ -213,6 +218,44 @@ table_fields: list = [
```
## Tests
The following Unit test suites exists for models:
- Unit Tests
- model (Base Model) `core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model.CenturionAbstractModelInheritedCases`
- model (Sub-Model) `core.tests.unit.centurion_sub_abstract.test_unit_centurion_sub_abstract_model.CenturionSubAbstractModelInheritedCases`
- Serializer `api.tests.unit.test_unit_serializer.SerializerTestCases`
- ViewSet `api.tests.unit.test_unit_common_viewset.*`
- Functional Tests
- model `core.tests.functional.centurion_abstract.test_functional_centurion_abstract_model.CenturionAbstractModelInheritedCases`
- API Fields Render `api.tests.functional.test_functional_api_fields.APIFieldsInheritedCases`
!!! info
If you add a feature you will have to [write the test cases](./testing.md) for that feature if they are not covered by existing test cases.
Each model has the following Test Suites auto-magic created:
- API Permissions checks `api.tests.functional.test_functional_meta_permissions_api`
_Checks the CRUD permissions against the models API endpoints_
- Audit History Model checks, `core.tests.unit.centurion_audit_meta.test_unit_meta_audit_history_model`
_Confirms the model has a [`AuditHistory`](./api/models/audit_history.md) model and other checks as required for an `AuditHistory` model._
These auto-magic tests require no input and will be created on a model inheriting from [`CenturionModel`](./api/models/centurion.md) and run every time the tests are run.
## Depreciated Docs undergoing re-write
- ToDo
@ -259,43 +302,6 @@ This section details the additional items that may need to be done when adding a
- If the model is a primary model, add it to the model link slash command in `app/core/lib/slash_commands/linked_model.py` function `command_linked_model`
## History
Adding [History](./core/model_history.md) to a model is automatic. If there is a desire not to have model history it can be disabled by adding attribute `_audit_enabled` to the model class and setting its value to `False.`
## Tests
The following Unit test suites exists for models:
- Unit Tests
- model (Base Model) `core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model.CenturionAbstractModelInheritedCases`
- model (Sub-Model) `core.tests.unit.centurion_sub_abstract.test_unit_centurion_sub_abstract_model.CenturionSubAbstractModelInheritedCases`
- Functional Tests
- model `core.tests.functional.centurion_abstract.test_functional_centurion_abstract_model.CenturionAbstractModelInheritedCases`
- API Fields Render `api.tests.functional.test_functional_api_fields.APIFieldsInheritedCases`
!!! info
If you add a feature you will have to [write the test cases](./testing.md) for that feature if they are not covered by existing test cases.
Each model has the following Test Suites auto-magic created:
- API Permissions checks `api.tests.functional.test_functional_meta_permissions_api`
_Checks the CRUD permissions against the models API endpoints_
- Audit History Model checks, `core.tests.unit.centurion_audit_meta.test_unit_meta_audit_history_model`
_Confirms the model has a [`AuditHistory`](./api/models/audit_history.md) model and other checks as required for an `AuditHistory` model._
These auto-magic tests require no input and will be created on a model inheriting from [`CenturionModel`](./api/models/centurion.md) and run every time the tests are run.
## Knowledge Base Article linking