Add unittest for the actual migrations

This commit is contained in:
Rebecca Breu 2021-07-28 18:24:08 +02:00
parent 5d115b9391
commit 3c7a050349
2 changed files with 49 additions and 1 deletions

View file

@ -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
-------

View file

@ -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()