diff --git a/dash/templates/dash/common/components/secondary-nav.html b/dash/templates/dash/common/components/secondary-nav.html index 410bf9c..8a476c5 100644 --- a/dash/templates/dash/common/components/secondary-nav.html +++ b/dash/templates/dash/common/components/secondary-nav.html @@ -4,7 +4,21 @@
Hello, {{ username }}!
+Name: {{ instance.name }} +
++Configuration: {{ instance.configuration }} +
++Created On: {{ instance.created_at }} +
+ ++Click here to delete instance +
+ +{% endblock %} diff --git a/dash/tests.py b/dash/tests.py index f22131a..d3ebca3 100644 --- a/dash/tests.py +++ b/dash/tests.py @@ -174,6 +174,7 @@ class CreateInstance(TestCase): self.assertEqual(b"Logout" in resp.content, True) self.assertEqual(str.encode(test) in resp.content, True) + # create instance payload = { "name": "test_create_instance_renders", "configuration": self.instance_config[0].name, @@ -193,11 +194,14 @@ class CreateInstance(TestCase): ).exists(), True, ) + instance = Instance.objects.get(name=payload["name"], owned_by=self.user) + # try to create instance with duplicate name resp = c.post(reverse("dash.instances.new"), payload) self.assertEqual(resp.status_code, 400) self.assertEqual(b"Instance name exists" in resp.content, True) + # try to create instance with a VM configuration that doesn't exist payload = { "name": f"2{payload['name']}", "configuration": f"2{payload['name']}", @@ -205,3 +209,48 @@ class CreateInstance(TestCase): resp = c.post(reverse("dash.instances.new"), payload) self.assertEqual(resp.status_code, 400) self.assertEqual(b"Configuration doesn" in resp.content, True) + + # list instances + resp = c.get(reverse("dash.instances.list")) + self.assertEqual(resp.status_code, 200) + self.assertEqual(str.encode(instance.name) in resp.content, True) + + # view instance details + resp = c.get(reverse("dash.instances.view", args=(instance.name,))) + self.assertEqual(resp.status_code, 200) + self.assertEqual(str.encode(instance.name) in resp.content, True) + + # delete instance details + delete_uri = reverse("dash.instances.delete", args=(instance.name,)) + + ## will ask for sudo confirmation + resp = c.get(delete_uri) + self.assertEqual(resp.status_code, 302) + ctx = {"next": delete_uri} + self.assertEqual( + resp.headers["location"], f"{reverse('accounts.sudo')}?{urlencode(ctx)}" + ) + + ## give sudo confirmation + payload = {"password": self.password, "next": ctx["next"]} + resp = c.post(reverse("accounts.sudo"), payload) + self.assertEqual(resp.status_code, 302) + self.assertEqual(resp.headers["location"], ctx["next"]) + + resp = c.get(delete_uri) + self.assertEqual(resp.status_code, 200) + self.assertEqual( + str.encode(f"to delete VM {instance.name}") in resp.content, True + ) + + resp = c.post(delete_uri) + self.assertEqual(resp.status_code, 302) + self.assertEqual(resp.headers["location"], reverse("dash.home")) + self.assertEqual( + Instance.objects.filter( + name=instance.name, + owned_by=self.user, + configuration_id=self.instance_config[0], + ).exists(), + False, + ) diff --git a/dash/urls.py b/dash/urls.py index a9d857a..9537f16 100644 --- a/dash/urls.py +++ b/dash/urls.py @@ -15,9 +15,12 @@ from django.contrib import admin from django.urls import path, include -from .views import home, create_instance +from .views import home, create_instance, delete_instance, list_instances, view_instance urlpatterns = [ path("instance/new/", create_instance, name="dash.instances.new"), + path("instance/list/", list_instances, name="dash.instances.list"), + path("instance/view/