Skip to content

Commit

Permalink
add flavor deletion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akochari committed Nov 26, 2024
1 parent bdc61d1 commit 476c1bc
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions projects/tests/test_create_remove_flavors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.test import TestCase

from projects.models import Project, Flavor
from projects.views import can_model_instance_be_deleted
from apps.models import Apps, CustomAppInstance

User = get_user_model()

Expand All @@ -25,7 +27,7 @@ def test_forbidden_flavor_creation(self):

response = self.client.post(
f"/projects/{project.slug}/createflavor/",
{"flavor_name": "new-flavor",
{"flavor_name": "new-flavor-user",
"cpu_req": "n",
"mem_req": "n",
"ephmem_req": "n",
Expand All @@ -49,7 +51,7 @@ def test_allowed_flavor_creation(self):
project = Project.objects.get(name="test-flavor")
response = self.client.post(
f"/projects/{project.slug}/createflavor/",
{"flavor_name": "new-flavor",
{"flavor_name": "new-flavor-superuser",
"cpu_req": "n",
"mem_req": "n",
"ephmem_req": "n",
Expand All @@ -63,3 +65,33 @@ def test_allowed_flavor_creation(self):

flavors = Flavor.objects.all()
self.assertEqual(len(flavors), 1)

"""
Test it is allowed to delete flavor that is not in use
"""
user = User.objects.get(email=test_superuser["email"])
flavor = Flavor.objects.get(name="new-flavor-superuser")

can_flavor_be_deleted = can_model_instance_be_deleted("flavor", flavor.pk)
self.assertTrue(can_flavor_be_deleted)

"""
Test it is not allowed to delete flavor that is in use
"""
app = Apps.objects.create(name="Some App", slug="customapp")
self.app_instance = CustomAppInstance.objects.create(
access="public",
owner=user,
name="test_app_instance_flavor",
description="some app description",
app=app,
project=project,
k8s_values={
"environment": {"pk": ""},
},
flavor=flavor
)

can_flavor_be_deleted = can_model_instance_be_deleted("flavor", flavor.pk)
self.assertFalse(can_flavor_be_deleted)

0 comments on commit 476c1bc

Please sign in to comment.