diff --git a/testing/test_songs_db.py b/testing/test_songs_db.py index 4210b3fef..ae8d78251 100644 --- a/testing/test_songs_db.py +++ b/testing/test_songs_db.py @@ -30,6 +30,10 @@ 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 @@ -48,6 +52,24 @@ def test_empty_songdb(empty_songs_db): 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 - 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