Przeglądaj źródła

Add listtags method to new sqlite driver

oz123 10 lat temu
rodzic
commit
a160e87eea

+ 9 - 0
pwman/data/drivers/sqlite.py

@@ -379,6 +379,15 @@ class SQLite(SQLiteDatabaseNewForm):
             ids = self._cur.fetchall()
             return ids
 
+    def listtags(self):
+        self._clean_orphands()
+        get_tags = "select data from tag"
+        self._cur.execute(get_tags)
+        tags = self._cur.fetchall()
+        if tags:
+            return tags
+        return []
+
     def _create_tables(self):
         self._cur.execute("PRAGMA TABLE_INFO(NODE)")
         if self._cur.fetchone() is not None:

+ 7 - 2
pwman/tests/db_tests.py

@@ -210,8 +210,13 @@ class CLITests(unittest.TestCase):
     def test_leet_password(self):
         password = self.tester.cli.get_password(None, leetify=True,
                                                 reader=lambda x: u'HAtman')
-        self.assertRegexpMatches(password, ("(H|h)?(A|a|4)?(T|t|\+)?(m|M|\|"
-                                            "\/\|)?(A|a|4)?(N|n|\|\\|)?"))
+        # python3 compatability
+        try:
+            self.assertRegexpMatches(password, ("(H|h)?(A|a|4)?(T|t|\+)?(m|M|\|"
+                                                "\/\|)?(A|a|4)?(N|n|\|\\|)?"))
+        except AttributeError:
+            self.assertRegex(password, ("(H|h)?(A|a|4)?(T|t|\+)?(m|M|\|"
+                                        "\/\|)?(A|a|4)?(N|n|\|\\|)?"))
 
     def test_get_url(self):
         url = self.tester.cli.get_url(reader=lambda: u'example.com')

+ 4 - 0
pwman/tests/test_sqlite.py

@@ -135,6 +135,10 @@ class TestSQLite(unittest.TestCase):
             else:
                 self.assertNotIn(baz_encrypted, data[0].decode())
 
+    def test_a10_test_listtags(self):
+        tags = self.db.listtags()
+        self.assertEqual(4, len(tags))
+
     def tearDown(self):
         self.db.close()