mirror of
https://github.com/gryf/pygtktalog.git
synced 2025-12-17 11:30:19 +01:00
Added logic for Image and Thumbnail db objects. Added scan functionality
This commit is contained in:
@@ -7,9 +7,11 @@
|
||||
"""
|
||||
import os
|
||||
import unittest
|
||||
import logging
|
||||
|
||||
from pygtktalog import scan
|
||||
from pygtktalog.dbobjects import File
|
||||
from pygtktalog.dbcommon import connect, Session
|
||||
|
||||
|
||||
|
||||
class TestScan(unittest.TestCase):
|
||||
@@ -31,6 +33,19 @@ class TestScan(unittest.TestCase):
|
||||
3. adding new directory tree which contains same files like already stored
|
||||
in the database
|
||||
"""
|
||||
def setUp(self):
|
||||
connect()
|
||||
root = File()
|
||||
root.id = 1
|
||||
root.filename = 'root'
|
||||
root.size = 0
|
||||
root.source = 0
|
||||
root.type = 0
|
||||
root.parent_id = 1
|
||||
|
||||
sess = Session()
|
||||
sess.add(root)
|
||||
sess.commit()
|
||||
|
||||
def test_happy_scenario(self):
|
||||
"""
|
||||
@@ -59,10 +74,8 @@ class TestScan(unittest.TestCase):
|
||||
scanobj.path = '/bin/sh'
|
||||
self.assertRaises(scan.NoAccessError, scanobj.add_files)
|
||||
|
||||
|
||||
# dir contains some non accessable items. Should just pass, and on
|
||||
# logs should be messages about it
|
||||
logging.basicConfig(level=logging.CRITICAL)
|
||||
scanobj.path = "/mnt/data/_test_/test_dir_permissions/"
|
||||
scanobj.add_files()
|
||||
|
||||
@@ -71,8 +84,38 @@ class TestScan(unittest.TestCase):
|
||||
scanobj.abort = True
|
||||
self.assertEqual(None, scanobj.add_files())
|
||||
|
||||
def test_rescan(self):
|
||||
"""
|
||||
Do the scan twice.
|
||||
"""
|
||||
ses = Session()
|
||||
self.assertEqual(len(ses.query(File).all()), 1)
|
||||
|
||||
scanob = scan.Scan("/mnt/data/_test_/test_dir")
|
||||
scanob.add_files()
|
||||
|
||||
# note: we have 144 elements in db, because of root element
|
||||
self.assertEqual(len(ses.query(File).all()), 144)
|
||||
|
||||
scanob2 = scan.Scan("/mnt/data/_test_/test_dir")
|
||||
scanob2.add_files()
|
||||
# it is perfectly ok, since we don't update collection, but just added
|
||||
# same directory twice.
|
||||
self.assertEqual(len(ses.query(File).all()), 287)
|
||||
file_ob = scanob._files[2]
|
||||
file2_ob = scanob2._files[2]
|
||||
|
||||
# File objects are different
|
||||
self.assertTrue(file_ob.id != file2_ob.id)
|
||||
|
||||
# While Image objects points to the same file
|
||||
self.assertTrue(file_ob.images[0].filename == \
|
||||
file2_ob.images[0].filename)
|
||||
|
||||
# they are different objects
|
||||
self.assertTrue(file_ob.images[0].id != file2_ob.images[0].id)
|
||||
|
||||
ses.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.chdir(os.path.join(os.path.abspath(os.path.dirname(__file__)), "../"))
|
||||
|
||||
Reference in New Issue
Block a user