mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-09-09 11:35:21 +03:00
added mock user in api endpoints tests
This commit is contained in:
parent
01511f3aef
commit
b5e44b5403
1
configs/3dc89371-56f1-45f8-8ec9-042f35ea6c65/test.txt
Normal file
1
configs/3dc89371-56f1-45f8-8ec9-042f35ea6c65/test.txt
Normal file
@ -0,0 +1 @@
|
||||
hello world
|
||||
1
configs/49720c91-645b-4e88-b27a-10e899deba50/test.txt
Normal file
1
configs/49720c91-645b-4e88-b27a-10e899deba50/test.txt
Normal file
@ -0,0 +1 @@
|
||||
hello
|
||||
1
configs/6824cfff-51b2-4c02-9e49-aaece7b6742a/test.txt
Normal file
1
configs/6824cfff-51b2-4c02-9e49-aaece7b6742a/test.txt
Normal file
@ -0,0 +1 @@
|
||||
hello world
|
||||
1
configs/7b34ada0-c96e-451d-95d6-be07d26a637a/test.txt
Normal file
1
configs/7b34ada0-c96e-451d-95d6-be07d26a637a/test.txt
Normal file
@ -0,0 +1 @@
|
||||
hello
|
||||
1
configs/87e5df97-07dd-4b4f-abad-4427745b89fd/config1.txt
Normal file
1
configs/87e5df97-07dd-4b4f-abad-4427745b89fd/config1.txt
Normal file
@ -0,0 +1 @@
|
||||
file1
|
||||
1
configs/87e5df97-07dd-4b4f-abad-4427745b89fd/config2.txt
Normal file
1
configs/87e5df97-07dd-4b4f-abad-4427745b89fd/config2.txt
Normal file
@ -0,0 +1 @@
|
||||
file2
|
||||
1
configs/baa12124-1afb-4650-a08f-25a3452c5cbc/config1.txt
Normal file
1
configs/baa12124-1afb-4650-a08f-25a3452c5cbc/config1.txt
Normal file
@ -0,0 +1 @@
|
||||
file1
|
||||
1
configs/baa12124-1afb-4650-a08f-25a3452c5cbc/config2.txt
Normal file
1
configs/baa12124-1afb-4650-a08f-25a3452c5cbc/config2.txt
Normal file
@ -0,0 +1 @@
|
||||
file2
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user