mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 18:18:47 +01:00
cleanup endpoint tests
This commit is contained in:
@@ -1,12 +1,28 @@
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from config import (
|
||||
OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS,
|
||||
OAUTH_REFRESH_TOKEN_EXPIRE_SECONDS,
|
||||
)
|
||||
from handler.auth import oauth_handler
|
||||
from handler.redis_handler import sync_cache
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_cache():
|
||||
sync_cache.flushall()
|
||||
yield
|
||||
sync_cache.flushall()
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@@ -33,3 +49,15 @@ def refresh_token(admin_user): # noqa
|
||||
return oauth_handler.create_refresh_token(
|
||||
data=data, expires_delta=timedelta(seconds=OAUTH_REFRESH_TOKEN_EXPIRE_SECONDS)
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def editor_access_token(editor_user): # noqa
|
||||
return oauth_handler.create_access_token(
|
||||
data={
|
||||
"sub": editor_user.username,
|
||||
"iss": "romm:oauth",
|
||||
"scopes": " ".join(editor_user.oauth_scopes),
|
||||
},
|
||||
expires_delta=timedelta(seconds=OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS),
|
||||
)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from handler.database import db_platform_handler, db_rom_handler
|
||||
from handler.metadata.base_handler import UniversalPlatformSlug as UPS
|
||||
@@ -9,12 +7,6 @@ from models.platform import Platform
|
||||
from models.rom import Rom, RomFile, RomFileCategory
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
def test_webrcade_feed(
|
||||
client: TestClient, access_token: str, platform: Platform, rom: Rom
|
||||
):
|
||||
|
||||
@@ -4,7 +4,6 @@ from unittest.mock import AsyncMock, patch
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from handler.filesystem.roms_handler import FSRomsHandler
|
||||
from handler.metadata.flashpoint_handler import FlashpointHandler, FlashpointRom
|
||||
@@ -17,13 +16,6 @@ from handler.metadata.ss_handler import SSHandler, SSRom
|
||||
from models.platform import Platform
|
||||
from models.rom import Rom
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
MOCK_IGDB_ID = 11111
|
||||
MOCK_MOBY_ID = 22222
|
||||
MOCK_SS_ID = 33333
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock
|
||||
from uuid import UUID
|
||||
@@ -6,41 +5,12 @@ from uuid import UUID
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from config import OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS
|
||||
from endpoints.roms import upload as upload_endpoint
|
||||
from handler.auth import oauth_handler
|
||||
from handler.redis_handler import sync_cache
|
||||
from models.platform import Platform
|
||||
from models.user import User
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_cache():
|
||||
sync_cache.flushall()
|
||||
yield
|
||||
sync_cache.flushall()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def editor_access_token(editor_user: User):
|
||||
return oauth_handler.create_access_token(
|
||||
data={
|
||||
"sub": editor_user.username,
|
||||
"iss": "romm:oauth",
|
||||
"scopes": " ".join(editor_user.oauth_scopes),
|
||||
},
|
||||
expires_delta=timedelta(seconds=OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS),
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def upload_fs(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
||||
uploads_tmp = tmp_path / "uploads"
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from handler.database import db_save_handler, db_screenshot_handler, db_state_handler
|
||||
from models.assets import Save, Screenshot, State
|
||||
@@ -10,12 +8,6 @@ from models.rom import Rom
|
||||
from models.user import User
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
def test_delete_saves(client, access_token, save):
|
||||
response = client.post(
|
||||
"/api/saves/delete",
|
||||
|
||||
@@ -2,8 +2,6 @@ from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from config import OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS
|
||||
from handler.auth import auth_handler, oauth_handler
|
||||
@@ -13,24 +11,6 @@ from models.client_token import ClientToken
|
||||
from models.user import Role
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def editor_access_token(editor_user):
|
||||
return oauth_handler.create_access_token(
|
||||
data={
|
||||
"sub": editor_user.username,
|
||||
"iss": "romm:oauth",
|
||||
"scopes": " ".join(editor_user.oauth_scopes),
|
||||
},
|
||||
expires_delta=timedelta(seconds=OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS),
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def viewer_access_token(viewer_user):
|
||||
return oauth_handler.create_access_token(
|
||||
@@ -43,12 +23,6 @@ def viewer_access_token(viewer_user):
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_cache():
|
||||
yield
|
||||
sync_cache.flushall()
|
||||
|
||||
|
||||
class TestClientTokenCRUD:
|
||||
def test_create_token(self, client, access_token, admin_user):
|
||||
response = client.post(
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from config.config_manager import (
|
||||
DEFAULT_EXCLUDED_DIRS,
|
||||
@@ -13,12 +10,6 @@ from config.config_manager import (
|
||||
from config.config_manager import config_manager as cm
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
def test_config(client):
|
||||
response = client.get("/api/config")
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
@@ -1,42 +1,10 @@
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from config import OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS
|
||||
from handler.auth import oauth_handler
|
||||
from handler.database import db_device_handler
|
||||
from handler.redis_handler import sync_cache
|
||||
from models.device import Device
|
||||
from models.user import User
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_cache():
|
||||
yield
|
||||
sync_cache.flushall()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def editor_access_token(editor_user: User):
|
||||
return oauth_handler.create_access_token(
|
||||
data={
|
||||
"sub": editor_user.username,
|
||||
"iss": "romm:oauth",
|
||||
"scopes": " ".join(editor_user.oauth_scopes),
|
||||
},
|
||||
expires_delta=timedelta(seconds=OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS),
|
||||
)
|
||||
|
||||
|
||||
class TestDeviceEndpoints:
|
||||
def test_register_device(self, client, access_token: str):
|
||||
response = client.post(
|
||||
|
||||
@@ -1,20 +1,11 @@
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from exceptions.fs_exceptions import PlatformAlreadyExistsException
|
||||
from utils import get_version
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
def test_heartbeat(client):
|
||||
response = client.get("/api/heartbeat")
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
|
||||
@@ -6,29 +6,15 @@ from unittest import mock
|
||||
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from config import OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS
|
||||
from handler.auth import oauth_handler
|
||||
from handler.auth.middleware.redis_session_middleware import RedisSessionMiddleware
|
||||
from handler.database.users_handler import DBUsersHandler
|
||||
from handler.redis_handler import async_cache, sync_cache
|
||||
from handler.redis_handler import async_cache
|
||||
from models.user import Role, User
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_cache():
|
||||
yield
|
||||
sync_cache.flushall()
|
||||
|
||||
|
||||
def test_login_logout(client, admin_user: User):
|
||||
response = client.get("/api/login")
|
||||
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.exceptions import HTTPException
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from config import OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS
|
||||
from handler.auth.constants import EDIT_SCOPES
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
def test_refreshing_oauth_token_basic(client, refresh_token):
|
||||
response = client.post(
|
||||
"/api/token",
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
def test_get_platforms(client, access_token, platform):
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
def test_get_raw_asset(client, access_token):
|
||||
|
||||
@@ -4,14 +4,11 @@ from unittest import mock
|
||||
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from config import OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS
|
||||
from handler.auth import oauth_handler
|
||||
from handler.auth.constants import Scope
|
||||
from handler.database import db_device_handler, db_device_save_sync_handler
|
||||
from handler.redis_handler import sync_cache
|
||||
from models.assets import Save
|
||||
from models.device import Device
|
||||
from models.platform import Platform
|
||||
@@ -19,18 +16,6 @@ from models.rom import Rom
|
||||
from models.user import User
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_cache():
|
||||
yield
|
||||
sync_cache.flushall()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def device(admin_user: User):
|
||||
return db_device_handler.add_device(
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
"""Tests for sync endpoints."""
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import datetime, timezone
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from config import OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS
|
||||
from handler.auth import oauth_handler
|
||||
from handler.database import (
|
||||
db_device_handler,
|
||||
db_device_save_sync_handler,
|
||||
db_save_handler,
|
||||
db_sync_session_handler,
|
||||
)
|
||||
from handler.redis_handler import sync_cache
|
||||
from models.assets import Save
|
||||
from models.device import Device, SyncMode
|
||||
from models.platform import Platform
|
||||
@@ -25,30 +19,6 @@ from models.sync_session import SyncSession, SyncSessionStatus
|
||||
from models.user import User
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def clear_cache():
|
||||
yield
|
||||
sync_cache.flushall()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def editor_access_token(editor_user: User):
|
||||
return oauth_handler.create_access_token(
|
||||
data={
|
||||
"sub": editor_user.username,
|
||||
"iss": "romm:oauth",
|
||||
"scopes": " ".join(editor_user.oauth_scopes),
|
||||
},
|
||||
expires_delta=timedelta(seconds=OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS),
|
||||
)
|
||||
|
||||
|
||||
class TestSyncNegotiate:
|
||||
def test_negotiate_new_client_save(
|
||||
self, client, access_token: str, admin_user: User, rom: Rom
|
||||
|
||||
@@ -2,18 +2,10 @@ from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
from fastapi import status
|
||||
from fastapi.testclient import TestClient
|
||||
from main import app
|
||||
|
||||
from tasks.tasks import Task, TaskType
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
with TestClient(app) as client:
|
||||
yield client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_task():
|
||||
"""Create a mock task for testing"""
|
||||
|
||||
Reference in New Issue
Block a user