소스 검색

Fix all failing tests

oz123 10 년 전
부모
커밋
d1a2d553d9
3개의 변경된 파일82개의 추가작업 그리고 90개의 파일을 삭제
  1. 6 7
      pwman/data/drivers/sqlite.py
  2. 70 70
      pwman/tests/db_tests.py
  3. 6 13
      pwman/tests/test_pwman.py

+ 6 - 7
pwman/data/drivers/sqlite.py

@@ -66,13 +66,12 @@ class SQLiteDatabaseNewForm(Database):
         self.dbformat = dbformat
 
     def _open(self):
-        #try:
-        print(self._filename)
-        self._con = sqlite.connect(self._filename)
-        self._cur = self._con.cursor()
-        self._checktables()
-        #except sqlite.DatabaseError as e:  # pragma: no cover
-        #    raise DatabaseException("SQLite: %s" % (e))
+        try:
+            self._con = sqlite.connect(self._filename)
+            self._cur = self._con.cursor()
+            self._checktables()
+        except sqlite.DatabaseError as e:  # pragma: no cover
+            raise DatabaseException("SQLite: %s" % (e))
 
     def close(self):
         self._cur.close()

+ 70 - 70
pwman/tests/db_tests.py

@@ -96,76 +96,76 @@ class DBTests(unittest.TestCase):
         # it will have a file name associated
         self.assertTrue(hasattr(self.db, '_filename'))
 
-   # def test_create_node(self):
-   #     "test that a node can be successfuly created"
-   #     # this method does not test do_new
-   #     # which is a UI method, rather we test
-   #     # _db.addnodes
-   #     username = 'tester'
-   #     password = 'Password'
-   #     url = 'example.org'
-   #     notes = 'some notes'
-   #     #node = NewNode(username, password, url, notes)
-   #     node = NewNode()
-   #     node.username = username
-   #     node.password = password
-   #     node.url = url
-   #     node.notes = notes
-   #     #node = NewNode(username, password, url, notes)
-   #     tags = [TagNew(tn) for tn in ['testing1', 'testing2']]
-   #     node.tags = tags
-   #     self.db.open()
-   #     self.db.addnodes([node])
-   #     idx_created = node._id
-   #     new_node = self.db.getnodes([idx_created])[0]
-
-   #     for key, attr in {'password': password, 'username': username,
-   #                       'url': url, 'notes': notes}.iteritems():
-   #         self.assertEquals(attr, getattr(new_node, key))
-   #     self.db.close()
-
-   # def test_tags(self):
-   #     enc = CryptoEngine.get()
-   #     got_tags = self.tester.cli._tags(enc)
-   #     self.assertEqual(2, len(got_tags))
-
-   # def test_change_pass(self):
-   #     enc = CryptoEngine.get()
-   #     enc._callback = DummyCallback2()
-   #     self.assertRaises(CryptoBadKeyException,
-   #                       self.tester.cli._db.changepassword)
-
-   # def test_db_change_pass(self):
-   #     "fuck yeah, we change the password and the new dummy works"
-   #     enc = CryptoEngine.get()
-   #     enc._callback = DummyCallback3()
-   #     self.tester.cli._db.changepassword()
-   #     self.tester.cli.do_forget('')
-   #     enc._callback = DummyCallback4()
-   #     self.tester.cli.do_ls('')
-
-   # def test_db_list_tags(self):
-   #     # tags are return as ecrypted strings
-   #     tags = self.tester.cli._db.listtags()
-   #     self.assertEqual(2, len(tags))
-   #     self.tester.cli.do_filter('testing1')
-   #     tags = self.tester.cli._db.listtags()
-   #     self.assertEqual(2, len(tags))
-   #     self.tester.cli.do_ls('')
-
-   # def test_db_remove_node(self):
-   #     node = self.tester.cli._db.getnodes([1])
-   #     self.tester.cli._db.removenodes(node)
-   #     # create the removed node again
-   #     node = NewNode()
-   #     node.username = 'tester'
-   #     node.password = 'Password'
-   #     node.url = 'example.org'
-   #     node.notes = 'some notes'
-   #     tags = [TagNew(tn) for tn in ['testing1', 'testing2']]
-   #     node.tags = tags
-   #     self.db.open()
-   #     self.db.addnodes([node])
+    def test_create_node(self):
+        "test that a node can be successfuly created"
+        # this method does not test do_new
+        # which is a UI method, rather we test
+        # _db.addnodes
+        username = 'tester'
+        password = 'Password'
+        url = 'example.org'
+        notes = 'some notes'
+        #node = NewNode(username, password, url, notes)
+        node = NewNode()
+        node.username = username
+        node.password = password
+        node.url = url
+        node.notes = notes
+        #node = NewNode(username, password, url, notes)
+        tags = [TagNew(tn) for tn in ['testing1', 'testing2']]
+        node.tags = tags
+        self.db.open()
+        self.db.addnodes([node])
+        idx_created = node._id
+        new_node = self.db.getnodes([idx_created])[0]
+
+        for key, attr in {'password': password, 'username': username,
+                          'url': url, 'notes': notes}.iteritems():
+            self.assertEquals(attr, getattr(new_node, key))
+        self.db.close()
+
+    def test_tags(self):
+        enc = CryptoEngine.get()
+        got_tags = self.tester.cli._tags(enc)
+        self.assertEqual(2, len(got_tags))
+
+    def test_change_pass(self):
+        enc = CryptoEngine.get()
+        enc._callback = DummyCallback2()
+        self.assertRaises(CryptoBadKeyException,
+                          self.tester.cli._db.changepassword)
+
+    def test_db_change_pass(self):
+        "fuck yeah, we change the password and the new dummy works"
+        enc = CryptoEngine.get()
+        enc._callback = DummyCallback3()
+        self.tester.cli._db.changepassword()
+        self.tester.cli.do_forget('')
+        enc._callback = DummyCallback4()
+        self.tester.cli.do_ls('')
+
+    def test_db_list_tags(self):
+        # tags are return as ecrypted strings
+        tags = self.tester.cli._db.listtags()
+        self.assertEqual(2, len(tags))
+        self.tester.cli.do_filter('testing1')
+        tags = self.tester.cli._db.listtags()
+        self.assertEqual(2, len(tags))
+        self.tester.cli.do_ls('')
+
+    def test_db_remove_node(self):
+        node = self.tester.cli._db.getnodes([1])
+        self.tester.cli._db.removenodes(node)
+        # create the removed node again
+        node = NewNode()
+        node.username = 'tester'
+        node.password = 'Password'
+        node.url = 'example.org'
+        node.notes = 'some notes'
+        tags = [TagNew(tn) for tn in ['testing1', 'testing2']]
+        node.tags = tags
+        self.db.open()
+        self.db.addnodes([node])
 
 
 class TestDBFalseConfig(unittest.TestCase):

