Sfoglia il codice sorgente

Add some more testing for the factory module

oz123 10 anni fa
parent
commit
3d4f994271
2 ha cambiato i file con 14 aggiunte e 2 eliminazioni
  1. 2 2
      pwman/data/factory.py
  2. 12 0
      pwman/tests/db_tests.py

+ 2 - 2
pwman/data/factory.py

@@ -59,13 +59,13 @@ def create(dbtype, version=None, filename=None):
             db = sqlite.SQLiteDatabaseNewForm()
         else:
             db = None
-    elif dbtype == "Postgresql":
+    elif dbtype == "Postgresql":  # pragma: no cover
         try:
             from pwman.data.drivers import postgresql
             db = postgresql.PostgresqlDatabase()
         except ImportError:
             raise DatabaseException("python-pygresql not installed")
-    elif dbtype == "MySQL":
+    elif dbtype == "MySQL":  # pragma: no cover
         try:
             from pwman.data.drivers import mysql
             db = mysql.MySQLDatabase()

+ 12 - 0
pwman/tests/db_tests.py

@@ -362,11 +362,23 @@ class CLITests(unittest.TestCase):
         self.assertTrue(self.tester.cli.do_exit(''))
 
 
+class FakeSqlite(object):
+
+    def check_db_version(self):
+        return ""
+
+
 class FactoryTest(unittest.TestCase):
 
     def test_factory_check_db_ver(self):
         self.assertEquals(factory.check_db_version('SQLite'), 0.5)
 
+    def test_factory_check_db_file(self):
+        orig_sqlite = getattr(factory, 'sqlite')
+        factory.sqlite = FakeSqlite()
+        self.assertEquals(factory.check_db_version('SQLite'), 0.3)
+        factory.sqlite = orig_sqlite
+
 
 class ConfigTest(unittest.TestCase):