diff options
| author | Todd Zullinger <tmzullinger@users.sourceforge.net> | 2007-07-31 20:42:54 +0000 |
|---|---|---|
| committer | Todd Zullinger <tmzullinger@users.sourceforge.net> | 2007-07-31 20:42:54 +0000 |
| commit | 6dda4b59bb0f788da38823a035f28d4c515a38be (patch) | |
| tree | 16f02c91b9efa543e3f4daab4b1bbcf3d88859f6 /bindings/python/tests | |
| parent | bd2fc5d392af67e46ee0fe8bf31b4f9e457f2da3 (diff) | |
| download | libgpod-6dda4b59bb0f788da38823a035f28d4c515a38be.tar.gz libgpod-6dda4b59bb0f788da38823a035f28d4c515a38be.tar.xz libgpod-6dda4b59bb0f788da38823a035f28d4c515a38be.zip | |
merge changes from the bug-1723660 branch
git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@1662 f01d2545-417e-4e96-918e-98f8d0dbbcb6
Diffstat (limited to 'bindings/python/tests')
| -rw-r--r-- | bindings/python/tests/resources/tiny.png | bin | 0 -> 155 bytes | |||
| -rw-r--r-- | bindings/python/tests/tests.py | 104 |
2 files changed, 104 insertions, 0 deletions
diff --git a/bindings/python/tests/resources/tiny.png b/bindings/python/tests/resources/tiny.png Binary files differnew file mode 100644 index 0000000..0b34c35 --- /dev/null +++ b/bindings/python/tests/resources/tiny.png diff --git a/bindings/python/tests/tests.py b/bindings/python/tests/tests.py index bdae7cb..09c89bf 100644 --- a/bindings/python/tests/tests.py +++ b/bindings/python/tests/tests.py @@ -66,5 +66,109 @@ class TestiPodFunctions(unittest.TestCase): def testVersion(self): self.assertEqual(type(gpod.version_info), types.TupleType) + +class TestPhotoDatabase(unittest.TestCase): + def setUp(self): + self.mp = tempfile.mkdtemp() + control_dir = os.path.join(self.mp,'iPod_Control') + photo_dir = os.path.join(control_dir, 'Photos') + shutil.copytree('resources', + control_dir) + os.mkdir(photo_dir) + self.db = gpod.PhotoDatabase(self.mp) + gpod.itdb_device_set_sysinfo (self.db._itdb.device, "ModelNumStr", "MA450"); + + def tearDown(self): + shutil.rmtree(self.mp) + + def testClose(self): + self.db.close() + + def testAddPhotoAlbum(self): + """ Test adding 5 photo albums to the database """ + for i in range(0, 5): + count = len(self.db.PhotoAlbums) + album = self.db.new_PhotoAlbum(title="Test %s" % i) + self.failUnless(len(self.db.PhotoAlbums) == (count + 1)) + + def testAddRemovePhotoAlbum(self): + """ Test removing all albums but "Photo Library" """ + self.testAddPhotoAlbum() + pas = [x for x in self.db.PhotoAlbums if x.name != "Photo Library"] + for pa in pas: + self.db.remove(pa) + self.assertEqual(len(self.db.PhotoAlbums), 1) + + def testRenamePhotoAlbum(self): + bad = [] + good = [] + + self.testAddPhotoAlbum() + pas = [x for x in self.db.PhotoAlbums if x.name != "Photo Library"] + for pa in pas: + bad.append(pa.name) + pa.name = "%s (renamed)" % pa.name + good.append(pa.name) + + pas = [x for x in self.db.PhotoAlbums if x.name != "Photo Library"] + for pa in pas: + self.failUnless(pa.name in bad) + self.failUnless(pa.name not in good) + + def testEnumeratePhotoAlbums(self): + [photo for photo in self.db.PhotoAlbums] + + def testAddPhoto(self): + photoname = os.path.join(self.mp, + 'iPod_Control', + 'tiny.png') + self.failUnless(os.path.exists(photoname)) + for n in range(1,5): + t = self.db.new_Photo(filename=photoname) + self.assertEqual(len(self.db), n) + + def testAddPhotoToAlbum(self): + self.testAddPhoto() + pa = self.db.new_PhotoAlbum(title="Add To Album Test") + count = len(pa) + for p in self.db.PhotoAlbums[0]: + pa.add(p) + self.assertEqual(len(pa), len(self.db.PhotoAlbums[0])) + self.failUnless(len(pa) > count) + + def testRemovePhotoFromAlbum(self): + self.testAddPhotoToAlbum() + pa = self.db.PhotoAlbums[1] + for p in pa[:]: + pa.remove(p) + # make sure we didn't delete the photo + self.failUnless(len(self.db.PhotoAlbums[0]) > 0) + # but that we did remove them from album + self.assertEqual(len(pa), 0) + + def testAddRemovePhoto(self): + self.testAddPhoto() + self.failUnless(len(self.db) > 0) + for photo in self.db.PhotoAlbums[0][:]: + self.db.remove(photo) + self.assertEqual(len(self.db), 0) + + def testAddCountPhotos(self): + count = len(self.db) + self.testAddPhoto() + self.failUnless(len(self.db) > count) + + def testEnumeratePhotoAlbums(self): + [photo for photo in self.db.PhotoAlbums] + + def testEnumeratePhotos(self): + for album in self.db.PhotoAlbums: + [photo for photo in album] + + def testEnumeratePhotosThumbs(self): + for album in self.db.PhotoAlbums: + for photo in album: + [thumb for thumb in photo.thumbnails] + if __name__ == '__main__': unittest.main() |
