mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-07-06 09:52:06 +02:00
Be better about DB insertion shape
This commit is contained in:
@@ -65,6 +65,29 @@ def test_require_connected_preserves_http_semantics():
|
||||
assert exc.value.status_code == 503
|
||||
|
||||
|
||||
def test_require_connected_returns_fresh_meshcore_after_connectivity_check():
|
||||
old_meshcore = object()
|
||||
new_meshcore = object()
|
||||
|
||||
class _SwappingManager:
|
||||
def __init__(self):
|
||||
self._meshcore = old_meshcore
|
||||
self.is_setup_in_progress = False
|
||||
|
||||
@property
|
||||
def is_connected(self):
|
||||
self._meshcore = new_meshcore
|
||||
return True
|
||||
|
||||
@property
|
||||
def meshcore(self):
|
||||
return self._meshcore
|
||||
|
||||
runtime = RadioRuntime(_SwappingManager())
|
||||
|
||||
assert runtime.require_connected() is new_meshcore
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_radio_operation_delegates_to_current_manager():
|
||||
manager = _Manager(meshcore="meshcore", is_connected=True)
|
||||
|
||||
@@ -4,6 +4,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.models import Contact, ContactUpsert
|
||||
from app.repository import (
|
||||
ContactAdvertPathRepository,
|
||||
ContactNameHistoryRepository,
|
||||
@@ -643,3 +644,34 @@ class TestMessageRepositoryGetById:
|
||||
result = await MessageRepository.get_by_id(999999)
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
class TestContactRepositoryUpsertContracts:
|
||||
@pytest.mark.asyncio
|
||||
async def test_accepts_contact_upsert_model(self, test_db):
|
||||
await ContactRepository.upsert(
|
||||
ContactUpsert(public_key="aa" * 32, name="Alice", type=1, on_radio=False)
|
||||
)
|
||||
|
||||
contact = await ContactRepository.get_by_key("aa" * 32)
|
||||
assert contact is not None
|
||||
assert contact.name == "Alice"
|
||||
assert contact.type == 1
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_accepts_contact_model(self, test_db):
|
||||
await ContactRepository.upsert(
|
||||
Contact(
|
||||
public_key="bb" * 32,
|
||||
name="Bob",
|
||||
type=2,
|
||||
on_radio=True,
|
||||
out_path_hash_mode=-1,
|
||||
)
|
||||
)
|
||||
|
||||
contact = await ContactRepository.get_by_key("bb" * 32)
|
||||
assert contact is not None
|
||||
assert contact.name == "Bob"
|
||||
assert contact.type == 2
|
||||
assert contact.on_radio is True
|
||||
|
||||
Reference in New Issue
Block a user