From 3c7a050349c9653702ac66219a00af27c5388cce Mon Sep 17 00:00:00 2001 From: Rebecca Breu Date: Wed, 28 Jul 2021 18:24:08 +0200 Subject: [PATCH] Add unittest for the actual migrations --- CHANGELOG.rst | 2 +- tests/fileio/test_sql.py | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e91fc9b..c279dcd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,7 +4,7 @@ Added ----- -* You can now add plain text notes +* You can now add plain text notes. Bee files from version 0.2.0 won't work with BeeRef 0.1.x. Changed ------- diff --git a/tests/fileio/test_sql.py b/tests/fileio/test_sql.py index 77235c7..0fcaa97 100644 --- a/tests/fileio/test_sql.py +++ b/tests/fileio/test_sql.py @@ -63,6 +63,54 @@ def test_sqliteio_migrate_migrates_when_file_not_writable(tmpfile): assert os.path.exists(newdir) is False +def test_all_migrations(tmpfile): + io = SQLiteIO(tmpfile, MagicMock(), create_new=True) + + # Set up version 1 bee file + io.ex('PRAGMA user_version=1') + io.ex(""" + CREATE TABLE items ( + id INTEGER PRIMARY KEY, + type TEXT NOT NULL, + x REAL DEFAULT 0, + y REAL DEFAULT 0, + z REAL DEFAULT 0, + scale REAL DEFAULT 1, + rotation REAL DEFAULT 0, + flip INTEGER DEFAULT 1, + filename TEXT)""") + io.ex(""" + CREATE TABLE sqlar ( + name TEXT PRIMARY KEY, + item_id INTEGER NOT NULL, + mode INT, + mtime INT default current_timestamp, + sz INT, + data BLOB, + FOREIGN KEY (item_id) + REFERENCES items (id) + ON DELETE CASCADE + ON UPDATE NO ACTION)""") + io.ex('INSERT INTO items ' + '(type, x, y, z, scale, rotation, flip, filename) ' + 'VALUES (?, ?, ?, ?, ?, ?, ?, ?) ', + ('pixmap', 22.2, 33.3, 0.22, 3.4, 45, -1, 'bee.png')) + io.ex('INSERT INTO sqlar (item_id, data) VALUES (?, ?)', + (1, b'bla')) + io.connection.commit() + del(io) + + io = SQLiteIO(tmpfile, MagicMock(), create_new=False) + result = io.fetchone('PRAGMA user_version') + assert result[0] == schema.USER_VERSION + result = io.fetchone( + 'SELECT x, y, items.data, sqlar.data FROM items ' + 'LEFT OUTER JOIN sqlar on sqlar.item_id = items.id') + assert result[0] == 22.2 + assert result[1] == 33.3 + assert json.loads(result[2]) == {'filename': 'bee.png'} + assert result[3] == b'bla' + def test_sqliteio_แบrite_meta_application_id(tmpfile): io = SQLiteIO(tmpfile, MagicMock(), create_new=True) io.write_meta()