+ 6 - 13
pwman/tests/test_pwman.py

@@ -38,23 +38,16 @@ sys.path.insert(0, os.getcwd())
 SetupTester().clean()
 
 
-class Dumb(unittest.TestCase):
-    def test_stupid(self):
-        os.system("df -h /")
-        self.assertTrue(True)
-
-
 def suite():
     loader = unittest.TestLoader()
     suite = unittest.TestSuite()
     suite.addTest(loader.loadTestsFromTestCase(DBTests))
-    #suite.addTest(loader.loadTestsFromTestCase(CryptoTest))
-    #suite.addTest(loader.loadTestsFromTestCase(CLITests))
-    #suite.addTest(loader.loadTestsFromTestCase(ConfigTest))
-    #suite.addTest(loader.loadTestsFromTestCase(FactoryTest))
-    #suite.addTest(loader.loadTestsFromTestCase(TestDBFalseConfig))
-    suite.addTest(loader.loadTestsFromTestCase(Dumb))
-    #suite.addTest(loader.loadTestsFromTestCase(Ferrum))
+    suite.addTest(loader.loadTestsFromTestCase(CryptoTest))
+    suite.addTest(loader.loadTestsFromTestCase(CLITests))
+    suite.addTest(loader.loadTestsFromTestCase(ConfigTest))
+    suite.addTest(loader.loadTestsFromTestCase(FactoryTest))
+    suite.addTest(loader.loadTestsFromTestCase(TestDBFalseConfig))
+    suite.addTest(loader.loadTestsFromTestCase(Ferrum))
     return suite
 
 if __name__ == '__main__':