diff --git a/src/pisi/packagedb.py b/src/pisi/packagedb.py index 896fcc2a..eccc26b1 100644 --- a/src/pisi/packagedb.py +++ b/src/pisi/packagedb.py @@ -9,10 +9,16 @@ import bsddb.dbshelve as shelve import util -import config +from context import ctx -util.check_dir(config.db_dir()) -d = shelve.open(config.db_dir() + '/package.bdb') +util.check_dir(ctx.db_dir()) +d = shelve.open(ctx.db_dir() + '/package.bdb') + +def has_package(name): + return d.has_key(name) + +def get_package(name): + return d[name] def add_package(name, package_info): d[name] = package_info diff --git a/src/unittests/packagedbtests.py b/src/unittests/packagedbtests.py new file mode 100644 index 00000000..7276acf5 --- /dev/null +++ b/src/unittests/packagedbtests.py @@ -0,0 +1,22 @@ + +import unittest +import os + +from pisi import packagedb +from pisi import util +from pisi import context + +class PackageDBTestCase(unittest.TestCase): + def setUp(self): + self.ctx = context.Context("samples/popt/popt.pspec") + + def testAdd(self): + packagedb.add_package("testpackagedb", self.ctx.spec.packages[0]) + self.assert_(packagedb.has_package("testpackagedb")) + + def testRemove(self): + self.testAdd() + packagedb.remove_package("testpackagedb") + self.assert_(not packagedb.has_package("testpackagedb")) + +suite = unittest.makeSuite(PackageDBTestCase) diff --git a/src/unittests/run.py b/src/unittests/run.py index d8e4038b..a96b3d40 100755 --- a/src/unittests/run.py +++ b/src/unittests/run.py @@ -7,18 +7,21 @@ sys.path.append(".") runTestSuite = lambda(x): unittest.TextTestRunner(verbosity=2).run(x) def run_all(): + import specfiletests import contexttests import fetchertests import archivetests import installdbtests + import packagedbtests alltests = unittest.TestSuite(( specfiletests.suite, contexttests.suite, fetchertests.suite, archivetests.suite, - installdbtests.suite + installdbtests.suite, + packagedbtests, suite )) runTestSuite(alltests)