test(itim): Cluster Type Serializer Validation checks

ref: #15 #248 #353
This commit is contained in:
2024-10-21 17:56:03 +09:30
parent 0803b2c766
commit a92bfd427f

View File

@ -0,0 +1,53 @@
import pytest
from django.test import TestCase
from rest_framework.exceptions import ValidationError
from access.models import Organization
from itim.serializers.cluster_type import ClusterType, ClusterTypeModelSerializer
class ClusterTypeValidationAPI(
TestCase,
):
model = ClusterType
@classmethod
def setUpTestData(self):
"""Setup Test
1. Create an org
2. Create an item
"""
organization = Organization.objects.create(name='test_org')
self.organization = organization
self.item = self.model.objects.create(
organization=organization,
name = 'os name',
)
def test_serializer_validation_no_name(self):
"""Serializer Validation Check
Ensure that if creating and no name is provided a validation error occurs
"""
with pytest.raises(ValidationError) as err:
serializer = ClusterTypeModelSerializer(data={
"organization": self.organization.id,
})
serializer.is_valid(raise_exception = True)
assert err.value.get_codes()['name'][0] == 'required'