Skip to content

Commit

Permalink
Fix more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljcollinsuk committed Jan 8, 2025
1 parent ecd1e36 commit f92b17e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
1 change: 0 additions & 1 deletion controlpanel/api/views/tool_deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

# First-party/Local
from controlpanel.api import serializers
from controlpanel.utils import start_background_task


class ToolDeploymentAPIView(GenericAPIView):
Expand Down
11 changes: 6 additions & 5 deletions tests/api/cluster/test_tool_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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(
Expand Down
18 changes: 13 additions & 5 deletions tests/api/views/test_tool_deployments.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
# 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")))
assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED


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()

0 comments on commit f92b17e

Please sign in to comment.