Jelajahi Sumber

Add some notes to test converter and crypto modules

oz123 10 tahun lalu
induk
melakukan
0f1e8bceeb
2 mengubah file dengan 27 tambahan dan 17 penghapusan
  1. 24 14
      pwman/tests/test_converter.py
  2. 3 3
      pwman/util/crypto.py

+ 24 - 14
pwman/tests/test_converter.py

@@ -326,28 +326,38 @@ class CreateTestDataBases(object):
         notes = 'some notes'
         node = node_factory(username, password, url, notes,
                             ['testing1', 'testing2'])
-        self.db.open()
-        self.db.addnodes([node])
+        self.db1.addnodes([node])
         idx_created = node._id
-        new_node = self.db.getnodes([idx_created])[0]
+        new_node = self.db1.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()
+                assert attr == getattr(new_node, key)
+        self.db1.close()
 
-    def run(self):
-        self.open_dbs()
-        # before add nodes to db1 we have to create an encryption key!
-        #enc = CryptoEngine.get(dbver=dbver)
-        #key = db.loadkey()
-        #if key is not None:
-        #enc.set_cryptedkey(key)
+    def add_nodes_to_db2(self):
+        username = 'tester'
+        password = 'Password'
+        url = 'example.org'
+        notes = 'some notes'
+        node = node_factory(username, password, url, notes,
+                            ['testing1', 'testing2'])
+        self.db2.addnodes([node])
+        idx_created = node._id
+        new_node = self.db2.getnodes([idx_created])[0]
 
+        for key, attr in {'password': password, 'username': username,
+                          'url': url, 'notes': notes}.iteritems():
+                assert attr == getattr(new_node, key)
+        self.db2.close()
 
-        #else:
-        #    self.get_user_password()
+    def run(self):
+        # before add nodes to db1 we have to create an encryption key!
+        # this is handeld by the open method
+        self.db1.open()
         self.add_nodes_to_db1()
+        self.db2.open()
+        self.add_nodes_to_db2()
 
 
 if __name__ == '__main__':

+ 3 - 3
pwman/util/crypto.py

@@ -471,11 +471,11 @@ class CryptoEngineOld(CryptoEngine):
         try:
             # old db version used to write stuff to db with
             # plaintext = cPickle.dumps(obj)
-            # TODO: completely remove this block, and convert
+            # DONE: completely remove this block, and convert
             # the DB to a completely plain text ...
-
+            # See the above CryptoEngine
             # This implies that the coversion from OLD DATABASE FORMAT has
-            # to plain strings too ...
+            # plain strings too ...
             return cPickle.loads(plaintext)
         except (TypeError, ValueError, cPickle.UnpicklingError, EOFError):
             return plaintext