mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-27 12:30:13 +03:00
Add/fix tests
This commit is contained in:
parent
a9525503c6
commit
4d35477e46
@ -86,7 +86,59 @@ class TestNodeRoutes:
|
||||
response = await client.get(app.url_path_for("get_nodes", project_id=project.id))
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()[0]["name"] == "test"
|
||||
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tags, expected_match",
|
||||
(
|
||||
([], True),
|
||||
(["tag1"], True),
|
||||
(["tag1", "tag2"], True),
|
||||
(["tag42"], False),
|
||||
(["tag1", "tag3"], False),
|
||||
),
|
||||
)
|
||||
async def test_list_nodes_with_tags(
|
||||
self,
|
||||
app: FastAPI,
|
||||
client: AsyncClient,
|
||||
project: Project,
|
||||
compute: Compute,
|
||||
tags: list,
|
||||
expected_match: bool
|
||||
) -> None:
|
||||
response = MagicMock()
|
||||
response.json = {"console": 2048}
|
||||
compute.post = AsyncioMagicMock(return_value=response)
|
||||
|
||||
await client.post(app.url_path_for("create_node", project_id=project.id), json={
|
||||
"name": "test",
|
||||
"node_type": "vpcs",
|
||||
"compute_id": "example.com",
|
||||
"tags": ["tag1", "tag2"],
|
||||
"properties": {
|
||||
"startup_script": "echo test"
|
||||
}
|
||||
})
|
||||
|
||||
await client.post(app.url_path_for("create_node", project_id=project.id), json={
|
||||
"name": "test2",
|
||||
"node_type": "vpcs",
|
||||
"compute_id": "example.com",
|
||||
"tags": ["tag3", "tag4"],
|
||||
"properties": {
|
||||
"startup_script": "echo test"
|
||||
}
|
||||
})
|
||||
|
||||
params = {"tags": tags}
|
||||
response = await client.get(app.url_path_for("get_nodes", project_id=project.id), params=params)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
if expected_match:
|
||||
assert len(response.json()) > 0
|
||||
else:
|
||||
assert len(response.json()) == 0
|
||||
|
||||
|
||||
async def test_get_node(
|
||||
self,
|
||||
@ -131,6 +183,7 @@ class TestNodeRoutes:
|
||||
"name": "test",
|
||||
"node_type": "vpcs",
|
||||
"compute_id": "example.com",
|
||||
"tags": ["tag1", "tag2"],
|
||||
"properties": {
|
||||
"startup_script": "echo test"
|
||||
}
|
||||
@ -139,8 +192,9 @@ class TestNodeRoutes:
|
||||
assert response.status_code == 200
|
||||
assert response.json()["name"] == "test"
|
||||
assert "name" not in response.json()["properties"]
|
||||
|
||||
|
||||
assert response.json()["tags"] == ["tag1", "tag2"]
|
||||
|
||||
|
||||
async def test_start_all_nodes(
|
||||
self,
|
||||
app: FastAPI,
|
||||
|
||||
@ -41,15 +41,18 @@ class TestTemplateRoutes:
|
||||
|
||||
async def test_route_exist(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
|
||||
new_template = {"base_script_file": "vpcs_base_config.txt",
|
||||
"category": "guest",
|
||||
"console_auto_start": False,
|
||||
"console_type": "telnet",
|
||||
"default_name_format": "PC{0}",
|
||||
"name": "VPCS_TEST",
|
||||
"compute_id": "local",
|
||||
"symbol": ":/symbols/vpcs_guest.svg",
|
||||
"template_type": "vpcs"}
|
||||
new_template = {
|
||||
"base_script_file": "vpcs_base_config.txt",
|
||||
"category": "guest",
|
||||
"console_auto_start": False,
|
||||
"console_type": "telnet",
|
||||
"default_name_format": "PC{0}",
|
||||
"name": "VPCS_TEST",
|
||||
"compute_id": "local",
|
||||
"symbol": ":/symbols/vpcs_guest.svg",
|
||||
"template_type": "vpcs",
|
||||
"tags": ["tag1", "tag2"]
|
||||
}
|
||||
|
||||
response = await client.post(app.url_path_for("create_template"), json=new_template)
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
@ -61,6 +64,36 @@ class TestTemplateRoutes:
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert len(response.json()) > 0
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"tags, expected_match",
|
||||
(
|
||||
([], True),
|
||||
(["tag1"], True),
|
||||
(["tag1", "tag2"], True),
|
||||
(["tag42"], False),
|
||||
(["tag1", "tag3"], False),
|
||||
),
|
||||
)
|
||||
async def test_template_list_with_tags(
|
||||
self,
|
||||
app: FastAPI,
|
||||
client: AsyncClient,
|
||||
tags: list,
|
||||
expected_match: bool
|
||||
) -> None:
|
||||
|
||||
params = {"tags": tags}
|
||||
response = await client.get(app.url_path_for("get_templates"), params=params)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
if expected_match:
|
||||
if not tags:
|
||||
assert len(response.json()) == 8
|
||||
else:
|
||||
assert response.json()[0]["name"] == "VPCS_TEST"
|
||||
assert len(response.json()) == 1
|
||||
else:
|
||||
assert len(response.json()) == 0
|
||||
|
||||
async def test_template_get(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
|
||||
template_id = str(uuid.uuid4())
|
||||
@ -105,11 +138,14 @@ class TestTemplateRoutes:
|
||||
async def test_template_update(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
|
||||
template_id = str(uuid.uuid4())
|
||||
params = {"template_id": template_id,
|
||||
"name": "VPCS_TEST",
|
||||
"version": "3.0",
|
||||
"compute_id": "local",
|
||||
"template_type": "vpcs"}
|
||||
params = {
|
||||
"template_id": template_id,
|
||||
"name": "VPCS_TEST",
|
||||
"version": "3.0",
|
||||
"compute_id": "local",
|
||||
"template_type": "vpcs",
|
||||
"tags": ["tag1", "tag2"]
|
||||
}
|
||||
|
||||
response = await client.post(app.url_path_for("create_template"), json=params)
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
@ -117,6 +153,7 @@ class TestTemplateRoutes:
|
||||
response = await client.get(app.url_path_for("get_template", template_id=template_id))
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["template_id"] == template_id
|
||||
assert response.json()["tags"] == ["tag1", "tag2"]
|
||||
|
||||
params = {"name": "VPCS_TEST_RENAMED", "console_auto_start": True}
|
||||
response = await client.put(app.url_path_for("update_template", template_id=template_id), json=params)
|
||||
|
||||
@ -139,6 +139,7 @@ def test_json(node, compute):
|
||||
"port_name_format": "Ethernet{0}",
|
||||
"port_segment_size": 0,
|
||||
"first_port_name": None,
|
||||
"tags": [],
|
||||
"custom_adapters": [],
|
||||
"console_auto_start": False,
|
||||
"ports": [
|
||||
@ -176,6 +177,7 @@ def test_json(node, compute):
|
||||
"port_segment_size": 0,
|
||||
"first_port_name": None,
|
||||
"custom_adapters": [],
|
||||
"tags": [],
|
||||
"console_auto_start": False,
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user