style: sort imports in api tests

This commit is contained in:
Mark Paronyan 2026-09-30 20:51:24 +03:00
parent 55df230864
commit b46b9a1d26
40 changed files with 142 additions and 152 deletions

View File

@ -16,14 +16,14 @@
import sys
import pytest
import psutil
import psutil
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from gns3server.version import __version__
from gns3server.utils.path import get_default_project_directory
from gns3server.version import __version__
pytestmark = pytest.mark.asyncio

View File

@ -16,13 +16,11 @@
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch
from gns3server.compute.project import Project
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -14,16 +14,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from unittest.mock import patch, MagicMock
import pytest
from unittest.mock import MagicMock, patch
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from gns3server.version import __version__
from gns3server.compute.project import Project
from gns3server.config import Config
from gns3server.schemas.config import ServerSettings
from gns3server.version import __version__
pytestmark = pytest.mark.asyncio

View File

@ -14,17 +14,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from unittest.mock import MagicMock, patch
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch, AsyncioMagicMock
from unittest.mock import patch, MagicMock
from gns3server.compute.docker import Docker
from gns3server.compute.docker.iol_docker_vm import IOLDockerVM
from gns3server.compute.project import Project
from tests.utils import AsyncioMagicMock, asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -14,12 +14,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import sys
import os
import stat
import sys
from unittest.mock import patch
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient

View File

@ -14,15 +14,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from unittest.mock import MagicMock, call
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch, AsyncioMagicMock
from unittest.mock import call, MagicMock
from gns3server.compute.project import Project
from tests.utils import AsyncioMagicMock, asyncio_patch
# The builtin Ethernet switch talks to uBridge (brctl/bridge modules) instead of
# the Dynamips hypervisor. These are the seams we stub so the routes can be

View File

@ -15,9 +15,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -14,18 +14,18 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import pytest_asyncio
import os
import stat
import uuid
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch
from unittest.mock import patch
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from gns3server.compute.project import Project
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -16,12 +16,11 @@
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch
from gns3server.compute.project import Project
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -15,9 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import json
import pytest
from gns3server.compute.notification_manager import NotificationManager

View File

