diff --git a/configs/3dc89371-56f1-45f8-8ec9-042f35ea6c65/test.txt b/configs/3dc89371-56f1-45f8-8ec9-042f35ea6c65/test.txt new file mode 100644 index 000000000..95d09f2b1 --- /dev/null +++ b/configs/3dc89371-56f1-45f8-8ec9-042f35ea6c65/test.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/configs/49720c91-645b-4e88-b27a-10e899deba50/test.txt b/configs/49720c91-645b-4e88-b27a-10e899deba50/test.txt new file mode 100644 index 000000000..b6fc4c620 --- /dev/null +++ b/configs/49720c91-645b-4e88-b27a-10e899deba50/test.txt @@ -0,0 +1 @@ +hello \ No newline at end of file diff --git a/configs/6824cfff-51b2-4c02-9e49-aaece7b6742a/test.txt b/configs/6824cfff-51b2-4c02-9e49-aaece7b6742a/test.txt new file mode 100644 index 000000000..95d09f2b1 --- /dev/null +++ b/configs/6824cfff-51b2-4c02-9e49-aaece7b6742a/test.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file diff --git a/configs/7b34ada0-c96e-451d-95d6-be07d26a637a/test.txt b/configs/7b34ada0-c96e-451d-95d6-be07d26a637a/test.txt new file mode 100644 index 000000000..b6fc4c620 --- /dev/null +++ b/configs/7b34ada0-c96e-451d-95d6-be07d26a637a/test.txt @@ -0,0 +1 @@ +hello \ No newline at end of file diff --git a/configs/87e5df97-07dd-4b4f-abad-4427745b89fd/config1.txt b/configs/87e5df97-07dd-4b4f-abad-4427745b89fd/config1.txt new file mode 100644 index 000000000..08219db9b --- /dev/null +++ b/configs/87e5df97-07dd-4b4f-abad-4427745b89fd/config1.txt @@ -0,0 +1 @@ +file1 \ No newline at end of file diff --git a/configs/87e5df97-07dd-4b4f-abad-4427745b89fd/config2.txt b/configs/87e5df97-07dd-4b4f-abad-4427745b89fd/config2.txt new file mode 100644 index 000000000..30d67d467 --- /dev/null +++ b/configs/87e5df97-07dd-4b4f-abad-4427745b89fd/config2.txt @@ -0,0 +1 @@ +file2 \ No newline at end of file diff --git a/configs/baa12124-1afb-4650-a08f-25a3452c5cbc/config1.txt b/configs/baa12124-1afb-4650-a08f-25a3452c5cbc/config1.txt new file mode 100644 index 000000000..08219db9b --- /dev/null +++ b/configs/baa12124-1afb-4650-a08f-25a3452c5cbc/config1.txt @@ -0,0 +1 @@ +file1 \ No newline at end of file diff --git a/configs/baa12124-1afb-4650-a08f-25a3452c5cbc/config2.txt b/configs/baa12124-1afb-4650-a08f-25a3452c5cbc/config2.txt new file mode 100644 index 000000000..30d67d467 --- /dev/null +++ b/configs/baa12124-1afb-4650-a08f-25a3452c5cbc/config2.txt @@ -0,0 +1 @@ +file2 \ No newline at end of file diff --git a/tests/api/routes/controller/test_templates.py b/tests/api/routes/controller/test_templates.py index e26c394bf..cd1745783 100644 --- a/tests/api/routes/controller/test_templates.py +++ b/tests/api/routes/controller/test_templates.py @@ -251,31 +251,33 @@ class TestTemplateRoutes: is_active=True ) app.dependency_overrides[get_current_active_user] = mock_get_current_active_user + try: + create_resp = await client.post(app.url_path_for("create_template"), json={ + "name": "TEST", + "compute_id": "local", + "template_type": "vpcs" + }) - create_resp = await client.post(app.url_path_for("create_template"), json={ - "name": "TEST", - "compute_id": "local", - "template_type": "vpcs" - }) + assert create_resp.status_code == 201 + template_id = create_resp.json()["template_id"] - assert create_resp.status_code == 201 - template_id = create_resp.json()["template_id"] - - await client.put( - app.url_path_for("update_base_config", template_id=template_id, filename="test.txt"), - json={"content": "hello"} - ) - - response = await client.get( - app.url_path_for( - "get_base_config", - template_id=template_id, - filename="test.txt" + await client.put( + app.url_path_for("update_base_config", template_id=template_id, filename="test.txt"), + json={"content": "hello"} ) - ) - assert response.status_code == 200 - assert response.json()["content"] == "hello" + response = await client.get( + app.url_path_for( + "get_base_config", + template_id=template_id, + filename="test.txt" + ) + ) + + assert response.status_code == 200 + assert response.json()["content"] == "hello" + finally: + app.dependency_overrides.pop(get_current_active_user, None) async def test_update_base_config(self, app: FastAPI, client: AsyncClient): @@ -287,24 +289,26 @@ class TestTemplateRoutes: is_active=True ) app.dependency_overrides[get_current_active_user] = mock_get_current_active_user + try: + template_name = f"TEST_UPDATE_{uuid.uuid4().hex[:8]}" + create_resp = await client.post(app.url_path_for("create_template"), json={ + "name": template_name, + "compute_id": "local", + "template_type": "vpcs" + }) + assert create_resp.status_code == 201 + template_id = create_resp.json()["template_id"] - template_name = f"TEST_UPDATE_{uuid.uuid4().hex[:8]}" - create_resp = await client.post(app.url_path_for("create_template"), json={ - "name": template_name, - "compute_id": "local", - "template_type": "vpcs" - }) - assert create_resp.status_code == 201 - template_id = create_resp.json()["template_id"] + payload = {"content": "hello world"} + response = await client.put( + app.url_path_for("update_base_config", template_id=template_id, filename="test.txt"), + json=payload + ) - payload = {"content": "hello world"} - response = await client.put( - app.url_path_for("update_base_config", template_id=template_id, filename="test.txt"), - json=payload - ) - - assert response.status_code == 200 - assert response.json()["content"] == "hello world" + assert response.status_code == 200 + assert response.json()["content"] == "hello world" + finally: + app.dependency_overrides.pop(get_current_active_user, None) async def test_update_base_config_missing_content(self, app: FastAPI, client: AsyncClient): @@ -316,22 +320,24 @@ class TestTemplateRoutes: is_active=True ) app.dependency_overrides[get_current_active_user] = mock_get_current_active_user + try: + template_name = f"TEST_MISSING_{uuid.uuid4().hex[:8]}" + create_resp = await client.post(app.url_path_for("create_template"), json={ + "name": template_name, + "compute_id": "local", + "template_type": "vpcs" + }) + assert create_resp.status_code == 201 + template_id = create_resp.json()["template_id"] - template_name = f"TEST_MISSING_{uuid.uuid4().hex[:8]}" - create_resp = await client.post(app.url_path_for("create_template"), json={ - "name": template_name, - "compute_id": "local", - "template_type": "vpcs" - }) - assert create_resp.status_code == 201 - template_id = create_resp.json()["template_id"] + response = await client.put( + app.url_path_for("update_base_config", template_id=template_id, filename="test.txt"), + json={} + ) - response = await client.put( - app.url_path_for("update_base_config", template_id=template_id, filename="test.txt"), - json={} - ) - - assert response.status_code in (400, 422) + assert response.status_code in (400, 422) + finally: + app.dependency_overrides.pop(get_current_active_user, None) async def test_base_config_template_not_found(self, app: FastAPI, client: AsyncClient): response = await client.get( @@ -350,33 +356,35 @@ class TestTemplateRoutes: is_active=True ) app.dependency_overrides[get_current_active_user] = mock_get_current_active_user + try: + template_name = f"TEST_LIST_{uuid.uuid4().hex[:8]}" + create_resp = await client.post(app.url_path_for("create_template"), json={ + "name": template_name, + "compute_id": "local", + "template_type": "vpcs" + }) + assert create_resp.status_code == 201 + template_id = create_resp.json()["template_id"] - template_name = f"TEST_LIST_{uuid.uuid4().hex[:8]}" - create_resp = await client.post(app.url_path_for("create_template"), json={ - "name": template_name, - "compute_id": "local", - "template_type": "vpcs" - }) - assert create_resp.status_code == 201 - template_id = create_resp.json()["template_id"] + await client.put( + app.url_path_for("update_base_config", template_id=template_id, filename="config1.txt"), + json={"content": "file1"} + ) + await client.put( + app.url_path_for("update_base_config", template_id=template_id, filename="config2.txt"), + json={"content": "file2"} + ) - await client.put( - app.url_path_for("update_base_config", template_id=template_id, filename="config1.txt"), - json={"content": "file1"} - ) - await client.put( - app.url_path_for("update_base_config", template_id=template_id, filename="config2.txt"), - json={"content": "file2"} - ) + response = await client.get( + app.url_path_for("list_base_configs", template_id=template_id) + ) - response = await client.get( - app.url_path_for("list_base_configs", template_id=template_id) - ) - - assert response.status_code == 200 - filenames = [item["filename"] for item in response.json()] - assert "config1.txt" in filenames - assert "config2.txt" in filenames + assert response.status_code == 200 + filenames = [item["filename"] for item in response.json()] + assert "config1.txt" in filenames + assert "config2.txt" in filenames + finally: + app.dependency_overrides.pop(get_current_active_user, None) class TestDuplicateTemplates: