Skip to content

Commit

Permalink
Implementing unit testing of create app instances from view form
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredeen committed Jan 2, 2025
1 parent c9bea42 commit d5a9c4d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 42 additions & 1 deletion apps/tests/test_app_helper_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""This module is used to test the helper functions that are used by user app instance functionality."""

import unittest
from unittest.mock import patch

from django.contrib.auth import get_user_model
from django.test import TestCase

from projects.models import Project
from projects.models import Flavor, Project

from ..app_registry import APP_REGISTRY
from ..helpers import create_instance_from_form
from ..models import Apps, JupyterInstance, K8sUserAppStatus

User = get_user_model()
Expand All @@ -17,13 +20,43 @@ class CreateAppInstanceTestCase(TestCase):

def setUp(self):
self.user = User.objects.create_user("foo1", "[email protected]", "bar")
self.project = Project.objects.create_project(name="test-app-creation", owner=self.user, description="")

@unittest.expectedFailure
def test_create_instance_from_form_valid_input(self):
# TODO: Status

# Create the form data
flavor = Flavor.objects.filter(project=self.project).first()

app_slug = "dashapp"

data = {
"name": "app-form-name",
"description": "app-form-description",
"flavor": str(flavor.pk),
"access": "public",
"port": 8000,
"image": "some-image",
"source_code_url": "https://someurlthatdoesnotexist.com",
}

_, form_class = APP_REGISTRY.get(app_slug)
form = form_class(data, project_pk=self.project.pk)

with patch("apps.tasks.delete_resource.delay") as mock_task: # noqa: F841
create_instance_from_form(form, self.project, app_slug, app_id=None)

pass

self.assertTrue(1 == 0)

@unittest.expectedFailure
def test_create_instance_from_form_invalid_input(self):
# TODO: Status
with patch("apps.tasks.delete_resource.delay") as mock_task: # noqa: F841
pass

self.assertTrue(1 == 0)


Expand All @@ -49,10 +82,18 @@ def setUp(self) -> None:
k8s_user_app_status=k8s_user_app_status,
)

@unittest.expectedFailure
def test_create_instance_from_form_valid_input(self):
# TODO: Status. Implement
with patch("apps.tasks.delete_resource.delay") as mock_task: # noqa: F841
pass

self.assertTrue(1 == 0)

@unittest.expectedFailure
def test_create_instance_from_form_invalid_input(self):
# TODO: Status. Implement
with patch("apps.tasks.delete_resource.delay") as mock_task: # noqa: F841
pass

self.assertTrue(1 == 0)
2 changes: 2 additions & 0 deletions apps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,11 @@ def get_form(self, request, project, app_slug, app_id):
user_can_create = False

if app_id:
# Updating an existing app instance
user_can_edit = model_class.objects.user_can_edit(request.user, project, app_slug)
instance = model_class.objects.get(pk=app_id)
else:
# Create a new app instance
user_can_create = model_class.objects.user_can_create(request.user, project, app_slug)
instance = None

Expand Down

0 comments on commit d5a9c4d

Please sign in to comment.