def testRefreshDatabaseWithDeleteSource(self): (srcdir, mediadir, tmpdir) = self._setup_test_data() try: photoman._find_and_archive_photos(srcdir, mediadir, True, 'foo') # Re-run and delete source, this should not cause any # library files to be deleted photoman._find_and_archive_photos(srcdir, mediadir, True, 'foo') files = [ os.path.join(tmpdir, 'dest/media/photos/2012/07_July/gnexus 160.jpg'), os.path.join( tmpdir, 'dest/media/photos/2002/' + '10_October/105-0555_IMG.JPG'), os.path.join( tmpdir, 'dest/media/photos/2003/03_March/594-9436_IMG.JPG'), os.path.join(tmpdir, 'dest/media/photos/2006/03_March/IMG_1427.JPG'), os.path.join(tmpdir, 'dest/media/photos/2006/06_June/DSC09012.JPG') ] for filepath in files: self.assertTrue(os.path.isfile(filepath), 'Expect %s wasnt deleted' % filepath) finally: shutil.rmtree(tmpdir)
def testNewDatabase(self): (srcdir, mediadir, tmpdir) = self._setup_test_data() try: photoman._find_and_archive_photos(srcdir, mediadir, False, 'foo') files = [ os.path.join(tmpdir, 'dest/media/media.db'), os.path.join(tmpdir, 'dest/media/photos/2012/07_July/gnexus 160.jpg'), os.path.join( tmpdir, 'dest/media/photos/2002/' + '10_October/105-0555_IMG.JPG'), os.path.join( tmpdir, 'dest/media/photos/2003/03_March/594-9436_IMG.JPG'), os.path.join(tmpdir, 'dest/media/photos/2006/03_March/IMG_1427.JPG'), os.path.join(tmpdir, 'dest/media/photos/2006/06_June/DSC09012.JPG'), os.path.join(tmpdir, 'src/DSC09012.JPG'), os.path.join(tmpdir, 'src/IMG_1427.JPG'), os.path.join(tmpdir, 'src/594-9436_IMG.JPG'), os.path.join(tmpdir, 'src/105-0555_IMG.JPG'), os.path.join(tmpdir, 'src/foo/gnexus 160.jpg') ] for filepath in files: self.assertTrue(os.path.isfile(filepath), 'Expect %s exists' % filepath) finally: shutil.rmtree(tmpdir)
def test_query_all(self): (srcdir, mediadir, tmpdir) = self._setup_test_data() try: photoman._find_and_archive_photos(srcdir, mediadir, True, 'foo') rep = media_common.Repository() rep.open(mediadir) cur = rep.con.cursor() cur.execute(''' select id, archive_path FROM photos''') rows = 0 for row in cur: rows += 1 self.assertEquals(5, rows) cur = rep.con.cursor() ids = [1, 5] cur.execute( ' DELETE from photos where id in (' + ','.join('?' * len(ids)) + ')', ids) cur.execute(''' select id, archive_path FROM photos''') rows = 0 for row in cur: rows += 1 self.assertEquals(3, rows) rep.close() finally: shutil.rmtree(tmpdir)
def test_scan_missing(self): (srcdir, mediadir, tmpdir) = self._setup_test_data() try: rows = 0 photoman._find_and_archive_photos(srcdir, mediadir, True, 'foo') rep = media_common.Repository() rep.open(os.path.join(mediadir)) rows = self._get_row_count(rep) rep.close() os.remove( os.path.join(mediadir, 'photos/2012/07_July/gnexus 160.jpg')) photoman._scan_missing_photos(mediadir) rep = media_common.Repository() rep.open(os.path.join(mediadir)) self.assertEquals(rows - 1, self._get_row_count(rep)) cur = rep.con.cursor() filepath = os.path.join(mediadir, 'photos/2012/07_July/gnexus 160.jpg') rows = cur.execute( ''' select id FROM photos WHERE archive_path = ?''', [filepath]) self.assertEquals(None, rows.fetchone()) rep.close() finally: shutil.rmtree(tmpdir)
def testNewDatabase(self): (srcdir, mediadir, tmpdir) = self._setup_test_data() try: photoman._find_and_archive_photos(srcdir, mediadir, False, 'foo') files = [ os.path.join(tmpdir, 'dest/media/media.db'), os.path.join(tmpdir, 'dest/media/photos/2012/07_July/gnexus 160.jpg'), os.path.join(tmpdir, 'dest/media/photos/2002/' + '10_October/105-0555_IMG.JPG'), os.path.join(tmpdir, 'dest/media/photos/2003/03_March/594-9436_IMG.JPG'), os.path.join(tmpdir, 'dest/media/photos/2006/03_March/IMG_1427.JPG'), os.path.join(tmpdir, 'dest/media/photos/2006/06_June/DSC09012.JPG'), os.path.join(tmpdir, 'src/DSC09012.JPG'), os.path.join(tmpdir, 'src/IMG_1427.JPG'), os.path.join(tmpdir, 'src/594-9436_IMG.JPG'), os.path.join(tmpdir, 'src/105-0555_IMG.JPG'), os.path.join(tmpdir, 'src/foo/gnexus 160.jpg')] for filepath in files: self.assertTrue(os.path.isfile(filepath), 'Expect %s exists' % filepath) finally: shutil.rmtree(tmpdir)
def test_query_all(self): (srcdir, mediadir, tmpdir) = self._setup_test_data() try: photoman._find_and_archive_photos(srcdir, mediadir, True, 'foo') rep = media_common.Repository() rep.open(mediadir) cur = rep.con.cursor() cur.execute(''' select id, archive_path FROM photos''') rows = 0 for row in cur: rows += 1 self.assertEquals(5, rows) cur = rep.con.cursor() ids = [1, 5] cur.execute(' DELETE from photos where id in (' + ','.join('?'*len(ids)) + ')', ids) cur.execute(''' select id, archive_path FROM photos''') rows = 0 for row in cur: rows += 1 self.assertEquals(3, rows) rep.close() finally: shutil.rmtree(tmpdir)
def testDuplicateFiles(self): (srcdir, mediadir, tmpdir) = self._setup_test_data() try: photoman._find_and_archive_photos(srcdir, mediadir, True, 'foo') self._copy_test_images(srcdir, 'dup_') photoman._find_and_archive_photos(srcdir, mediadir, False, 'foo') #print 'testDuplicatefiles Result' #self._print_tree(tmpdir) finally: shutil.rmtree(tmpdir)
def testNewDatabaseDeleteSource(self): (srcdir, mediadir, tmpdir) = self._setup_test_data() try: photoman._find_and_archive_photos(srcdir, mediadir, True, 'foo') files = [ os.path.join(tmpdir, 'src/DSC09012.JPG'), os.path.join(tmpdir, 'src/IMG_1427.JPG'), os.path.join(tmpdir, 'src/594-9436_IMG.JPG'), os.path.join(tmpdir, 'src/105-0555_IMG.JPG'), os.path.join(tmpdir, 'src/gnexus 160.jpg')] for filepath in files: self.assertFalse(os.path.isfile(filepath), 'Expect %s is deleted' % filepath) finally: shutil.rmtree(tmpdir)
def testNewDatabaseDeleteSource(self): (srcdir, mediadir, tmpdir) = self._setup_test_data() try: photoman._find_and_archive_photos(srcdir, mediadir, True, 'foo') files = [ os.path.join(tmpdir, 'src/DSC09012.JPG'), os.path.join(tmpdir, 'src/IMG_1427.JPG'), os.path.join(tmpdir, 'src/594-9436_IMG.JPG'), os.path.join(tmpdir, 'src/105-0555_IMG.JPG'), os.path.join(tmpdir, 'src/gnexus 160.jpg') ] for filepath in files: self.assertFalse(os.path.isfile(filepath), 'Expect %s is deleted' % filepath) finally: shutil.rmtree(tmpdir)
def testRefreshDatabaseWithDeleteSource(self): (srcdir, mediadir, tmpdir) = self._setup_test_data() try: photoman._find_and_archive_photos(srcdir, mediadir, True, 'foo') # Re-run and delete source, this should not cause any # library files to be deleted photoman._find_and_archive_photos(srcdir, mediadir, True, 'foo') files = [ os.path.join(tmpdir, 'dest/media/photos/2012/07_July/gnexus 160.jpg'), os.path.join(tmpdir, 'dest/media/photos/2002/' + '10_October/105-0555_IMG.JPG'), os.path.join(tmpdir, 'dest/media/photos/2003/03_March/594-9436_IMG.JPG'), os.path.join(tmpdir, 'dest/media/photos/2006/03_March/IMG_1427.JPG'), os.path.join(tmpdir, 'dest/media/photos/2006/06_June/DSC09012.JPG')] for filepath in files: self.assertTrue(os.path.isfile(filepath), 'Expect %s wasnt deleted' % filepath) finally: shutil.rmtree(tmpdir)
def test_scan_missing(self): (srcdir, mediadir, tmpdir) = self._setup_test_data() try: rows = 0 photoman._find_and_archive_photos(srcdir, mediadir, True, 'foo') rep = media_common.Repository() rep.open(os.path.join(mediadir)) rows = self._get_row_count(rep) rep.close() os.remove(os.path.join(mediadir, 'photos/2012/07_July/gnexus 160.jpg')) photoman._scan_missing_photos(mediadir) rep = media_common.Repository() rep.open(os.path.join(mediadir)) self.assertEquals(rows - 1, self._get_row_count(rep)) cur = rep.con.cursor() filepath = os.path.join(mediadir, 'photos/2012/07_July/gnexus 160.jpg') rows = cur.execute(''' select id FROM photos WHERE archive_path = ?''', [filepath]) self.assertEquals(None, rows.fetchone()) rep.close() finally: shutil.rmtree(tmpdir)