Bläddra i källkod

add more testing

this time we add testing for the config module
oz123 11 år sedan
förälder
incheckning
793963ccc6
2 ändrade filer med 25 tillägg och 3 borttagningar
  1. 23 2
      pwman/tests/db_tests.py
  2. 2 1
      pwman/tests/test_pwman.py

+ 23 - 2
pwman/tests/db_tests.py

@@ -47,6 +47,11 @@ class SetupTester(object):
         if os.path.exists(config.get_value('Database', 'filename')):
             os.remove(config.get_value('Database', 'filename'))
 
+        if os.path.exists(os.path.join(os.path.dirname(__file__),
+                                       'testing_config')):
+            os.remove(os.path.join(os.path.dirname(__file__),
+                                   'testing_config'))
+
     def create(self):
         dbver = 0.4
         dbtype = config.get_value("Database", "type")
@@ -160,8 +165,6 @@ class CLITests(unittest.TestCase):
         # This will pass only when running all the tests than ...
         self.assertEqual(len(rows), 2)
 
-    #TODO: implement a test for get_ids
-
     def test_get_ids(self):
         #used by do_cp or do_open
         self.assertEqual([1], self.tester.cli.get_ids('1'))
@@ -170,3 +173,21 @@ class CLITests(unittest.TestCase):
         self.assertListEqual([], self.tester.cli.get_ids('5x-1'))
         self.assertListEqual([], self.tester.cli.get_ids('5x'))
         self.assertListEqual([], self.tester.cli.get_ids('5\\'))
+
+
+class ConfigTest(unittest.TestCase):
+
+    def setUp(self):
+        "test that the right db instance was created"
+        dbver = 0.4
+        self.dbtype = config.get_value("Database", "type")
+        self.db = pwman.data.factory.create(self.dbtype, dbver)
+        self.tester = SetupTester()
+        self.tester.create()
+
+    def test_config_write(self):
+        config.save(os.path.join(os.path.dirname(__file__), 'testing_config'))
+    def test_config_write_with_none(self):
+        config._file = os.path.join(os.path.dirname(__file__), 'testing_config')
+        config.save()
+

+ 2 - 1
pwman/tests/test_pwman.py

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