Add test for empty song database

This commit is contained in:
Martin Zibricky 2011-09-04 14:50:25 +02:00
parent 27897c95fd
commit 445a0ccb49
1 changed files with 24 additions and 2 deletions

View File

@ -30,6 +30,10 @@
Songs database tests Songs database tests
""" """
import pytest
from sqlalchemy.exc import InvalidRequestError
from sqlalchemy.orm.exc import UnmappedInstanceError
from openlp.plugins.songs.lib.db import Author, Book, MediaFile, Song, Topic from openlp.plugins.songs.lib.db import Author, Book, MediaFile, Song, Topic
@ -48,6 +52,24 @@ def test_empty_songdb(empty_songs_db):
assert c(Topic) == 0 assert c(Topic) == 0
def test_nonexisting_class(empty_songs_db): def test_unmapped_class(empty_songs_db):
# test class not mapped to any sqlalchemy table # test class not mapped to any sqlalchemy table
assert 0 class A(object):
pass
db = empty_songs_db
assert db.save_object(A()) == False
assert db.save_objects([A(), A()]) == False
# no key - new object instance is created from supplied class
assert type(db.get_object(A, key=None)) == A
with pytest.raises(InvalidRequestError):
db.get_object(A, key=1)
with pytest.raises(InvalidRequestError):
db.get_object_filtered(A, filter_clause=None)
with pytest.raises(InvalidRequestError):
db.get_all_objects(A)
with pytest.raises(InvalidRequestError):
db.get_object_count(A)
assert db.delete_object(A, key=None) == False
assert db.delete_all_objects(A) == False