refactor: update authentication handling to use aiohttp.encode_basic_auth and adjust request options + fix other pytest warnings

This commit is contained in:
grossmj committed 2026-10-31 22:00:21 +07:00
1 parent 1608a65a01
commit ac65698eea
9 files changed
+50 -33

No files matched your search

@@ -130,4 +130,4 @@ class TestApplianceRoutes:
app.url_path_for("add_appliance_version", appliance_id=appliance_id),
json={"name": "bad", "registry_version": 7, "images": {"hda_disk_image": "empty99G.qcow2"}},
)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
+1 -1
View File
@@ -256,7 +256,7 @@ class TestLinkRoutes:
response = await client.post(
app.url_path_for("create_link", project_id=project.id), json={"nodes": [bad, valid]}
)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
async def test_get_link(
self, app: FastAPI, client: AsyncClient, project: Project, nodes: Tuple[Node, Node]
+2 -2
View File
@@ -142,7 +142,7 @@ class TestMarkerRoutes:
app.url_path_for("create_marker", project_id=project.id, link_id=link.id),
json={"name": "bad name!", "bpf": "icmp"},
)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
async def test_create_marker_name_too_long_rejected(
self, app: FastAPI, client: AsyncClient, project: Project
@@ -155,7 +155,7 @@ class TestMarkerRoutes:
app.url_path_for("create_marker", project_id=project.id, link_id=link.id),
json={"name": "x" * 33, "bpf": "icmp"}, # max_length is 32
)
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
assert response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT
async def test_get_markers(self, app: FastAPI, client: AsyncClient, project: Project) -> None:
+2 -13
View File
@@ -107,7 +107,6 @@ async def test_compute_httpQuery(compute):
"https://example.com:84/v3/compute/projects",
headers={"content-type": "application/json"},
data=b'{"a": "b"}',
auth=None,
params=None,
chunked=None,
timeout=120,
@@ -129,15 +128,13 @@ async def test_compute_httpQueryAuth(compute):
mock.assert_called_with(
"POST",
"https://example.com:84/v3/compute/projects",
headers={"content-type": "application/json"},
headers={"content-type": "application/json", "Authorization": aiohttp.encode_basic_auth("root", "toor")},
data=b'{"a": "b"}',
auth=compute._auth,
params=None,
chunked=None,
timeout=120,
)
assert compute._auth.login == "root"
assert compute._auth.password == "toor"
assert compute._auth == aiohttp.encode_basic_auth("root", "toor")
# @pytest.mark.asyncio
@@ -200,7 +197,6 @@ async def test_compute_httpQueryNotConnectedInvalidVersion(compute):
"https://example.com:84/v3/compute/capabilities",
headers={"content-type": "application/json"},
data=None,
auth=None,
params=None,
chunked=None,
timeout=120,
@@ -223,7 +219,6 @@ async def test_compute_httpQueryNotConnectedNonGNS3Server(compute):
"https://example.com:84/v3/compute/capabilities",
headers={"content-type": "application/json"},
data=None,
auth=None,
params=None,
chunked=None,
timeout=120,
@@ -246,7 +241,6 @@ async def test_compute_httpQueryNotConnectedNonGNS3Server2(compute):
"https://example.com:84/v3/compute/capabilities",
headers={"content-type": "application/json"},
data=None,
auth=None,
params=None,
chunked=None,
timeout=120,
@@ -293,7 +287,6 @@ async def test_compute_httpQuery_project(compute):
"https://example.com:84/v3/compute/projects",
headers={"content-type": "application/json"},
data=json.dumps(project.asdict()),
auth=None,
params=None,
chunked=None,
timeout=120,
@@ -455,7 +448,6 @@ async def test_forward_get(compute):
"https://example.com:84/v3/compute/qemu/images",
headers={"content-type": "application/json"},
data=None,
auth=None,
params=None,
chunked=None,
timeout=None,
@@ -487,7 +479,6 @@ async def test_forward_post(compute):
"https://example.com:84/v3/compute/qemu/img",
headers={"content-type": "application/json"},
data=b'{"id": 42}',
auth=None,
params=None,
chunked=None,
timeout=None,
@@ -509,7 +500,6 @@ async def test_list_files(project, compute):
f"https://example.com:84/v3/compute/projects/{project.id}/files",
headers={"content-type": "application/json"},
data=None,
auth=None,
params=None,
chunked=None,
timeout=None,
@@ -540,7 +530,6 @@ async def test_interfaces(compute):
"https://example.com:84/v3/compute/network/interfaces",
headers={"content-type": "application/json"},
data=None,
auth=None,
params=None,
chunked=None,
timeout=120,
+4 -1
View File
@@ -120,7 +120,7 @@ async def write_file(path, z):
@pytest.fixture
def export_project_with_symlink(tmpdir, controller):
async def _export(symlink_target):
project = Project(controller=controller, name="test")
project = Project(controller=controller, name="test", filename="project.gns3")
project.dump = MagicMock()
topology = {
@@ -148,6 +148,9 @@ def export_project_with_symlink(tmpdir, controller):
await export_project(z, project, str(tmpdir), include_images=False)
await write_file(zip_path, z)
with zipfile.ZipFile(zip_path) as archive:
assert archive.namelist().count("project.gns3") == 1
return zip_path
return _export
+4
View File
@@ -7,3 +7,7 @@ asyncio_default_fixture_loop_scope=function
markers =
e2e: live end-to-end tests (real server, kernel interfaces, emulators)
addopts = -m "not e2e"
filterwarnings =
ignore:'asyncio\.iscoroutinefunction' is deprecated:DeprecationWarning:langsmith\._internal\._beta_decorator
ignore:_pytest\.python\.CallSpec2 has been renamed to CallSpec\.:pytest.PytestRemovedIn10Warning:anyio\.pytest_plugin