@ -1,482 +0,0 @@
|
||||
import django
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.shortcuts import reverse
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.relations import Hyperlink
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
from access.models.team import Team
|
||||
from access.models.team_user import TeamUsers
|
||||
|
||||
from api.tests.abstract.api_fields import APITenancyObject
|
||||
|
||||
User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
class ModelNotesNotesAPIFields(
|
||||
APITenancyObject
|
||||
):
|
||||
"""Base Model Notes Test Cases
|
||||
|
||||
This Test Suite must be included in ALL model notes tests
|
||||
|
||||
Args:
|
||||
APITenancyObject (class): Base test cases for ALL API fields
|
||||
"""
|
||||
|
||||
model = None
|
||||
|
||||
view_name: str = None
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user and item
|
||||
2. Create an item
|
||||
|
||||
"""
|
||||
|
||||
self.organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.view_user = User.objects.create_user(username="test_user_view", password="password", is_superuser = True)
|
||||
|
||||
|
||||
view_permissions = Permission.objects.get(
|
||||
codename = 'view_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = self.model._meta.app_label,
|
||||
model = self.model._meta.model_name,
|
||||
)
|
||||
)
|
||||
|
||||
view_team = Team.objects.create(
|
||||
team_name = 'view_team',
|
||||
organization = self.organization,
|
||||
)
|
||||
|
||||
view_team.permissions.set([view_permissions])
|
||||
|
||||
teamuser = TeamUsers.objects.create(
|
||||
team = view_team,
|
||||
user = self.view_user
|
||||
)
|
||||
|
||||
|
||||
@classmethod
|
||||
def make_request(self):
|
||||
client = Client()
|
||||
url = reverse('v2:' + self.view_name + '-detail', kwargs=self.url_view_kwargs)
|
||||
|
||||
|
||||
client.force_login(self.view_user)
|
||||
response = client.get(url)
|
||||
|
||||
self.api_data = response.data
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_model_notes(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
This test case is to override a test case of the same name
|
||||
as this model does not have a `model_notes` field
|
||||
|
||||
model_notes field must exist
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
def test_api_field_type_model_notes(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
This test case is to override a test case of the same name
|
||||
as this model does not have a `model_notes` field
|
||||
|
||||
model_notes field must be str
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_content(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
content field must exist
|
||||
"""
|
||||
|
||||
assert 'content' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_content(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
content field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['content']) is str
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_content_type(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
content_type field must exist
|
||||
"""
|
||||
|
||||
assert 'content_type' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_content_type(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
content_type field must be int
|
||||
"""
|
||||
|
||||
assert type(self.api_data['content_type']) is int
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_created_by(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
created_by field must exist
|
||||
"""
|
||||
|
||||
assert 'created_by' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_created_by(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
created_by field must be dict
|
||||
"""
|
||||
|
||||
assert type(self.api_data['created_by']) is dict
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_created_by_id(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
created_by.id field must exist
|
||||
"""
|
||||
|
||||
assert 'id' in self.api_data['created_by']
|
||||
|
||||
|
||||
def test_api_field_type_created_by_id(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
created_by.id field must be int
|
||||
"""
|
||||
|
||||
assert type(self.api_data['created_by']['id']) is int
|
||||
|
||||
|
||||
def test_api_field_exists_created_by_display_name(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
created_by.display_name field must exist
|
||||
"""
|
||||
|
||||
assert 'display_name' in self.api_data['created_by']
|
||||
|
||||
|
||||
def test_api_field_type_created_by_display_name(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
created_by.display_name field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['created_by']['display_name']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_created_by_first_name(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
created_by.first_name field must exist
|
||||
"""
|
||||
|
||||
assert 'first_name' in self.api_data['created_by']
|
||||
|
||||
|
||||
def test_api_field_type_created_by_first_name(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
created_by.first_name field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['created_by']['first_name']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_created_by_last_name(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
created_by.last_name field must exist
|
||||
"""
|
||||
|
||||
assert 'last_name' in self.api_data['created_by']
|
||||
|
||||
|
||||
def test_api_field_type_created_by_last_name(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
created_by.last_name field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['created_by']['last_name']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_created_by_username(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
created_by.username field must exist
|
||||
"""
|
||||
|
||||
assert 'username' in self.api_data['created_by']
|
||||
|
||||
|
||||
def test_api_field_type_created_by_username(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
created_by.username field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['created_by']['username']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_created_by_is_active(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
created_by.is_active field must exist
|
||||
"""
|
||||
|
||||
assert 'is_active' in self.api_data['created_by']
|
||||
|
||||
|
||||
def test_api_field_type_created_by_is_active(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
created_by.is_active field must be bool
|
||||
"""
|
||||
|
||||
assert type(self.api_data['created_by']['is_active']) is bool
|
||||
|
||||
|
||||
def test_api_field_exists_created_by_url(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
created_by.url field must exist
|
||||
"""
|
||||
|
||||
assert 'url' in self.api_data['created_by']
|
||||
|
||||
|
||||
def test_api_field_type_created_by_url(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
created_by.url field must be Hyperlink
|
||||
"""
|
||||
|
||||
assert type(self.api_data['created_by']['url']) is Hyperlink
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_modified_by(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
modified_by field must exist
|
||||
"""
|
||||
|
||||
assert 'modified_by' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_modified_by(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
modified_by field must be dict
|
||||
"""
|
||||
|
||||
assert type(self.api_data['modified_by']) is dict
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_modified_by_id(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
modified_by.id field must exist
|
||||
"""
|
||||
|
||||
assert 'id' in self.api_data['modified_by']
|
||||
|
||||
|
||||
def test_api_field_type_modified_by_id(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
modified_by.id field must be int
|
||||
"""
|
||||
|
||||
assert type(self.api_data['modified_by']['id']) is int
|
||||
|
||||
|
||||
def test_api_field_exists_modified_by_display_name(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
modified_by.display_name field must exist
|
||||
"""
|
||||
|
||||
assert 'display_name' in self.api_data['modified_by']
|
||||
|
||||
|
||||
def test_api_field_type_modified_by_display_name(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
modified_by.display_name field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['modified_by']['display_name']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_modified_by_first_name(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
modified_by.first_name field must exist
|
||||
"""
|
||||
|
||||
assert 'first_name' in self.api_data['modified_by']
|
||||
|
||||
|
||||
def test_api_field_type_modified_by_first_name(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
modified_by.first_name field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['modified_by']['first_name']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_modified_by_last_name(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
modified_by.last_name field must exist
|
||||
"""
|
||||
|
||||
assert 'last_name' in self.api_data['modified_by']
|
||||
|
||||
|
||||
def test_api_field_type_modified_by_last_name(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
modified_by.last_name field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['modified_by']['last_name']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_modified_by_username(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
modified_by.username field must exist
|
||||
"""
|
||||
|
||||
assert 'username' in self.api_data['modified_by']
|
||||
|
||||
|
||||
def test_api_field_type_modified_by_username(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
modified_by.username field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['modified_by']['username']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_modified_by_is_active(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
modified_by.is_active field must exist
|
||||
"""
|
||||
|
||||
assert 'is_active' in self.api_data['modified_by']
|
||||
|
||||
|
||||
def test_api_field_type_modified_by_is_active(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
modified_by.is_active field must be bool
|
||||
"""
|
||||
|
||||
assert type(self.api_data['modified_by']['is_active']) is bool
|
||||
|
||||
|
||||
def test_api_field_exists_modified_by_url(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
modified_by.url field must exist
|
||||
"""
|
||||
|
||||
assert 'url' in self.api_data['modified_by']
|
||||
|
||||
|
||||
def test_api_field_type_modified_by_url(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
modified_by.url field must be Hyperlink
|
||||
"""
|
||||
|
||||
assert type(self.api_data['modified_by']['url']) is Hyperlink
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,221 +0,0 @@
|
||||
import django
|
||||
|
||||
from django.contrib.auth.models import AnonymousUser, Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
from access.models.team import Team
|
||||
from access.models.team_user import TeamUsers
|
||||
|
||||
# Test Cases
|
||||
from api.tests.abstract.test_metadata_functional import MetadataAttributesFunctional
|
||||
from api.tests.abstract.api_permissions_viewset import APIPermissions
|
||||
from api.tests.abstract.api_serializer_viewset import SerializersTestCases
|
||||
|
||||
from settings.models.app_settings import AppSettings
|
||||
|
||||
User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
class ModelNotesViewSetBase:
|
||||
"""Common Test Case setup for model notes"""
|
||||
|
||||
viewset = None
|
||||
"""Viewset that will be tested"""
|
||||
|
||||
app_namespace = 'v2'
|
||||
|
||||
url_name: str = None
|
||||
"""URL namew to test"""
|
||||
|
||||
change_data = {'content': 'changed data'}
|
||||
|
||||
delete_data = {}
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user and item
|
||||
. create an organization that is different to item
|
||||
2. Create a team
|
||||
3. create teams with each permission: view, add, change, delete
|
||||
4. create a user per team
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization = organization
|
||||
|
||||
different_organization = Organization.objects.create(name='test_different_organization')
|
||||
|
||||
self.different_organization = different_organization
|
||||
|
||||
|
||||
self.model = self.viewset.model
|
||||
|
||||
|
||||
|
||||
self.global_organization = Organization.objects.create(
|
||||
name = 'test_global_organization'
|
||||
)
|
||||
|
||||
app_settings = AppSettings.objects.get(
|
||||
owner_organization = None
|
||||
)
|
||||
|
||||
app_settings.global_organization = self.global_organization
|
||||
|
||||
app_settings.save()
|
||||
|
||||
self.view_user = User.objects.create_user(username="test_user_view", password="password")
|
||||
|
||||
|
||||
self.add_data = {
|
||||
'content': 'team_post'
|
||||
}
|
||||
|
||||
|
||||
view_permissions = Permission.objects.get(
|
||||
codename = 'view_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = self.model._meta.app_label,
|
||||
model = self.model._meta.model_name,
|
||||
)
|
||||
)
|
||||
|
||||
view_team = Team.objects.create(
|
||||
team_name = 'view_team',
|
||||
organization = organization,
|
||||
)
|
||||
|
||||
view_team.permissions.set([view_permissions])
|
||||
|
||||
|
||||
|
||||
add_permissions = Permission.objects.get(
|
||||
codename = 'add_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = self.model._meta.app_label,
|
||||
model = self.model._meta.model_name,
|
||||
)
|
||||
)
|
||||
|
||||
add_team = Team.objects.create(
|
||||
team_name = 'add_team',
|
||||
organization = organization,
|
||||
)
|
||||
|
||||
add_team.permissions.set([add_permissions])
|
||||
|
||||
|
||||
|
||||
change_permissions = Permission.objects.get(
|
||||
codename = 'change_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = self.model._meta.app_label,
|
||||
model = self.model._meta.model_name,
|
||||
)
|
||||
)
|
||||
|
||||
change_team = Team.objects.create(
|
||||
team_name = 'change_team',
|
||||
organization = organization,
|
||||
)
|
||||
|
||||
change_team.permissions.set([change_permissions])
|
||||
|
||||
|
||||
|
||||
delete_permissions = Permission.objects.get(
|
||||
codename = 'delete_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = self.model._meta.app_label,
|
||||
model = self.model._meta.model_name,
|
||||
)
|
||||
)
|
||||
|
||||
delete_team = Team.objects.create(
|
||||
team_name = 'delete_team',
|
||||
organization = organization,
|
||||
)
|
||||
|
||||
delete_team.permissions.set([delete_permissions])
|
||||
|
||||
|
||||
self.no_permissions_user = User.objects.create_user(username="test_no_permissions", password="password")
|
||||
|
||||
|
||||
teamuser = TeamUsers.objects.create(
|
||||
team = view_team,
|
||||
user = self.view_user
|
||||
)
|
||||
|
||||
self.add_user = User.objects.create_user(username="test_user_add", password="password")
|
||||
teamuser = TeamUsers.objects.create(
|
||||
team = add_team,
|
||||
user = self.add_user
|
||||
)
|
||||
|
||||
self.change_user = User.objects.create_user(username="test_user_change", password="password")
|
||||
teamuser = TeamUsers.objects.create(
|
||||
team = change_team,
|
||||
user = self.change_user
|
||||
)
|
||||
|
||||
self.delete_user = User.objects.create_user(username="test_user_delete", password="password")
|
||||
teamuser = TeamUsers.objects.create(
|
||||
team = delete_team,
|
||||
user = self.delete_user
|
||||
)
|
||||
|
||||
|
||||
self.different_organization_user = User.objects.create_user(username="test_different_organization_user", password="password")
|
||||
|
||||
|
||||
different_organization_team = Team.objects.create(
|
||||
team_name = 'different_organization_team',
|
||||
organization = different_organization,
|
||||
)
|
||||
|
||||
different_organization_team.permissions.set([
|
||||
view_permissions,
|
||||
add_permissions,
|
||||
change_permissions,
|
||||
delete_permissions,
|
||||
])
|
||||
|
||||
TeamUsers.objects.create(
|
||||
team = different_organization_team,
|
||||
user = self.different_organization_user
|
||||
)
|
||||
|
||||
|
||||
|
||||
class ModelNotesPermissionsAPI(
|
||||
ModelNotesViewSetBase,
|
||||
APIPermissions,
|
||||
):
|
||||
"""Model Notes Permission Test Cases"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class ModelNotesSerializer(
|
||||
ModelNotesViewSetBase,
|
||||
SerializersTestCases,
|
||||
):
|
||||
"""Model Notes Serializer Test Cases"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ModelNotesMetadata(
|
||||
ModelNotesViewSetBase,
|
||||
MetadataAttributesFunctional,
|
||||
):
|
||||
"""Model Notes Metadata Test Cases"""
|
||||
|
||||
pass
|
@ -1,286 +0,0 @@
|
||||
import django
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
|
||||
from centurion.tests.abstract.mock_view import MockView
|
||||
|
||||
User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
class ModelNotesSerializerTestCases:
|
||||
""" Model Notes Serializer Test Suite
|
||||
|
||||
These test cases are for model notes. This Test Suite mist be included
|
||||
in serializer tests for a notes model.
|
||||
|
||||
Actual test class must supply the following:
|
||||
|
||||
- self.item - a created note instance
|
||||
- self.note_model - a model instance the note will be made for
|
||||
- self.note_model_two - a model instance the note will be made for
|
||||
- self.valid_data - Serializer dict containing ALL fields for the model.
|
||||
"""
|
||||
|
||||
model = None
|
||||
"""Notes Model to test"""
|
||||
|
||||
model_serializer = None
|
||||
"""Notes Model Serializer to test"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test"""
|
||||
|
||||
self.organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization_two = Organization.objects.create(name='test_org_two')
|
||||
|
||||
self.content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
)
|
||||
|
||||
self.content_type_two = ContentType.objects.get(
|
||||
app_label = 'core',
|
||||
model = 'modelnotes',
|
||||
)
|
||||
|
||||
self.user = User.objects.create_user(username="test_user_view", password="password")
|
||||
|
||||
self.user_two = User.objects.create_user(username="test_user_view_two", password="password")
|
||||
|
||||
|
||||
|
||||
def test_serializer_valid_data_is_valid(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that valid data does not throw an exception
|
||||
"""
|
||||
|
||||
data = self.valid_data.copy()
|
||||
|
||||
mock_view = MockView(
|
||||
user = self.user,
|
||||
model = self.model
|
||||
)
|
||||
|
||||
mock_view.kwargs = {
|
||||
'model_id': self.note_model.id
|
||||
}
|
||||
|
||||
serializer = self.model_serializer(
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = data
|
||||
)
|
||||
|
||||
assert serializer.is_valid(raise_exception = True)
|
||||
|
||||
|
||||
def test_serializer_valid_data_field_content_type(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that the `content_type` user is obtained by the request object
|
||||
and not the data passed.
|
||||
"""
|
||||
|
||||
data = self.valid_data.copy()
|
||||
|
||||
mock_view = MockView(
|
||||
user = self.user,
|
||||
model = self.model
|
||||
)
|
||||
|
||||
mock_view.kwargs = {
|
||||
'model_id': self.note_model.id
|
||||
}
|
||||
|
||||
serializer = self.model_serializer(
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = data
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
serializer.save()
|
||||
|
||||
assert serializer.instance.content_type == self.content_type
|
||||
|
||||
|
||||
def test_serializer_valid_data_field_model(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that the `model` user is obtained by the request object
|
||||
and not the data passed.
|
||||
"""
|
||||
|
||||
data = self.valid_data.copy()
|
||||
|
||||
mock_view = MockView(
|
||||
user = self.user,
|
||||
model = self.model
|
||||
)
|
||||
|
||||
mock_view.kwargs = {
|
||||
'model_id': self.note_model.id
|
||||
}
|
||||
|
||||
serializer = self.model_serializer(
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = data
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
serializer.save()
|
||||
|
||||
assert serializer.instance.model == self.note_model
|
||||
|
||||
|
||||
def test_serializer_valid_data_field_created_by(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that the `created_by` user is obtained by the request object
|
||||
and not the data passed.
|
||||
"""
|
||||
|
||||
data = self.valid_data.copy()
|
||||
|
||||
mock_view = MockView(
|
||||
user = self.user,
|
||||
model = self.model
|
||||
)
|
||||
|
||||
mock_view.kwargs = {
|
||||
'model_id': self.note_model.id
|
||||
}
|
||||
|
||||
serializer = self.model_serializer(
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = data
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
serializer.save()
|
||||
|
||||
assert serializer.instance.created_by == self.user
|
||||
|
||||
|
||||
def test_serializer_valid_data_field_modified_by(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that the `modified_by` user is obtained by the request object
|
||||
and not the data passed.
|
||||
"""
|
||||
|
||||
data = self.valid_data.copy()
|
||||
|
||||
mock_view = MockView(
|
||||
user = self.user,
|
||||
model = self.model
|
||||
)
|
||||
|
||||
mock_view.action = 'update'
|
||||
|
||||
mock_view.kwargs = {
|
||||
'model_id': self.note_model.id
|
||||
}
|
||||
|
||||
serializer = self.model_serializer(
|
||||
instance = self.item,
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = data
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
serializer.save()
|
||||
|
||||
assert serializer.instance.modified_by == self.user
|
||||
|
||||
|
||||
def test_serializer_valid_data_field_content_partial_update(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that the `content` is updated when editing.
|
||||
"""
|
||||
|
||||
data = {
|
||||
'content': 'a comment to update for partial update'
|
||||
}
|
||||
|
||||
mock_view = MockView(
|
||||
user = self.user,
|
||||
model = self.model
|
||||
)
|
||||
|
||||
mock_view.action = 'partial_update'
|
||||
|
||||
mock_view.kwargs = {
|
||||
'model_id': self.note_model.id
|
||||
}
|
||||
|
||||
serializer = self.model_serializer(
|
||||
instance = self.item,
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = data,
|
||||
partial = True,
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
serializer.save()
|
||||
|
||||
assert serializer.instance.content == data['content']
|
||||
|
||||
|
||||
def test_serializer_valid_data_field_content_update(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that the `content` is updated when editing.
|
||||
"""
|
||||
|
||||
data = self.valid_data.copy()
|
||||
|
||||
mock_view = MockView(
|
||||
user = self.user,
|
||||
model = self.model
|
||||
)
|
||||
|
||||
mock_view.action = 'update'
|
||||
|
||||
mock_view.kwargs = {
|
||||
'model_id': self.note_model.id
|
||||
}
|
||||
|
||||
serializer = self.model_serializer(
|
||||
instance = self.item,
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = data
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
serializer.save()
|
||||
|
||||
assert serializer.instance.content == data['content']
|
@ -1,125 +0,0 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from core.viewsets.manufacturer_notes import ViewSet
|
||||
|
||||
from core.tests.abstract.test_functional_notes_viewset import (
|
||||
ModelNotesViewSetBase,
|
||||
ModelNotesMetadata,
|
||||
ModelNotesPermissionsAPI,
|
||||
ModelNotesSerializer
|
||||
)
|
||||
|
||||
|
||||
|
||||
class ViewSetBase(
|
||||
ModelNotesViewSetBase
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
url_name = '_api_v2_manufacturer_note'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
self.item = self.viewset.model.objects.create(
|
||||
organization = self.organization,
|
||||
content = 'a random comment',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
self.other_org_item = self.viewset.model.objects.create(
|
||||
organization = self.different_organization,
|
||||
content = 'a random comment',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.different_organization,
|
||||
name = 'note model other_org_item',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
|
||||
self.global_org_item = self.viewset.model.objects.create(
|
||||
organization = self.global_organization,
|
||||
content = 'a random comment global_organization',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.global_organization,
|
||||
name = 'note model global_organization',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
self.url_kwargs = {
|
||||
'model_id': self.item.model.pk,
|
||||
}
|
||||
|
||||
self.url_view_kwargs = {
|
||||
'model_id': self.item.model.pk,
|
||||
'pk': self.item.id
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ManufacturerModelNotesPermissionsAPI(
|
||||
ViewSetBase,
|
||||
ModelNotesPermissionsAPI,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
|
||||
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 global model making this test not-applicable.
|
||||
|
||||
Items returned from the query Must be from the users organization and
|
||||
global ONLY!
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ManufacturerBaseModelNotesSerializer(
|
||||
ViewSetBase,
|
||||
ModelNotesSerializer,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ManufacturerModelNotesMetadata(
|
||||
ViewSetBase,
|
||||
ModelNotesMetadata,
|
||||
TestCase,
|
||||
|
||||
):
|
||||
|
||||
pass
|
@ -1,54 +0,0 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from core.tests.abstract.model_notes_api_fields import ModelNotesNotesAPIFields
|
||||
|
||||
from core.models.manufacturer_notes import Manufacturer, ManufacturerNotes
|
||||
|
||||
|
||||
|
||||
class ManufacturerNotesAPI(
|
||||
ModelNotesNotesAPIFields,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = ManufacturerNotes
|
||||
|
||||
view_name: str = '_api_v2_manufacturer_note'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Call parent setup
|
||||
2. Create a model note
|
||||
3. add url kwargs
|
||||
4. make the API request
|
||||
|
||||
"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
content = 'a random comment',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = Manufacturer.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
|
||||
self.url_view_kwargs = {
|
||||
'model_id': self.item.model.pk,
|
||||
'pk': self.item.pk
|
||||
}
|
||||
|
||||
self.make_request()
|
@ -1,54 +0,0 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from core.tests.abstract.model_notes_api_fields import ModelNotesNotesAPIFields
|
||||
|
||||
from core.models.ticket.ticket_category_notes import TicketCategory, TicketCategoryNotes
|
||||
|
||||
|
||||
|
||||
class NotesAPI(
|
||||
ModelNotesNotesAPIFields,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = TicketCategoryNotes
|
||||
|
||||
view_name: str = '_api_v2_ticket_category_note'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Call parent setup
|
||||
2. Create a model note
|
||||
3. add url kwargs
|
||||
4. make the API request
|
||||
|
||||
"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
content = 'a random comment',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = TicketCategory.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
|
||||
self.url_view_kwargs = {
|
||||
'model_id': self.item.model.pk,
|
||||
'pk': self.item.pk
|
||||
}
|
||||
|
||||
self.make_request()
|
@ -1,125 +0,0 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from core.viewsets.ticket_category_notes import ViewSet
|
||||
|
||||
from core.tests.abstract.test_functional_notes_viewset import (
|
||||
ModelNotesViewSetBase,
|
||||
ModelNotesMetadata,
|
||||
ModelNotesPermissionsAPI,
|
||||
ModelNotesSerializer
|
||||
)
|
||||
|
||||
|
||||
|
||||
class ViewSetBase(
|
||||
ModelNotesViewSetBase
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
url_name = '_api_v2_ticket_category_note'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
self.item = self.viewset.model.objects.create(
|
||||
organization = self.organization,
|
||||
content = 'a random comment',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
self.other_org_item = self.viewset.model.objects.create(
|
||||
organization = self.different_organization,
|
||||
content = 'a random comment',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.different_organization,
|
||||
name = 'note model other_org_item',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
|
||||
self.global_org_item = self.viewset.model.objects.create(
|
||||
organization = self.global_organization,
|
||||
content = 'a random comment global_organization',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.global_organization,
|
||||
name = 'note model global_organization',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
self.url_kwargs = {
|
||||
'model_id': self.item.model.pk,
|
||||
}
|
||||
|
||||
self.url_view_kwargs = {
|
||||
'model_id': self.item.model.pk,
|
||||
'pk': self.item.id
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ManufacturerModelNotesPermissionsAPI(
|
||||
ViewSetBase,
|
||||
ModelNotesPermissionsAPI,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
|
||||
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 global model making this test not-applicable.
|
||||
|
||||
Items returned from the query Must be from the users organization and
|
||||
global ONLY!
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ManufacturerBaseModelNotesSerializer(
|
||||
ViewSetBase,
|
||||
ModelNotesSerializer,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ManufacturerModelNotesMetadata(
|
||||
ViewSetBase,
|
||||
ModelNotesMetadata,
|
||||
TestCase,
|
||||
|
||||
):
|
||||
|
||||
pass
|
@ -1,54 +0,0 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from core.tests.abstract.model_notes_api_fields import ModelNotesNotesAPIFields
|
||||
|
||||
from core.models.ticket.ticket_comment_category_notes import TicketCommentCategory, TicketCommentCategoryNotes
|
||||
|
||||
|
||||
|
||||
class NotesAPI(
|
||||
ModelNotesNotesAPIFields,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = TicketCommentCategoryNotes
|
||||
|
||||
view_name: str = '_api_v2_ticket_comment_category_note'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Call parent setup
|
||||
2. Create a model note
|
||||
3. add url kwargs
|
||||
4. make the API request
|
||||
|
||||
"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
content = 'a random comment',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = TicketCommentCategory.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
|
||||
self.url_view_kwargs = {
|
||||
'model_id': self.item.model.pk,
|
||||
'pk': self.item.pk
|
||||
}
|
||||
|
||||
self.make_request()
|
@ -1,125 +0,0 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from core.viewsets.ticket_comment_category_notes import ViewSet
|
||||
|
||||
from core.tests.abstract.test_functional_notes_viewset import (
|
||||
ModelNotesViewSetBase,
|
||||
ModelNotesMetadata,
|
||||
ModelNotesPermissionsAPI,
|
||||
ModelNotesSerializer
|
||||
)
|
||||
|
||||
|
||||
|
||||
class ViewSetBase(
|
||||
ModelNotesViewSetBase
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
url_name = '_api_v2_ticket_comment_category_note'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
self.item = self.viewset.model.objects.create(
|
||||
organization = self.organization,
|
||||
content = 'a random comment',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
self.other_org_item = self.viewset.model.objects.create(
|
||||
organization = self.different_organization,
|
||||
content = 'a random comment',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.different_organization,
|
||||
name = 'note model other_org_item',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
|
||||
self.global_org_item = self.viewset.model.objects.create(
|
||||
organization = self.global_organization,
|
||||
content = 'a random comment global_organization',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.global_organization,
|
||||
name = 'note model global_organization',
|
||||
),
|
||||
created_by = self.view_user,
|
||||
modified_by = self.view_user,
|
||||
)
|
||||
|
||||
self.url_kwargs = {
|
||||
'model_id': self.item.model.pk,
|
||||
}
|
||||
|
||||
self.url_view_kwargs = {
|
||||
'model_id': self.item.model.pk,
|
||||
'pk': self.item.id
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ManufacturerModelNotesPermissionsAPI(
|
||||
ViewSetBase,
|
||||
ModelNotesPermissionsAPI,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
|
||||
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 global model making this test not-applicable.
|
||||
|
||||
Items returned from the query Must be from the users organization and
|
||||
global ONLY!
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ManufacturerBaseModelNotesSerializer(
|
||||
ViewSetBase,
|
||||
ModelNotesSerializer,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ManufacturerModelNotesMetadata(
|
||||
ViewSetBase,
|
||||
ModelNotesMetadata,
|
||||
TestCase,
|
||||
|
||||
):
|
||||
|
||||
pass
|
@ -1,16 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from core.tests.unit.model_notes.test_unit_model_notes_model import (
|
||||
ModelNotesInheritedCases
|
||||
)
|
||||
|
||||
from core.models.manufacturer_notes import ManufacturerNotes
|
||||
|
||||
|
||||
|
||||
class ManufacturerNotesModel(
|
||||
ModelNotesInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = ManufacturerNotes
|
@ -1,60 +0,0 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from core.tests.abstract.test_unit_model_notes_serializer import ModelNotesSerializerTestCases
|
||||
|
||||
from core.serializers.manufacturer_notes import ManufacturerNotes, ManufacturerNoteModelSerializer
|
||||
|
||||
|
||||
|
||||
class ManufacturerNotesSerializer(
|
||||
ModelNotesSerializerTestCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = ManufacturerNotes
|
||||
|
||||
model_serializer = ManufacturerNoteModelSerializer
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
self.note_model = self.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
)
|
||||
|
||||
self.note_model_two = self.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model two',
|
||||
)
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
content = 'a random comment for an exiting item',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model existing item',
|
||||
),
|
||||
created_by = self.user_two,
|
||||
)
|
||||
|
||||
|
||||
self.valid_data = {
|
||||
'organization': self.organization_two.id,
|
||||
'content': 'a random comment',
|
||||
'content_type': self.content_type_two.id,
|
||||
'model': self.note_model_two.id,
|
||||
'created_by': self.user_two.id,
|
||||
'modified_by': self.user_two.id,
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
from core.viewsets.manufacturer_notes import ViewSet
|
||||
|
||||
|
||||
|
||||
|
||||
class ManufacturerNotesViewsetList(
|
||||
ModelViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_v2_manufacturer_note'
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create object that is to be tested against
|
||||
2. add kwargs
|
||||
3. make list request
|
||||
"""
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
self.note_model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
)
|
||||
|
||||
self.kwargs = {
|
||||
'model_id': self.note_model.pk,
|
||||
}
|
||||
|
||||
|
||||
client = Client()
|
||||
|
||||
url = reverse(
|
||||
self.route_name + '-list',
|
||||
kwargs = self.kwargs
|
||||
)
|
||||
|
||||
client.force_login(self.view_user)
|
||||
|
||||
self.http_options_response_list = client.options(url)
|
@ -1,137 +0,0 @@
|
||||
import django
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
|
||||
from centurion.tests.unit.test_unit_models import TenancyObjectInheritedCases
|
||||
|
||||
from core.models.model_notes import ModelNotes
|
||||
|
||||
User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
class ModelNotesTestCases(
|
||||
TenancyObjectInheritedCases
|
||||
):
|
||||
|
||||
kwargs_item_create = {
|
||||
'content': 'a random comment for an exiting item',
|
||||
}
|
||||
|
||||
model = ModelNotes
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test"""
|
||||
|
||||
if not hasattr(self, 'organization'):
|
||||
|
||||
self.organization = Organization.objects.create(name='test_org')
|
||||
|
||||
|
||||
self.user = User.objects.create_user(username="test_user_view", password="password")
|
||||
|
||||
self.kwargs_item_create.update({
|
||||
'created_by': self.user,
|
||||
})
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
|
||||
class ModelNotesInheritedCases(
|
||||
ModelNotesTestCases
|
||||
):
|
||||
|
||||
kwargs_item_create = {}
|
||||
|
||||
|
||||
model = None
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test"""
|
||||
|
||||
kwargs_item_create = ModelNotesTestCases.kwargs_item_create
|
||||
|
||||
kwargs_item_create.update( self.kwargs_item_create )
|
||||
|
||||
if not hasattr(self, 'organization'):
|
||||
|
||||
self.organization = Organization.objects.create(name='test_org')
|
||||
|
||||
|
||||
if not hasattr(self, 'kwargs_create_related_model'):
|
||||
|
||||
if 'organization' in self.model.model.field.related_model().fields:
|
||||
|
||||
self.kwargs_create_related_model: dict = {
|
||||
'organization': self.organization,
|
||||
}
|
||||
|
||||
else:
|
||||
|
||||
self.kwargs_create_related_model: dict = {}
|
||||
|
||||
|
||||
if 'organization' in self.model.model.field.related_model().fields:
|
||||
|
||||
self.kwargs_create_related_model.update({
|
||||
'organization': self.organization,
|
||||
})
|
||||
|
||||
|
||||
if 'name' in self.model.model.field.related_model().fields:
|
||||
|
||||
self.kwargs_create_related_model.update({
|
||||
'name': 'model for note'
|
||||
})
|
||||
|
||||
self.kwargs_item_create.update({
|
||||
'content_type': ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
'model': self.model.model.field.related_model.objects.create(
|
||||
**self.kwargs_create_related_model,
|
||||
),
|
||||
})
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
|
||||
class ModelNotesTest(
|
||||
ModelNotesTestCases,
|
||||
TestCase
|
||||
):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test"""
|
||||
|
||||
self.kwargs_item_create.update({
|
||||
'content_type': ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model._meta.model_name).lower(),
|
||||
),
|
||||
})
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
def test_attribute_type_get_url(self):
|
||||
"""Attribute Type
|
||||
|
||||
This test case is a duplicate of a test with the same name. this model
|
||||
does not require this attribute be tested as it's a base model.
|
||||
|
||||
get_url is of type str
|
||||
"""
|
||||
|
||||
assert True
|
@ -1,16 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from core.tests.unit.model_notes.test_unit_model_notes_model import (
|
||||
ModelNotesInheritedCases
|
||||
)
|
||||
|
||||
from core.models.ticket.ticket_category_notes import TicketCategoryNotes
|
||||
|
||||
|
||||
|
||||
class NotesModel(
|
||||
ModelNotesInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = TicketCategoryNotes
|
@ -1,60 +0,0 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from core.tests.abstract.test_unit_model_notes_serializer import ModelNotesSerializerTestCases
|
||||
|
||||
from core.serializers.ticket_category_notes import TicketCategoryNotes, TicketCategoryNoteModelSerializer
|
||||
|
||||
|
||||
|
||||
class NotesSerializer(
|
||||
ModelNotesSerializerTestCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = TicketCategoryNotes
|
||||
|
||||
model_serializer = TicketCategoryNoteModelSerializer
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
self.note_model = self.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
)
|
||||
|
||||
self.note_model_two = self.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model two',
|
||||
)
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
content = 'a random comment for an exiting item',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model existing item',
|
||||
),
|
||||
created_by = self.user_two,
|
||||
)
|
||||
|
||||
|
||||
self.valid_data = {
|
||||
'organization': self.organization_two.id,
|
||||
'content': 'a random comment',
|
||||
'content_type': self.content_type_two.id,
|
||||
'model': self.note_model_two.id,
|
||||
'created_by': self.user_two.id,
|
||||
'modified_by': self.user_two.id,
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
from core.viewsets.ticket_category_notes import ViewSet
|
||||
|
||||
|
||||
|
||||
|
||||
class NotesViewsetList(
|
||||
ModelViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_v2_ticket_category_note'
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create object that is to be tested against
|
||||
2. add kwargs
|
||||
3. make list request
|
||||
"""
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
self.note_model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
)
|
||||
|
||||
self.kwargs = {
|
||||
'model_id': self.note_model.pk,
|
||||
}
|
||||
|
||||
|
||||
client = Client()
|
||||
|
||||
url = reverse(
|
||||
self.route_name + '-list',
|
||||
kwargs = self.kwargs
|
||||
)
|
||||
|
||||
client.force_login(self.view_user)
|
||||
|
||||
self.http_options_response_list = client.options(url)
|
@ -1,16 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from core.tests.unit.model_notes.test_unit_model_notes_model import (
|
||||
ModelNotesInheritedCases
|
||||
)
|
||||
|
||||
from core.models.ticket.ticket_comment_category_notes import TicketCommentCategoryNotes
|
||||
|
||||
|
||||
|
||||
class NotesModel(
|
||||
ModelNotesInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = TicketCommentCategoryNotes
|
@ -1,60 +0,0 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
from core.tests.abstract.test_unit_model_notes_serializer import ModelNotesSerializerTestCases
|
||||
|
||||
from core.serializers.ticket_comment_category_notes import TicketCommentCategoryNotes, TicketCommentCategoryNoteModelSerializer
|
||||
|
||||
|
||||
|
||||
class NotesSerializer(
|
||||
ModelNotesSerializerTestCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = TicketCommentCategoryNotes
|
||||
|
||||
model_serializer = TicketCommentCategoryNoteModelSerializer
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
self.note_model = self.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
)
|
||||
|
||||
self.note_model_two = self.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model two',
|
||||
)
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
content = 'a random comment for an exiting item',
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = str(self.model._meta.app_label).lower(),
|
||||
model = str(self.model.model.field.related_model.__name__).replace(' ', '').lower(),
|
||||
),
|
||||
model = self.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model existing item',
|
||||
),
|
||||
created_by = self.user_two,
|
||||
)
|
||||
|
||||
|
||||
self.valid_data = {
|
||||
'organization': self.organization_two.id,
|
||||
'content': 'a random comment',
|
||||
'content_type': self.content_type_two.id,
|
||||
'model': self.note_model_two.id,
|
||||
'created_by': self.user_two.id,
|
||||
'modified_by': self.user_two.id,
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
from core.viewsets.ticket_comment_category_notes import ViewSet
|
||||
|
||||
|
||||
|
||||
class NotesViewsetList(
|
||||
ModelViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_v2_ticket_comment_category_note'
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create object that is to be tested against
|
||||
2. add kwargs
|
||||
3. make list request
|
||||
"""
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
self.note_model = self.viewset.model.model.field.related_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'note model',
|
||||
)
|
||||
|
||||
self.kwargs = {
|
||||
'model_id': self.note_model.pk,
|
||||
}
|
||||
|
||||
|
||||
client = Client()
|
||||
|
||||
url = reverse(
|
||||
self.route_name + '-list',
|
||||
kwargs = self.kwargs
|
||||
)
|
||||
|
||||
client.force_login(self.view_user)
|
||||
|
||||
self.http_options_response_list = client.options(url)
|
Reference in New Issue
Block a user