Philipp Hörist pushed to branch dbimprv at gajim / gajim
Commits:
5e1cd0b4 by Philipp Hörist at 2026-05-18T19:52:42+02:00
new: Tests: Add migration test
- - - - -
1 changed file:
- + test/database/test_migration.py
Changes:
=====================================
test/database/test_migration.py
=====================================
@@ -0,0 +1,84 @@
+# This file is part of Gajim.
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+from __future__ import annotations
+
+import unittest
+from pathlib import Path
+
+import sqlalchemy as sa
+
+from gajim.common import app
+from gajim.common.settings import Settings
+from gajim.common.storage.archive import migration
+from gajim.common.storage.archive.storage import CURRENT_USER_VERSION
+from gajim.common.storage.archive.storage import MessageArchiveStorage
+
+
+class TestMigration(unittest.TestCase):
+ def setUp(self) -> None:
+ self._init_settings()
+
+ def tearDown(self) -> None:
+ Path("test.db").unlink(missing_ok=True)
+ Path("test.db-shm").unlink(missing_ok=True)
+ Path("test.db-wal").unlink(missing_ok=True)
+
+ def _init_settings(self) -> None:
+ app.settings = Settings(in_memory=True)
+ app.settings.init()
+ app.settings.add_account("testacc1")
+ app.settings.set_account_setting("testacc1", "address",
"[email protected]")
+
+ def test_migration(self) -> None:
+ # Database schema for Gajim 0.16.9
+ DATABASE_SCHEMA = """
+ CREATE TABLE jids(
+ jid_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
+ jid TEXT UNIQUE,
+ type INTEGER
+ );
+
+ CREATE TABLE unread_messages(
+ message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
+ jid_id INTEGER,
+ shown BOOLEAN default 0
+ );
+
+ CREATE INDEX idx_unread_messages_jid_id ON unread_messages
(jid_id);
+
+ CREATE TABLE logs(
+ log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
+ jid_id INTEGER,
+ contact_name TEXT,
+ time INTEGER,
+ kind INTEGER,
+ show INTEGER,
+ message TEXT,
+ subject TEXT
+ );
+
+ CREATE INDEX idx_logs_jid_id_time ON logs (jid_id, time DESC);"""
+
+ dbpath = Path("test.db")
+ engine = sa.create_engine(f"sqlite:///{dbpath}", echo=False)
+
+ with engine.connect() as connection:
+ for stmt in DATABASE_SCHEMA.split(";"):
+ connection.execute(sa.text(stmt))
+ connection.commit()
+
+ engine.dispose()
+
+ archive = MessageArchiveStorage(path=dbpath)
+ migration.run(archive, 0)
+
+ version = archive.get_user_version()
+ self.assertEqual(version, CURRENT_USER_VERSION)
+
+ archive.shutdown()
+
+
+if __name__ == "__main__":
+ unittest.main()
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/5e1cd0b4dc44ade3803cf9db6702dcda0ca1dff0
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/commit/5e1cd0b4dc44ade3803cf9db6702dcda0ca1dff0
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]