test(itam): Software Version Notes Function Viewset Tests

ref: #525 #541
This commit is contained in:
2025-02-08 22:32:05 +09:30
parent 382b1d2a30
commit a74550e1f3

View File

@ -0,0 +1,140 @@
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from core.tests.abstract.test_functional_notes_viewset import (
ModelNotesViewSetBase,
ModelNotesMetadata,
ModelNotesPermissionsAPI,
ModelNotesSerializer
)
from itam.models.software import Software
from itam.viewsets.software_version_notes import ViewSet
class ViewSetBase(
ModelNotesViewSetBase
):
viewset = ViewSet
url_name = '_api_v2_software_version_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 = '11',
software = Software.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',
software = Software.objects.create(
organization = self.organization,
name = 'note model other org',
),
),
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',
software = Software.objects.create(
organization = self.organization,
name = 'note model global_org_item',
),
),
created_by = self.view_user,
modified_by = self.view_user,
)
self.url_kwargs = {
'software_id': self.item.model.software.pk,
'model_id': self.item.model.pk,
}
self.url_view_kwargs = {
'software_id': self.item.model.software.pk,
'model_id': self.item.model.pk,
'pk': self.item.id
}
class SoftwareVersionModelNotesPermissionsAPI(
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 SoftwareVersionBaseModelNotesSerializer(
ViewSetBase,
ModelNotesSerializer,
TestCase,
):
pass
class SoftwareVersionModelNotesMetadata(
ViewSetBase,
ModelNotesMetadata,
TestCase,
):
pass