Ver código fonte

add testing for getting tags

oz123 11 anos atrás
pai
commit
75ae633590
2 arquivos alterados com 10 adições e 4 exclusões
  1. 7 2
      pwman/tests/db_tests.py
  2. 3 2
      pwman/ui/cli.py

+ 7 - 2
pwman/tests/db_tests.py

@@ -18,7 +18,7 @@ else:
 import pwman.util.config as config
 import pwman.data.factory
 from pwman.data.nodes import NewNode
-from pwman.data.tags import Tag
+from pwman.data.tags import Tag, TagNew
 from pwman.util.crypto import CryptoEngine
 from pwman import which, default_config
 import unittest
@@ -132,4 +132,9 @@ class CLITests(unittest.TestCase):
         self.assertEqual(notes, 'test 123\n test 456')
 
     def test_get_tags(self):
-        pass
+        tags = self.tester.cli.get_tags(reader=lambda: 'looking glass')
+        for t in tags:
+            self.assertIsInstance(t, TagNew)
+
+        for t, n in zip(tags, 'looking glass'.split()):
+            self.assertEqual(t.name.strip(), n)

+ 3 - 2
pwman/ui/cli.py

@@ -699,7 +699,7 @@ class BaseCommands(PwmanCliOld):
         t = self._tags(enc)
         print '\n'.join(t)
 
-    def get_tags(self, default=None):
+    def get_tags(self, default=None, reader=raw_input):
         """read tags from user"""
         defaultstr = ''
         if default:
@@ -728,7 +728,8 @@ class BaseCommands(PwmanCliOld):
                     else:
                         count += 1
 
-        taglist = tools.getinput("Tags: ", defaultstr, completer=complete)
+        taglist = tools.getinput("Tags: ", defaultstr, completer=complete,
+                                 reader=reader)
         tagstrings = taglist.split()
         tags = [TagN(tn) for tn in tagstrings]