Jelajahi Sumber

Add do_export and tests

oz123 10 tahun lalu
induk
melakukan
9ddccfe560
2 mengubah file dengan 15 tambahan dan 5 penghapusan
  1. 7 0
      pwman/tests/test_base_ui.py
  2. 8 5
      pwman/ui/baseui.py

+ 7 - 0
pwman/tests/test_base_ui.py

@@ -80,6 +80,13 @@ class TestBaseUI(unittest.TestCase):
         sys.stdout = self.saved_stdout
         self.output.getvalue()
 
+    def test_3_do_export(self):
+        self.tester.cli.do_export("{'filename':'foo.csv'}")
+        with open('foo.csv') as f:
+            l = f.readlines()
+
+        self.assertIn('alice;example.com;secret;some notes;foo,bar,baz', l[1])
+
 if __name__ == '__main__':
 
     ce = CryptoEngine.get()

+ 8 - 5
pwman/ui/baseui.py

@@ -79,12 +79,15 @@ class BaseCommands(HelpUI):
             writer = csv.writer(csvfile, delimiter=delim)
             writer.writerow(['Username', 'URL', 'Password', 'Notes',
                              'Tags'])
-            for n in nodes:
+            for node in nodes:
+                n = Node.from_encrypted_entries(node[1], node[2], node[3],
+                                                node[4],
+                                                node[5:])
                 tags = n.tags
-                tags = filter(None, tags)
-                tags = ','.join(t.strip() for t in tags)
-                writer.writerow([n.username, n.url, n.password, n.notes,
-                                 tags])
+                tags = ','.join(t.strip().decode() for t in tags)
+                r = list(map(bytes.decode, [n.username, n.url, n.password,
+                                            n.notes]))
+                writer.writerow(r + [tags])
 
         print("Successfuly exported database to {}".format(
             os.path.join(os.getcwd(), filename)))