bricks@414: # Copyright (C) 2010 by Intevation GmbH bricks@414: # Authors: bricks@414: # Bjoern Ricks bricks@414: # bricks@414: # This program is free software under the GPL (>=v2) bricks@414: # Read the file COPYING coming with the software for details. bricks@414: bricks@414: """Tests for treepkg.info.data""" bricks@414: bricks@414: import unittest bricks@414: import os.path bricks@414: import sys bricks@414: bricks@414: test_dir = os.path.dirname(__file__) bricks@414: sys.path.append(os.path.join(test_dir, os.pardir)) bricks@414: bricks@414: from treepkg.info.data import Package bricks@414: from treepkg.info.data import CacheDb bricks@414: from filesupport import FileTestMixin bricks@414: bricks@414: class TestCacheDb(unittest.TestCase, FileTestMixin): bricks@414: bricks@414: def test_cache_db(self): bricks@414: tmpdir = self.create_test_specific_temp_dir() bricks@414: package = Package("/tmp/abc/abc_0.1_i386.deb", "abc", bricks@414: "abc_0.1_i386.deb", "/source/abc/abc_0.1_i386.deb", bricks@414: "binary-i386", "1234567") bricks@414: # tmpfile = self.create_temp_file("cachedb1", "abc") bricks@414: # with self.assertRaises(Exception): bricks@414: # db = CacheDb(tmpfile) bricks@414: bricks@414: dbfile = os.path.join(tmpdir, "cachedb2") bricks@414: db = CacheDb(dbfile) bricks@416: # insert bricks@416: filename = package.filename bricks@414: db.add_package(package) bricks@416: package = db.get_package(filename) bricks@416: self.assertEquals("1234567", package.md5sum) bricks@416: # update bricks@416: package.md5sum = "01234567" bricks@416: db.add_package(package) bricks@416: package = db.get_package(filename) bricks@416: self.assertEquals("01234567", package.md5sum) bricks@414: bricks@416: # test get_package bricks@414: package2 = db.get_package(package.filename) bricks@414: self.assertNotEquals(None, package2) bricks@414: self.assertEquals(package.filename, package2.filename) bricks@414: self.assertEquals(package.name, package2.name) bricks@414: self.assertEquals(package.sourcepath, package2.sourcepath) bricks@414: self.assertEquals(package.arch, package2.arch) bricks@414: self.assertEquals(package.md5sum, package2.md5sum) bricks@414: bricks@414: package3 = Package("/tmp/foo/foo_0.2.i386.deb", "foo", bricks@416: "foo_0.2_i386.deb", "/tmp/source/foo/foo_0.2.i386.deb", bricks@414: "binary-i386", "987654321") bricks@416: package4 = Package("/tmp/john/doe_0.3.i386.deb", "john", bricks@416: "doe_0.3.i386.deb", "/tmp/source/john/doe_0.3.i386.deb", bricks@416: "binary-i386", "5671234") bricks@414: db.add_package(package3) bricks@416: db.add_package(package4) bricks@416: bricks@416: # test get_old_packages bricks@414: oldpackages = db.get_old_packages([package.filename]) bricks@416: self.assertEquals(2, len(oldpackages)) bricks@414: packages = db.get_packages() bricks@416: self.assertEquals(3, len(packages)) bricks@416: db.remove_packages(oldpackages) bricks@414: packages = db.get_packages() bricks@414: self.assertEquals(1, len(packages)) bricks@414: bricks@414: if __name__ == '__main__': bricks@414: unittest.main() bricks@414: