You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ADN-DMR-Peer-Server/tests/infrastructure/test_mysql_pool_ensure.py

62 lines
2.6 KiB

# ADN DMR Peer Server - tests infrastructure mysql pool ensure
#
# Copyright (C) 2026 Rodrigo Pérez, CE5RPY <ce5rpy@qmd.cl>
#
###############################################################################
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
###############################################################################
"""Startup ensure for peer_dynamic_tgs (server-owned migration)."""
from __future__ import annotations
from unittest.mock import MagicMock
from adn_server.infrastructure.persistence.database_config import validate_database_settings
from adn_server.infrastructure.persistence.mysql_pool import (
_ensure_peer_dynamic_tgs_on_cursor,
describe_mysql_error,
)
def test_validate_database_settings_requires_db_name() -> None:
assert validate_database_settings({"db_username": "hbmon", "db_name": ""}) is not None
def test_describe_mysql_error_unknown_database() -> None:
err = Exception(1049, "Unknown database 'missing'")
msg = describe_mysql_error(err)
assert "1049" in msg
assert "DATABASE.DB_NAME" in msg
def test_ensure_peer_dynamic_tgs_applies_migration_once() -> None:
cur = MagicMock()
cur.fetchone.side_effect = [None, (1,)] # migration missing, then exists on re-check path
_ensure_peer_dynamic_tgs_on_cursor(cur)
executed = [call[0][0] for call in cur.execute.call_args_list]
assert any("schema_migrations" in sql for sql in executed)
assert any("peer_dynamic_tgs" in sql for sql in executed)
assert any("INSERT IGNORE INTO schema_migrations" in sql for sql in executed)
def test_ensure_peer_dynamic_tgs_skips_when_migration_marked() -> None:
cur = MagicMock()
cur.fetchone.return_value = (1,)
_ensure_peer_dynamic_tgs_on_cursor(cur)
executed = [call[0][0] for call in cur.execute.call_args_list]
assert any("schema_migrations" in sql for sql in executed)
assert not any("CREATE TABLE IF NOT EXISTS peer_dynamic_tgs" in sql for sql in executed)

Powered by TurnKey Linux.