Procházet zdrojové kódy

Add factory testing

oz123 před 11 roky
rodič
revize
458c7aff1f
3 změnil soubory, kde provedl 19 přidání a 15 odebrání
  1. 10 13
      pwman/data/factory.py
  2. 7 1
      pwman/tests/db_tests.py
  3. 2 1
      pwman/tests/test_pwman.py

+ 10 - 13
pwman/data/factory.py

@@ -47,24 +47,21 @@ def create(type, version=None, filename=None):
     Create a Database instance.
     'type' can only be 'SQLite' at the moment
     """
-    if (type == "SQLite"):
-        try:
-            from pwman.data.drivers import sqlite
-            if version == 0.4 and filename:
-                db = sqlite.SQLiteDatabaseNewForm(filename)
-            elif version == 0.4:
-                db = sqlite.SQLiteDatabaseNewForm()
-            else:
-                db = sqlite.SQLiteDatabase()
-        except ImportError:
-            raise DatabaseException("python-sqlite not installed")
-    elif (type == "Postgresql"):
+    if type == "SQLite":
+        from pwman.data.drivers import sqlite
+        if version == 0.4 and filename:
+            db = sqlite.SQLiteDatabaseNewForm(filename)
+        elif version == 0.4:
+            db = sqlite.SQLiteDatabaseNewForm()
+        else:
+            db = sqlite.SQLiteDatabase()
+    elif type == "Postgresql":
         try:
             from pwman.data.drivers import postgresql
             db = postgresql.PostgresqlDatabase()
         except ImportError:
             raise DatabaseException("python-pygresql not installed")
-    elif (type == "MySQL"):
+    elif type == "MySQL":
         try:
             from pwman.data.drivers import mysql
             db = mysql.MySQLDatabase()

+ 7 - 1
pwman/tests/db_tests.py

@@ -40,7 +40,7 @@ from pwman import which, default_config
 from pwman.ui.cli import get_pass_conf
 from pwman.ui.tools import CMDLoop, CliMenuItem
 import unittest
-
+from pwman.data import factory
 _saveconfig = False
 
 default_config['Database'] = {'type': 'SQLite',
@@ -254,6 +254,12 @@ class CLITests(unittest.TestCase):
         self.assertTrue(self.tester.cli.do_exit(''))
 
 
+class FactoryTest(unittest.TestCase):
+
+    def test_factory_check_db_ver(self):
+        self.assertEquals(factory.check_db_version('SQLite'), u"'0.4'")
+
+
 class ConfigTest(unittest.TestCase):
 
     def setUp(self):

+ 2 - 1
pwman/tests/test_pwman.py

@@ -22,7 +22,7 @@
 import os
 import sys
 import unittest
-from db_tests import (DBTests, SetupTester, CLITests, ConfigTest)
+from db_tests import (DBTests, SetupTester, CLITests, ConfigTest, FactoryTest)
 from crypto_tests import CryptoTest
 
 # make sure we use local pwman
@@ -40,6 +40,7 @@ def suite():
     suite.addTest(loader.loadTestsFromTestCase(CryptoTest))
     suite.addTest(loader.loadTestsFromTestCase(CLITests))
     suite.addTest(loader.loadTestsFromTestCase(ConfigTest))
+    suite.addTest(loader.loadTestsFromTestCase(FactoryTest))
     return suite
 
 if __name__ == '__main__':