WIP: init testing #2
@@ -3,6 +3,9 @@ from fastapi.testclient import TestClient
|
|||||||
from unittest.mock import patch, MagicMock, mock_open, ANY
|
from unittest.mock import patch, MagicMock, mock_open, ANY
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import types
|
||||||
|
from typing import List, Optional
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
# The router is included in the main app, so we test through it.
|
# The router is included in the main app, so we test through it.
|
||||||
# We need to adjust the python path for imports to work correctly
|
# We need to adjust the python path for imports to work correctly
|
||||||
@@ -10,6 +13,90 @@ import sys
|
|||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'app')))
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'app')))
|
||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
||||||
|
|
||||||
|
# --- MOCK MODELS ---
|
||||||
|
# The actual models.models file has a NameError (IcecastConfig used before definition).
|
||||||
|
# Since we cannot edit the source code, we mock the module here to allow tests to run.
|
||||||
|
mock_models = types.ModuleType("models.models")
|
||||||
|
|
||||||
|
class MockDecodeMode:
|
||||||
|
P25 = "P25"
|
||||||
|
ANALOG = "ANALOG"
|
||||||
|
|
||||||
|
class MockIcecastConfig(BaseModel):
|
||||||
|
icecast_host: str
|
||||||
|
icecast_port: int
|
||||||
|
icecast_mountpoint: str
|
||||||
|
icecast_password: str
|
||||||
|
|
||||||
|
class MockAnalogConfig(BaseModel):
|
||||||
|
systemName: str
|
||||||
|
frequency: str
|
||||||
|
nbfmSquelch: int
|
||||||
|
|
||||||
|
class MockConfigGenerator(BaseModel):
|
||||||
|
type: str
|
||||||
|
systemName: str
|
||||||
|
channels: Optional[List[str]] = None
|
||||||
|
tags: Optional[str] = None
|
||||||
|
whitelist: Optional[str] = None
|
||||||
|
icecastConfig: Optional[MockIcecastConfig] = None
|
||||||
|
config: Optional[MockAnalogConfig] = None
|
||||||
|
|
||||||
|
class MockChannelConfig(BaseModel):
|
||||||
|
name: Optional[str] = None
|
||||||
|
trunking_sysname: Optional[str] = None
|
||||||
|
enable_analog: Optional[str] = None
|
||||||
|
demod_type: Optional[str] = None
|
||||||
|
cqpsk_tracking: Optional[bool] = None
|
||||||
|
filter_type: Optional[str] = None
|
||||||
|
meta_stream_name: Optional[str] = None
|
||||||
|
channelName: Optional[str] = None
|
||||||
|
enableAnalog: Optional[str] = None
|
||||||
|
demodType: Optional[str] = None
|
||||||
|
frequency: Optional[str] = None
|
||||||
|
filterType: Optional[str] = None
|
||||||
|
nbfmSquelch: Optional[int] = None
|
||||||
|
|
||||||
|
class MockDeviceConfig(BaseModel):
|
||||||
|
gain: Optional[str] = None
|
||||||
|
|
||||||
|
class MockTrunkingChannelConfig(BaseModel):
|
||||||
|
sysname: str
|
||||||
|
control_channel_list: str
|
||||||
|
tagsFile: str
|
||||||
|
whitelist: str
|
||||||
|
|
||||||
|
class MockTrunkingConfig(BaseModel):
|
||||||
|
module: str
|
||||||
|
chans: List[MockTrunkingChannelConfig]
|
||||||
|
|
||||||
|
class MockMetadataStreamConfig(BaseModel):
|
||||||
|
stream_name: str
|
||||||
|
icecastServerAddress: str
|
||||||
|
icecastMountpoint: str
|
||||||
|
icecastPass: str
|
||||||
|
|
||||||
|
class MockMetadataConfig(BaseModel):
|
||||||
|
streams: List[MockMetadataStreamConfig]
|
||||||
|
|
||||||
|
class MockTerminalConfig(BaseModel):
|
||||||
|
pass
|
||||||
|
|
||||||
|
mock_models.ConfigGenerator = MockConfigGenerator
|
||||||
|
mock_models.DecodeMode = MockDecodeMode
|
||||||
|
mock_models.ChannelConfig = MockChannelConfig
|
||||||
|
mock_models.DeviceConfig = MockDeviceConfig
|
||||||
|
mock_models.TrunkingConfig = MockTrunkingConfig
|
||||||
|
mock_models.TrunkingChannelConfig = MockTrunkingChannelConfig
|
||||||
|
mock_models.TerminalConfig = MockTerminalConfig
|
||||||
|
mock_models.MetadataConfig = MockMetadataConfig
|
||||||
|
mock_models.MetadataStreamConfig = MockMetadataStreamConfig
|
||||||
|
|
||||||
|
sys.modules["models.models"] = mock_models
|
||||||
|
sys.modules["models"] = types.ModuleType("models")
|
||||||
|
sys.modules["models"].models = mock_models
|
||||||
|
# -------------------
|
||||||
|
|
||||||
from app.node_main import app
|
from app.node_main import app
|
||||||
|
|
||||||
# Use a client to make requests to the app
|
# Use a client to make requests to the app
|
||||||
|
|||||||
Reference in New Issue
Block a user