oz123 10 rokov pred
rodič
commit
dd828f00a3

+ 3 - 1
pwman/tests/test_base_ui.py

@@ -51,7 +51,7 @@ class TestBaseUI(unittest.TestCase):
     def test_do_new(self):
         sys.stdin = StringIO(("alice\nsecret\nexample.com\nsome notes"
                               "\nfoo bar baz"))
-        _node = self.tester.cli.do_newn('')
+        _node = self.tester.cli.do_new('')
         self.assertListEqual(['foo', 'bar', 'baz'], _node.tags)
         sys.stdin = sys.__stdin__
         nodeid = self.tester.cli._db.listnodes()
@@ -64,6 +64,8 @@ class TestBaseUI(unittest.TestCase):
         for idx, t in enumerate(['foo', 'bar', 'baz']):
             self.assertTrue(t, tags[idx])
 
+    def test_do_list(self):
+        self.tester.cli.do_list('')
 
 if __name__ == '__main__':
 

+ 2 - 0
pwman/tests/test_pwman.py

@@ -34,6 +34,7 @@ from .test_config import TestConfig
 from .test_sqlite import TestSQLite
 from .test_importer import TestImporter
 from .test_factory import TestFactory
+from .test_base_ui import TestBaseUI
 
 if 'win' not in sys.platform:
     from .test_complete_ui import (Ferrum, NEW_DB_PATH)
@@ -63,6 +64,7 @@ def suite():
     suite.addTest(loader.loadTestsFromTestCase(TestSQLite))
     suite.addTest(loader.loadTestsFromTestCase(TestImporter))
     suite.addTest(loader.loadTestsFromTestCase(TestFactory))
+    suite.addTest(loader.loadTestsFromTestCase(TestBaseUI))
     #if 'win' not in sys.platform:
     #    suite.addTest(loader.loadTestsFromTestCase(Ferrum))
     return suite

+ 0 - 1
pwman/ui/base.py

@@ -422,7 +422,6 @@ class BaseCommands(BaseUI, HelpUI):
         tags = [TagNew(tn) for tn in tagstrings]
         return tags
 
-
     def do_filter(self, args):
         tagstrings = args.split()
         try:

+ 14 - 5
pwman/ui/baseui.py

@@ -80,7 +80,8 @@ class BaseCommands(HelpUI):
 
     def _get_tags(self, default=None, reader=raw_input):
         """
-        Tags are simply return as a list
+        Read tags from user input.
+        Tags are simply returned as a list
         """
         # TODO: add method to read tags from db, so they
         # could be used for tab completer
@@ -103,11 +104,16 @@ class BaseCommands(HelpUI):
         cols -= 8
         return rows, cols
 
+    def _format_line(self, tag_pad, nid="ID", user="USER", url="URL",
+                     tags="TAGS"):
+        return ("{ID:<3} {USER:<{us}}{URL:<{ur}}{Tags:<{tg}}"
+                "".format(ID=nid, USER=user, URL=url, Tags=tags, us=12,
+                          ur=20, tg=tag_pad - 32))
+
     def _print_node_line(self, node, rows, cols):
         tagstring = ','.join([str(t) for t in node.tags])
-        fmt = ('{nid}. Username: {name:<{f}} URL: {url:<{f}} Tags: {tags:<{f}}'
-               ''.format(url=node.url + ',', name=node.username + ',', f=10,
-                         tags=tagstring, nid=node._id))
+        fmt = self._format_line(cols - 32, node._id, node.username, node.url,
+                                tagstring)
         formatted_entry = tools.typeset(fmt, Fore.YELLOW, False)
         print(formatted_entry)
 
@@ -126,6 +132,9 @@ class BaseCommands(HelpUI):
                 node[3],
                 node[4],
                 node[5:]))
+
+        head = self._format_line(cols-32)
+        print(tools.typeset(head, Fore.YELLOW, False))
         for idx, node in enumerate(_nodes_inst):
             node._id = idx + 1
             self._print_node_line(node, rows, cols)
@@ -139,7 +148,7 @@ class BaseCommands(HelpUI):
         return sys.stdin.readline()
 
     def _get_secret(self):
-        # TODO: enable old functionallity
+        # TODO: enable old functionallity, with password generator.
         if sys.stdin.isatty():
             p = getpass.getpass()
         else: