Skip to content

Commit

Permalink
pre-commit fix
Browse files Browse the repository at this point in the history
  • Loading branch information
akochari committed Nov 26, 2024
1 parent 476c1bc commit 3120ce4
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions projects/tests/test_create_remove_flavors.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from django.contrib.auth import get_user_model
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
from projects.models import Flavor, Project
from projects.views import can_model_instance_be_deleted

User = get_user_model()

test_user = {"username": "foo1", "email": "[email protected]", "password": "bar"}
test_superuser = {"username": "superuser", "email": "[email protected]", "password": "bar"}


class FlavorTestCase(TestCase):
def setUp(self):
user = User.objects.create_user(test_user["username"], test_user["email"], test_user["password"])
_ = Project.objects.create_project(name="test-flavor", owner=user, description="")
superuser = User.objects.create_superuser(test_superuser["username"], test_superuser["email"], test_superuser["password"])
#self.client.login(username=test_user["email"], password=test_user["password"])
User.objects.create_superuser(test_superuser["username"], test_superuser["email"], test_superuser["password"])

def test_forbidden_flavor_creation(self):
"""
Expand All @@ -27,22 +27,22 @@ def test_forbidden_flavor_creation(self):

response = self.client.post(
f"/projects/{project.slug}/createflavor/",
{"flavor_name": "new-flavor-user",
"cpu_req": "n",
"mem_req": "n",
"ephmem_req": "n",
"cpu_lim": "n",
"mem_lim": "n",
"ephmem_lim": "n"
},
{
"flavor_name": "new-flavor-user",
"cpu_req": "n",
"mem_req": "n",
"ephmem_req": "n",
"cpu_lim": "n",
"mem_lim": "n",
"ephmem_lim": "n",
},
)

self.assertEqual(response.status_code, 403)

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


def test_allowed_flavor_creation(self):
"""
Test superuser is allowed to create flavor
Expand All @@ -51,21 +51,22 @@ 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-superuser",
"cpu_req": "n",
"mem_req": "n",
"ephmem_req": "n",
"cpu_lim": "n",
"mem_lim": "n",
"ephmem_lim": "n"
},
{
"flavor_name": "new-flavor-superuser",
"cpu_req": "n",
"mem_req": "n",
"ephmem_req": "n",
"cpu_lim": "n",
"mem_lim": "n",
"ephmem_lim": "n",
},
)

self.assertEqual(response.status_code, 302)

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

"""
Test it is allowed to delete flavor that is not in use
"""
Expand All @@ -89,9 +90,8 @@ def test_allowed_flavor_creation(self):
k8s_values={
"environment": {"pk": ""},
},
flavor=flavor
flavor=flavor,
)

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

0 comments on commit 3120ce4

Please sign in to comment.