test(core): API Permission Test Cases for ticket_base model
ref: #731 #723
This commit is contained in:
@ -4,6 +4,8 @@ from django.test import (
|
||||
TestCase
|
||||
)
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
|
||||
|
||||
def pytest_pycollect_makeitem(collector, name, obj):
|
||||
@ -25,3 +27,62 @@ def pytest_pycollect_makeitem(collector, name, obj):
|
||||
@pytest.fixture(autouse=True)
|
||||
def enable_db_access_for_all_tests(db): # pylint: disable=W0613:unused-argument
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def create_model(request, django_db_blocker):
|
||||
|
||||
item = None
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
item = request.cls.model.objects.create(
|
||||
**request.cls.kwargs_create_item
|
||||
)
|
||||
|
||||
request.cls.item = item
|
||||
|
||||
yield item
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
request.cls.item.delete()
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def organization_one(django_db_blocker):
|
||||
|
||||
item = None
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
item = Organization.objects.create(
|
||||
name = 'org one'
|
||||
)
|
||||
|
||||
yield item
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
item.delete()
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def organization_two(django_db_blocker):
|
||||
|
||||
item = None
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
item = Organization.objects.create(
|
||||
name = 'org two'
|
||||
)
|
||||
|
||||
yield item
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
item.delete()
|
||||
|
14
app/core/tests/functional/ticket_base/conftest.py
Normal file
14
app/core/tests/functional/ticket_base/conftest.py
Normal file
@ -0,0 +1,14 @@
|
||||
import pytest
|
||||
|
||||
from core.models.ticket_base import TicketBase
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model(request):
|
||||
|
||||
request.cls.model = TicketBase
|
||||
|
||||
yield request.cls.model
|
||||
|
||||
del request.cls.model
|
@ -0,0 +1,95 @@
|
||||
import pytest
|
||||
|
||||
from api.tests.functional.test_functional_api_permissions import (
|
||||
APIPermissionsInheritedCases,
|
||||
)
|
||||
|
||||
|
||||
|
||||
class PermissionsAPITestCases(
|
||||
APIPermissionsInheritedCases,
|
||||
):
|
||||
|
||||
add_data: dict = {
|
||||
'title': 'ticket one',
|
||||
'description': 'sadsa'
|
||||
}
|
||||
|
||||
app_namespace = 'v2'
|
||||
|
||||
change_data = {'description': 'device'}
|
||||
|
||||
delete_data = {}
|
||||
|
||||
kwargs_create_item: dict = {
|
||||
'title': 'ticket two',
|
||||
'description': 'sadsa'
|
||||
}
|
||||
|
||||
kwargs_create_item_diff_org: dict = {
|
||||
'title': 'ticket three',
|
||||
'description': 'sadsa'
|
||||
}
|
||||
|
||||
url_kwargs: dict = {}
|
||||
|
||||
url_name = '_api_v2_ticket'
|
||||
|
||||
url_view_kwargs: dict = {}
|
||||
|
||||
|
||||
|
||||
def test_returned_data_from_user_and_global_organizations_only(self):
|
||||
"""Check items returned
|
||||
|
||||
This test case is a over-ride of a test case with the same name.
|
||||
This model is not a tenancy model making this test not-applicable.
|
||||
|
||||
Items returned from the query Must be from the users organization and
|
||||
global ONLY!
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class TicketBasePermissionsAPIInheritedCases(
|
||||
PermissionsAPITestCases,
|
||||
):
|
||||
|
||||
add_data: dict = None
|
||||
|
||||
kwargs_create_item: dict = None
|
||||
|
||||
kwargs_create_item_diff_org: dict = None
|
||||
|
||||
|
||||
@pytest.fixture(scope='class')
|
||||
def inherited_var_setup(self, request):
|
||||
|
||||
request.cls.url_kwargs.update({
|
||||
'ticket_model': self.model._meta.model_name
|
||||
})
|
||||
|
||||
request.cls.url_view_kwargs.update({
|
||||
'ticket_model': self.model._meta.model_name
|
||||
})
|
||||
|
||||
|
||||
|
||||
@pytest.fixture(scope='class', autouse = True)
|
||||
def class_setup(self, request, django_db_blocker,
|
||||
model,
|
||||
var_setup,
|
||||
prepare,
|
||||
inherited_var_setup,
|
||||
create_model,
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class TicketBasePermissionsAPIPyTest(
|
||||
PermissionsAPITestCases,
|
||||
):
|
||||
|
||||
pass
|
@ -34,6 +34,6 @@ As with any other object within Centurion, the addition of a feature requires it
|
||||
|
||||
- `Functional` Test Cases
|
||||
|
||||
- `core.tests.functional.contact.<*>.<Inherited class name>InheritedCases` _(if inheriting from `Contact`)_ Test cases for sub-models
|
||||
- `core.tests.functional.ticket_base.<*>.<Inherited class name>InheritedCases` _(if inheriting from `TicketBase`)_ Test cases for sub-models
|
||||
|
||||
The above listed test cases cover **all** tests for objects that are inherited from the base class. To complete the tests, you will need to add test cases for the differences your model introduces.
|
||||
|
Reference in New Issue
Block a user