Przeglądaj źródła

Drop old do_new and replace with a new method

oz123 10 lat temu
rodzic
commit
d14f98eb89
5 zmienionych plików z 13 dodań i 47 usunięć
  1. 1 0
      Makefile
  2. 4 3
      pwman/data/drivers/sqlite.py
  3. 6 0
      pwman/tests/test_base_ui.py
  4. 0 42
      pwman/ui/base.py
  5. 2 2
      pwman/ui/baseui.py

+ 1 - 0
Makefile

@@ -14,6 +14,7 @@ help:
 clean: clean-build clean-pyc
 	rm -fr htmlcov/
 	rm -f test.db
+	rm -f pwman/tests/test-baseui.pwman.db
 
 clean-build:
 	rm -fr build/

+ 4 - 3
pwman/data/drivers/sqlite.py

@@ -482,7 +482,8 @@ class SQLite(SQLiteDatabaseNewForm):
         tagids = [str(id[0]) for id in tagids]
         self._cur.execute(sql, (tagids))
         tags = self._cur.fetchall()
-        return tags
+        for t in tags:
+            yield t[0]
 
     def getnodes(self, ids):
         """
@@ -493,8 +494,8 @@ class SQLite(SQLiteDatabaseNewForm):
         nodes = self._cur.fetchall()
         nodes_w_tags = []
         for node in nodes:
-            tags = self._get_node_tags(node)
-            nodes_w_tags.append(list(node) + [list(tags)])
+            tags = list(self._get_node_tags(node))
+            nodes_w_tags.append(list(node) + tags)
 
         return nodes_w_tags
 

+ 6 - 0
pwman/tests/test_base_ui.py

@@ -57,6 +57,12 @@ class TestBaseUI(unittest.TestCase):
         nodeid = self.tester.cli._db.listnodes()
         self.assertListEqual([1], nodeid)
         nodes = self.tester.cli._db.getnodes(nodeid)
+        ce = CryptoEngine.get()
+        user = ce.decrypt(nodes[0][1])
+        self.assertTrue(user, 'alice')
+        tags = nodes[0][5:]
+        for idx, t in enumerate(['foo', 'bar', 'baz']):
+            self.assertTrue(t, tags[idx])
 
 
 if __name__ == '__main__':

+ 0 - 42
pwman/ui/base.py

@@ -489,48 +489,6 @@ class BaseCommands(BaseUI, HelpUI):
         except Exception as e:
             self.error(e)
 
-    def do_new(self, args):
-        """
-        can override default config settings the following way:
-        Pwman3 0.2.1 (c) visit: http://github.com/pwman3/pwman3
-        pwman> n {'leetify':False, 'numerics':True, 'special_chars':True}
-        Password (Blank to generate):
-        """
-        errmsg = ("could not parse config override, please input some"
-                  " kind of dictionary, e.g.: n {'leetify':False, "
-                  " numerics':True, 'special_chars':True}")
-        try:
-            username = self.get_username()
-            if args:
-                try:
-                    args = ast.literal_eval(args)
-                except Exception:
-                    raise Exception(errmsg)
-                if not isinstance(args, dict):
-                    raise Exception(errmsg)
-                password = self.get_password(argsgiven=1, **args)
-            else:
-                numerics, leet, s_chars = get_pass_conf(self.config)
-                password = self.get_password(argsgiven=0,
-                                             numerics=numerics,
-                                             leetify=leet,
-                                             special_signs=s_chars)
-            url = self.get_url()
-            notes = self.get_notes()
-            node = NewNode()
-            node.username = username
-            node.password = password
-            node.url = url
-            node.notes = notes
-            # node = NewNode(username, password, url, notes)
-            node.tags = self.get_tags()
-            self._db.addnodes([node])
-            print ("Password ID: %d" % (node._id))
-            # when done with node erase it
-            zerome(password)
-        except Exception as e:
-            self.error(e)
-
     def do_print(self, arg):
         for i in self.get_ids(arg):
             try:

+ 2 - 2
pwman/ui/baseui.py

@@ -84,7 +84,7 @@ class BaseCommands(HelpUI):
         Tags are simply return as a list
         """
         # TODO: add method to read tags from db, so they
-        # could bn used for tab completer
+        # could be used for tab completer
         print("Tags: ", end="")
         sys.stdout.flush()
         taglist = sys.stdin.readline()
@@ -129,7 +129,7 @@ class BaseCommands(HelpUI):
             p = sys.stdin.readline().rstrip()
         return p
 
-    def do_newn(self, args):
+    def do_new(self, args):
         node = {}
         node['username'] = self._get_input("Username: ")
         node['password'] = self._get_secret()