test(api): API Permission ViewSet Abstract Class added

ref: #15 #248 #345
This commit is contained in:
2024-10-14 21:53:34 +09:30
parent 5edbdd76f4
commit 2690e17f93
8 changed files with 496 additions and 74 deletions

View File

@ -1,11 +0,0 @@
---
title: API Model Permission add Test Cases
description: No Fuss Computings model permissions add unit tests
date: 2024-06-16
template: project.html
about: https://gitlab.com/nofusscomputing/infrastructure/configuration-management/centurion_erp
---
::: app.api.tests.abstract.api_permissions.APIPermissionAdd
options:
show_source: true

View File

@ -1,11 +0,0 @@
---
title: Model Permissions Change Test Cases
description: No Fuss Computings model permissions change unit tests
date: 2024-06-15
template: project.html
about: https://gitlab.com/nofusscomputing/infrastructure/configuration-management/centurion_erp
---
::: app.api.tests.abstract.api_permissions.APIPermissionChange
options:
show_source: true

View File

@ -1,11 +0,0 @@
---
title: Model Permissions Delete Test Cases
description: No Fuss Computings model permissions delete unit tests
date: 2024-06-15
template: project.html
about: https://gitlab.com/nofusscomputing/infrastructure/configuration-management/centurion_erp
---
::: app.api.tests.abstract.api_permissions.APIPermissionDelete
options:
show_source: true

View File

@ -1,11 +0,0 @@
---
title: Model Permissions View Test Cases
description: No Fuss Computings model permissions view unit tests
date: 2024-06-15
template: project.html
about: https://gitlab.com/nofusscomputing/infrastructure/configuration-management/centurion_erp
---
::: app.api.tests.abstract.api_permissions.APIPermissionView
options:
show_source: true

View File

@ -1,12 +0,0 @@
---
title: API Model Permissions Test Cases
description: No Fuss Computings model permissions add unit tests
date: 2024-06-16
template: project.html
about: https://gitlab.com/nofusscomputing/infrastructure/configuration-management/centurion_erp
---
::: app.api.tests.abstract.api_permissions.APIPermissions
options:
show_source: true
inherited_members: true

View File

@ -10,14 +10,36 @@ Unit tests are written to aid in application stability and to assist in preventi
User Interface (UI) test are written _if applicable_ to test the user interface to ensure that it functions as it should. Changes to the UI will need to be tested.
!!! note
As of release v1.3, the UI has moved to it's [own project](https://github.com/nofusscomputing/centurion_erp_ui) with the current Django UI feature locked and depreciated.
In most cases functional tests will not need to be written, however you should confirm this with a maintainer.
Integration tests **will** be required if the development introduces code that interacts with an independent third-party application.
## Available Test classes
To aid in development we have written test classes that you can inherit from for your test classes
- API Permission Checks
_These tests ensure that only a user with the correct permissions can perform an action against a Model within Centurion_
- `api.tests.abstract.api_permissions_viewset.APIPermissionAdd` _Add permission checks_
- `api.tests.abstract.api_permissions_viewset.APIPermissionChange` _Change permission check_
- `api.tests.abstract.api_permissions_viewset.APIPermissionDelete` _Delete permission check_
- `api.tests.abstract.api_permissions_viewset.APIPermissionView` _View permission check_
- `api.tests.abstract.api_permissions_viewset.APIPermissions` _Add, Change, Delete and View permission checks_
## Writing Tests
We use class based tests. Each class will require a `setUpTestData` method for test setup. To furhter assist in the writing of tests, we have written the test cases for common items as an abstract class. You are advised to review the [test cases](./api/tests/index.md) and if it's applicable to the item you have added, than add the test case class to be inherited by your test class.
We use class based tests. Each class will require a `setUpTestData` method for test setup. To furhter assist in the writing of tests, we have written the test cases for common items as an abstract class. You are advised to inherit from our test classes _(see above)_ as a strating point and extend from there.
Naming of test classes is in `CamelCase` in format `<Model Name><what's being tested>` for example the class name for device model history entry tests would be `DeviceHistory`.
@ -30,7 +52,6 @@ Example of a model history test class.
``` py
import pytest
import unittest
import requests
from django.test import TestCase, Client
@ -82,22 +103,19 @@ example file system structure showing the layout of the tests directory for a mo
│      ├── test_<model name>_core_history.py
│      ├── test_<model name>_history_permission.py
│      ├── test_<model name>.py
│      └── test_<model name>_views.py
│      └── test_<model name>_viewsets.py
```
Tests are broken up into the type the test is (sub-directory to test), and they are `unit`, `functional`, `UI` and `integration`. These sub-directories each contain a sub-directory for each model they are testing.
Items to test include, and are not limited to:
- CRUD permissions admin site
- CRUD permissions api site - [ModelPermissions (API)](./api/tests/model_permissions_api.md)
- CRUD permissions api site
- CRUD permissions main site - [ModelPermissions](./api/tests/model_permissions.md)
- can only access organization object - [ModelPermissions](./api/tests/model_permissions.md), [ModelPermissions (API)](./api/tests/model_permissions_api.md)
- can only access organization object
- can access global object (still to require model CRUD permission)