added mock user in api endpoints tests

This commit is contained in:
Volobue 2026-05-25 22:17:14 +03:00
parent 01511f3aef
commit b5e44b5403
9 changed files with 91 additions and 75 deletions

View File

@ -0,0 +1 @@
hello world

View File

@ -0,0 +1 @@
hello

View File

@ -0,0 +1 @@
hello world

View File

@ -0,0 +1 @@
hello

View File

@ -0,0 +1 @@
file1

View File

@ -0,0 +1 @@
file2

View File

@ -0,0 +1 @@
file1

View File

@ -0,0 +1 @@
file2

View File

@ -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: