Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Commit

Permalink
Added a database schema upgrade test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Romansky committed Oct 18, 2014
1 parent ff645ce commit 8756aad
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/freeseer/framework/database.py
Expand Up @@ -121,6 +121,33 @@ def __get_db_version_int(self):
query.first()
return query.value(0).toInt()[0]

def __test_2x_schema_insertion(self):
"""Testing function used to insert a 2x format database schema into the database"""
return QtSql.QSqlQuery('''
CREATE TABLE presentations
(Id Integer Primary Key,
Title varchar(255),
Speaker varchar(100),
Description text,
Level varchar(25),
Event varchar(100),
Room varchar(25),
Time timestamp)
''')

def __test_insert_2x_presentation(self):
"""Inserts a hardcoded 2x format presentation into the database for use with the
__test_2x_schema_insertion() function
"""
return QtSql.QSqlQuery('''
INSERT INTO presentations
VALUES(1, 'An Old Title', 'Old Speaker', 'This is an example presentation from 2x', 'level 9',
'Winter conference', '12', '2002-10-05')
''')

def __drop_presentation(self):
QtSql.QSqlQuery('DROP TABLE presentations')

def __update_version(self):
"""Upgrade database to the latest SCHEMA_VERSION"""

Expand Down
14 changes: 14 additions & 0 deletions src/freeseer/tests/framework/test_database.py
Expand Up @@ -26,6 +26,7 @@

import pytest
import httpretty
from PyQt4 import QtSql
from PyQt4.QtCore import QDate, QTime

from freeseer.framework.config.profile import Profile
Expand Down Expand Up @@ -322,3 +323,16 @@ def test_update_failure(db):
assert db.get_report('1').comment == failure1.comment
db.update_failure('1', failure2) # replace failure1 with failure2
assert db.get_report('1').comment == failure2.comment


def test_upgrade_database(db):
db._QtDBConnector__drop_presentation() # This is how to call a private function in python. :(
# Create a 2x table.
assert db._QtDBConnector__test_2x_schema_insertion()
# Insert a 2x value.
assert db._QtDBConnector__test_insert_2x_presentation()

db._QtDBConnector__update_version()
presentation = db.get_presentation('1')
assert None != presentation
assert presentation.title == 'An Old Title'

0 comments on commit 8756aad

Please sign in to comment.