From f92b17e5db04546d5290d3b0b1b55a233012834d Mon Sep 17 00:00:00 2001 From: Michael Collins <15347726+michaeljcollinsuk@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:05:00 +0000 Subject: [PATCH] Fix more tests --- controlpanel/api/views/tool_deployments.py | 1 - tests/api/cluster/test_tool_deployment.py | 11 ++++++----- tests/api/views/test_tool_deployments.py | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/controlpanel/api/views/tool_deployments.py b/controlpanel/api/views/tool_deployments.py index 8cfeadd0c..9567fb276 100644 --- a/controlpanel/api/views/tool_deployments.py +++ b/controlpanel/api/views/tool_deployments.py @@ -6,7 +6,6 @@ # First-party/Local from controlpanel.api import serializers -from controlpanel.utils import start_background_task class ToolDeploymentAPIView(GenericAPIView): diff --git a/tests/api/cluster/test_tool_deployment.py b/tests/api/cluster/test_tool_deployment.py index 46854d6da..52fce3846 100644 --- a/tests/api/cluster/test_tool_deployment.py +++ b/tests/api/cluster/test_tool_deployment.py @@ -4,7 +4,7 @@ # First-party/Local from controlpanel.api import cluster -from controlpanel.api.models import Tool, User +from controlpanel.api.models import Tool, ToolDeployment, User def test_url(): @@ -18,14 +18,15 @@ def test_url(): chart_name="rstudio", version="1.0.0", ) + tool_deployment = ToolDeployment(user=user, tool=tool) expected = f"https://{user.slug}-rstudio.{settings.TOOLS_DOMAIN}/" # In the absence of a tool_domain, the chart_name (rstudio) is used. - assert tool.url(user) == expected - tool.chart_name = "rstudio-bespoke" - tool.tool_domain = "rstudio" + assert tool_deployment.url == expected + tool_deployment.chart_name = "rstudio-bespoke" + tool_deployment.tool_domain = "rstudio" # Now the chart_name is custom, the tool_domain (rstudio) is used, ensuring # the url remains "valid". - assert tool.url(user) == expected + assert tool_deployment.url == expected @pytest.mark.parametrize( diff --git a/tests/api/views/test_tool_deployments.py b/tests/api/views/test_tool_deployments.py index b62b0cffa..482ce0a2a 100644 --- a/tests/api/views/test_tool_deployments.py +++ b/tests/api/views/test_tool_deployments.py @@ -1,7 +1,13 @@ +# Standard library +from unittest.mock import patch + # Third-party from rest_framework import status from rest_framework.reverse import reverse +# First-party/Local +from tests.api.models.test_tool import tool # noqa: F401 + def test_get(client): response = client.get(reverse("tool-deployments", ("rstudio", "deploy"))) @@ -9,18 +15,20 @@ def test_get(client): def test_post_not_valid_data(client): - data = {"version": "rstudio_v1.0.0"} + data = {"tool": 1000} response = client.post(reverse("tool-deployments", ("rstudio", "deploy")), data) assert response.status_code == status.HTTP_400_BAD_REQUEST -def test_post_not_supported_action(client): - data = {"version": "rstudio_v1.0.0"} +def test_post_not_supported_action(client, tool): # noqa: F811 + data = {"tool": tool.pk} response = client.post(reverse("tool-deployments", ("rstudio", "testing")), data) assert response.status_code == status.HTTP_400_BAD_REQUEST -def test_post(client): - data = {"version": "rstudio__v1.0.0__1"} +@patch("controlpanel.api.serializers.ToolDeploymentSerializer.save") +def test_post(save, client, tool): # noqa: F811 + data = {"tool": tool.pk} response = client.post(reverse("tool-deployments", ("rstudio", "deploy")), data) assert response.status_code == status.HTTP_200_OK + save.assert_called_once()