@ -14,17 +14,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import uuid
import os
import uuid
from unittest.mock import patch
from tests.utils import asyncio_patch
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from gns3server.compute.project_manager import ProjectManager
from gns3server.compute.project import Project
from gns3server.compute.project_manager import ProjectManager
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio
@ -208,6 +208,7 @@ class TestBatchNIOEdgeCases:
async def test_dynamips_router_dispatch_to_slot_add_nio_binding(self):
"""_add_nio_binding dispatches Dynamips router to slot_add_nio_binding."""
from unittest.mock import AsyncMock, MagicMock
from gns3server.api.routes.compute.projects import _add_nio_binding
node = MagicMock()
@ -222,6 +223,7 @@ class TestBatchNIOEdgeCases:
async def test_dynamips_switch_dispatch_to_add_nio(self):
"""_add_nio_binding dispatches Dynamips switch to add_nio."""
from unittest.mock import AsyncMock, MagicMock
from gns3server.api.routes.compute.projects import _add_nio_binding
node = MagicMock()
@ -239,8 +241,8 @@ class TestBatchNIOEdgeCases:
Dynamips.create_nio is async (returns a coroutine) unlike the sync
base version. The batch handler must await it.
"""
import inspect
import asyncio as _asyncio
import inspect
class _FakeDynamips:
async def create_nio(self, node, nio_settings):
@ -267,6 +269,7 @@ class TestBatchNIOEdgeCases:
async def test_qemu_dispatch_to_adapter_add_nio_binding(self):
"""_add_nio_binding dispatches Qemu to adapter_add_nio_binding."""
from unittest.mock import AsyncMock, MagicMock
from gns3server.api.routes.compute.projects import _add_nio_binding
node = MagicMock()
@ -281,6 +284,7 @@ class TestBatchNIOEdgeCases:
async def test_iou_dispatch_to_adapter_add_nio_binding(self):
"""_add_nio_binding dispatches IOU to adapter_add_nio_binding(adapter, port, nio)."""
from unittest.mock import AsyncMock, MagicMock
from gns3server.api.routes.compute.projects import _add_nio_binding
node = MagicMock()
@ -300,6 +304,7 @@ class TestBatchNIOEdgeCases:
cross-wired links (the last entry per node wins).
"""
from unittest.mock import AsyncMock, MagicMock
from gns3server.api.routes.compute.projects import (
_add_nio_binding,
_get_existing_nio,
@ -326,6 +331,7 @@ class TestBatchNIOEdgeCases:
async def test_vpcs_dispatch_to_port_add_nio_binding(self):
"""_add_nio_binding dispatches VPCS to port_add_nio_binding."""
from unittest.mock import AsyncMock, MagicMock
from gns3server.api.routes.compute.projects import _add_nio_binding
node = MagicMock()
@ -340,6 +346,7 @@ class TestBatchNIOEdgeCases:
async def test_builtin_dispatch_to_add_nio(self):
"""_add_nio_binding dispatches Builtin nodes to add_nio(nio, port)."""
from unittest.mock import AsyncMock, MagicMock
from gns3server.api.routes.compute.projects import _add_nio_binding
node = MagicMock()

View File

@ -14,19 +14,19 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import shutil
import stat
import uuid
from unittest.mock import MagicMock, patch
import pytest
import pytest_asyncio
import os
import stat
import shutil
import uuid
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch
from unittest.mock import patch, MagicMock
from gns3server.compute.project import Project
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -14,15 +14,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch
from unittest.mock import patch
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from gns3server.compute.project import Project
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -14,15 +14,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch
from unittest.mock import patch
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from gns3server.compute.project import Project
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -14,15 +14,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch
from unittest.mock import patch
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from gns3server.compute.project import Project
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -33,9 +33,9 @@ from gns3server.controller.node import Node
from gns3server.controller.project import Project
from gns3server.services import access_ticket_service
from gns3server.services.access_tickets import (
AccessTicketService,
DEFAULT_TICKET_TTL,
TICKET_PREFIX,
AccessTicketService,
)
from gns3server.utils.http_client import HTTPClient
from tests.api.routes.controller.test_nodes import FakeComputeConsoleWebSocket

View File

@ -17,16 +17,15 @@
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from sqlalchemy.ext.asyncio import AsyncSession
from gns3server.db.repositories.users import UsersRepository
from gns3server.db.repositories.rbac import RbacRepository
from gns3server.schemas.controller.users import User
from gns3server.schemas.controller.rbac import ACECreate
from gns3server.controller import Controller
from gns3server.db.repositories.rbac import RbacRepository
from gns3server.db.repositories.users import UsersRepository
from gns3server.schemas.controller.rbac import ACECreate
from gns3server.schemas.controller.users import User
pytestmark = pytest.mark.asyncio

View File

@ -16,11 +16,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import pytest
import shutil
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from gns3server.controller import Controller
pytestmark = pytest.mark.asyncio

View File

@ -16,9 +16,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import uuid
import pytest
from unittest.mock import MagicMock, patch
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
@ -26,7 +26,7 @@ from gns3server.schemas.controller.computes import Compute
pytestmark = pytest.mark.asyncio
from tests.utils import asyncio_patch, AsyncioMagicMock
from tests.utils import AsyncioMagicMock, asyncio_patch
class TestComputeRoutes:

View File

@ -16,11 +16,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import pytest
from unittest.mock import MagicMock
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from unittest.mock import MagicMock
from gns3server.config import Config

View File

@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient

View File

@ -15,9 +15,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -16,11 +16,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from sqlalchemy.ext.asyncio import AsyncSession
from gns3server.db.repositories.users import UsersRepository
from gns3server.schemas.controller.users import User, UserGroupCreate

View File

@ -15,22 +15,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import json
import uuid
import pytest
import hashlib
import json
import os
import uuid
from tests.utils import asyncio_patch
from sqlalchemy.ext.asyncio import AsyncSession
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import AsyncioMagicMock
from sqlalchemy.ext.asyncio import AsyncSession
from gns3server.compute.qemu import Qemu
from gns3server.controller import Controller
from gns3server.db.repositories.images import ImagesRepository
from gns3server.db.repositories.templates import TemplatesRepository
from gns3server.compute.qemu import Qemu
from tests.utils import AsyncioMagicMock, asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -14,23 +14,22 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import uuid
import pytest_asyncio
from typing import Tuple
from unittest.mock import MagicMock, patch
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from unittest.mock import patch, MagicMock
from tests.utils import asyncio_patch, AsyncioMagicMock
from gns3server.controller.project import Project
from gns3server.controller.compute import Compute
from gns3server.controller.link import FILTERS, Link
from gns3server.controller.node import Node
from gns3server.controller.ports.ethernet_port import EthernetPort
from gns3server.controller.link import Link, FILTERS
from gns3server.controller.project import Project
from gns3server.controller.udp_link import UDPLink
from tests.utils import AsyncioMagicMock, asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -32,11 +32,10 @@ import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from gns3server.controller import marker_replay
from gns3server.controller.project import Project
from gns3server.controller.udp_link import UDPLink
from gns3server.controller import marker_replay
from tests.controller.test_marker_replay import _write_pcap, _icmp_frame, _tcp_syn_frame, _cols
from tests.controller.test_marker_replay import _cols, _icmp_frame, _tcp_syn_frame, _write_pcap
pytestmark = pytest.mark.asyncio

View File

@ -23,10 +23,9 @@ import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from tests.utils import asyncio_patch
from gns3server.controller.project import Project
from gns3server.controller.udp_link import UDPLink
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -16,7 +16,6 @@
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient

View File

@ -18,31 +18,28 @@
import asyncio
import contextlib
import logging
from types import SimpleNamespace
from typing import List, Optional
from unittest.mock import MagicMock, patch
import aiohttp
import pytest
from types import SimpleNamespace
from typing import List, Optional
from fastapi import FastAPI, HTTPException, WebSocketDisconnect, status
from httpx import AsyncClient
from pydantic import SecretStr
from httpx_ws import aconnect_ws
from httpx_ws import WebSocketDisconnect as HttpxWebSocketDisconnect
from httpx_ws.transport import ASGIWebSocketTransport, ASGIWebSocketAsyncNetworkStream
from unittest.mock import MagicMock, patch
from tests.utils import AsyncioMagicMock
from httpx_ws import aconnect_ws
from httpx_ws.transport import ASGIWebSocketAsyncNetworkStream, ASGIWebSocketTransport
from pydantic import SecretStr
from gns3server.api.routes.controller.nodes import vnc_console, ws_console
from gns3server.config import Config
from gns3server.controller.compute import Compute
from gns3server.controller.node import Node
from gns3server.controller.project import Project
from gns3server.controller.compute import Compute
from gns3server.utils.http_client import HTTPClient
from gns3server.api.routes.controller.nodes import ws_console, vnc_console
from gns3server.services import auth_service
from gns3server.services.authentication import DEFAULT_JWT_SECRET_KEY
from gns3server.utils.http_client import HTTPClient
from tests.utils import AsyncioMagicMock
pytestmark = pytest.mark.asyncio

View File

@ -16,16 +16,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import uuid
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from sqlalchemy.ext.asyncio import AsyncSession
from gns3server.db.repositories.pools import ResourcePoolsRepository
from gns3server.controller import Controller
from gns3server.controller.project import Project
from gns3server.db.repositories.pools import ResourcePoolsRepository
from gns3server.schemas.controller.pools import ResourceCreate, ResourcePoolCreate
pytestmark = pytest.mark.asyncio

View File

@ -14,21 +14,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import uuid
import os
import json
import os
import uuid
from unittest.mock import MagicMock, patch
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient
from unittest.mock import patch, MagicMock
from tests.utils import asyncio_patch, AsyncioMagicMock
import gns3server.utils.zipfile_zstd as zipfile_zstd
from gns3server.controller import Controller
from gns3server.controller.project import Project
from gns3server.controller.compute import Compute
from gns3server.controller.project import Project
from tests.utils import AsyncioMagicMock, asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -16,11 +16,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from sqlalchemy.ext.asyncio import AsyncSession
from gns3server.db.repositories.rbac import RbacRepository
pytestmark = pytest.mark.asyncio

View File

@ -14,11 +14,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import configparser
import os
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient

View File

@ -17,9 +17,9 @@
import os
import uuid
import pytest
import pytest_asyncio
from fastapi import FastAPI, status
from httpx import AsyncClient

View File

@ -15,10 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import os
import urllib.parse
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient

View File

@ -15,27 +15,25 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import json
import os
import shutil
import unittest.mock
import uuid
from pathlib import Path
import pytest
import uuid
import unittest.mock
from pathlib import Path
from fastapi import FastAPI, status
from httpx import AsyncClient
from sqlalchemy.ext.asyncio import AsyncSession
from tests.utils import asyncio_patch
from gns3server import schemas
from gns3server.api.routes.controller.dependencies.authentication import get_current_active_user
from gns3server.controller import Config, Controller
from gns3server.db.repositories.images import ImagesRepository
from gns3server.db.repositories.templates import TemplatesRepository
from gns3server.controller import Controller
from gns3server.controller import Config
from gns3server.services.templates import BUILTIN_TEMPLATES
from gns3server.api.routes.controller.dependencies.authentication import get_current_active_user
from gns3server import schemas
from tests.utils import asyncio_patch
pytestmark = pytest.mark.asyncio

View File

@ -15,21 +15,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
from typing import Optional
import pytest
from fastapi import FastAPI, HTTPException, status
from sqlalchemy import update
from httpx import AsyncClient
from joserfc import jwt
from joserfc.jwk import OctKey
from sqlalchemy import update
from sqlalchemy.ext.asyncio import AsyncSession
from gns3server.db.repositories.users import UsersRepository
from gns3server.services import auth_service
from gns3server.config import Config
from gns3server.schemas.controller.users import User
import gns3server.db.models as models
from gns3server.config import Config
from gns3server.db.repositories.users import UsersRepository
from gns3server.schemas.controller.users import User
from gns3server.services import auth_service
pytestmark = pytest.mark.asyncio

View File

@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient

View File

@ -14,16 +14,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import os
from fastapi import FastAPI, status
from httpx import AsyncClient
from unittest.mock import patch
from gns3server.version import __version__
import pytest
from fastapi import FastAPI, status
from httpx import AsyncClient
from gns3server.controller import Controller
from gns3server.utils.get_resource import get_resource
from gns3server.version import __version__
pytestmark = pytest.mark.asyncio

View File

@ -14,15 +14,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from typing import Iterator, Sequence, Tuple
import pytest
from fastapi import FastAPI, status
from fastapi.routing import APIRoute, APIWebSocketRoute, _IncludedRouter
from starlette.routing import BaseRoute, Mount
from httpx import AsyncClient
from httpx_ws import aconnect_ws
from httpx_ws.transport import ASGIWebSocketTransport
from typing import Iterator, Sequence, Tuple
from starlette.routing import BaseRoute, Mount
pytestmark = pytest.mark.asyncio