|
@@ -25,11 +25,14 @@ import sys
|
|
|
from pwman.data import factory
|
|
|
from pwman.data.database import DatabaseException
|
|
|
from pwman.data.drivers.sqlite import SQLite
|
|
|
-from pwman.data.drivers.postgresql import PostgresqlDatabase
|
|
|
from pwman.data.database import __DB_FORMAT__
|
|
|
from .test_tools import (SetupTester)
|
|
|
-
|
|
|
-db = ".".join(("pwman","test", sys.version.split(" " ,1)[0], "db"))
|
|
|
+try:
|
|
|
+ from pwman.data.drivers.postgresql import PostgresqlDatabase
|
|
|
+ has_psycopg = True
|
|
|
+except ImportError:
|
|
|
+ has_psycopg = False
|
|
|
+db = ".".join(("pwman", "test", sys.version.split(" ", 1)[0], "db"))
|
|
|
testdb = os.path.abspath(os.path.join(os.path.dirname(__file__), db))
|
|
|
|
|
|
_saveconfig = False
|
|
@@ -49,7 +52,8 @@ class TestFactory(unittest.TestCase):
|
|
|
self.tester.create()
|
|
|
|
|
|
def test_factory_check_db_ver(self):
|
|
|
- self.assertEqual(factory.check_db_version('sqlite://'+testdb), u"'0.6'")
|
|
|
+ self.assertEqual(
|
|
|
+ factory.check_db_version('sqlite://'+testdb), u"'0.6'")
|
|
|
|
|
|
@unittest.skip("not supported at the moment")
|
|
|
def test_factory_check_db_file(self):
|
|
@@ -67,21 +71,26 @@ class TestFactory(unittest.TestCase):
|
|
|
db.close()
|
|
|
os.unlink(fn)
|
|
|
self.assertIsInstance(db, SQLite)
|
|
|
- self.assertRaises(DatabaseException, factory.createdb, *('UNKNOWN',
|
|
|
- __DB_FORMAT__))
|
|
|
+ self.assertRaises(DatabaseException, factory.createdb,
|
|
|
+ *('UNKNOWN', __DB_FORMAT__))
|
|
|
|
|
|
def test_factory_createdb(self):
|
|
|
db = factory.createdb("sqlite:///test.db", 0.6)
|
|
|
self.assertIsInstance(db, SQLite)
|
|
|
del db
|
|
|
- db = factory.createdb("postgresql:///pwman", 0.6)
|
|
|
- self.assertIsInstance(db, PostgresqlDatabase)
|
|
|
- del db
|
|
|
db = factory.createdb("sqlite:///test.db", 0.7)
|
|
|
self.assertIsInstance(db, SQLite)
|
|
|
del db
|
|
|
+
|
|
|
+ @unittest.skipUnless(has_psycopg, "requires psycopg")
|
|
|
+ def test_factory_createdb_postgresql(self):
|
|
|
+ db = factory.createdb("postgresql:///pwman", 0.6)
|
|
|
+ self.assertIsInstance(db, PostgresqlDatabase)
|
|
|
+ del db
|
|
|
db = factory.createdb("postgresql:///pwman", 0.7)
|
|
|
self.assertIsInstance(db, PostgresqlDatabase)
|
|
|
+ del db
|
|
|
+
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
# make sure we use local pwman
|