瀏覽代碼

Add remove nodes method

oz123 10 年之前
父節點
當前提交
8b123504ea
共有 3 個文件被更改,包括 13 次插入5 次删除
  1. 6 3
      pwman/data/drivers/sqlite.py
  2. 2 2
      pwman/tests/db_tests.py
  3. 5 0
      pwman/tests/test_sqlite.py

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

@@ -483,16 +483,19 @@ class SQLite(SQLiteDatabaseNewForm):
                "" % ','.join('%s=?' % k for k in list(kwargs)))
         self._cur.execute(sql, (list(kwargs.values()) + [nid]))
         if tags:
-            #  update all old node entries in lookup
-            #  create new entries
+            # update all old node entries in lookup
+            # create new entries
             # clean all old tags
             sql_clean = "DELETE FROM LOOKUP WHERE NODEID=?"
             self._cur.execute(sql_clean, str(nid))
-            # TODO, update tags lookup
             self._setnodetags(nid, tags)
 
         self._con.commit()
 
+    def removenodes(self, nids):
+        sql_rm = "delete from node where id in (%s)" % ','.join('?'*len(nids))
+        self._cur.execute(sql_rm, (nids))
+
     def _clean_orphands(self):
         clean = ("delete from tag where not exists "
                  "(select 'x' from lookup l where l.tagid = tag.id)")

+ 2 - 2
pwman/tests/db_tests.py

@@ -211,10 +211,10 @@ class CLITests(unittest.TestCase):
         password = self.tester.cli.get_password(None, leetify=True,
                                                 reader=lambda x: u'HAtman')
         # python3 compatability
-        try:
+        if sys.version_info.major < 3:
             self.assertRegexpMatches(password, ("(H|h)?(A|a|4)?(T|t|\+)?(m|M|\|"
                                                 "\/\|)?(A|a|4)?(N|n|\|\\|)?"))
-        except AttributeError:
+        else:
             self.assertRegex(password, ("(H|h)?(A|a|4)?(T|t|\+)?(m|M|\|"
                                         "\/\|)?(A|a|4)?(N|n|\|\\|)?"))
 

+ 5 - 0
pwman/tests/test_sqlite.py

@@ -139,6 +139,11 @@ class TestSQLite(unittest.TestCase):
         tags = self.db.listtags()
         self.assertEqual(4, len(tags))
 
+    def test_a11_test_rmnodes(self):
+        self.db.removenodes([1, 2])
+        rv = self.db._cur.execute("select * from node").fetchall()
+        self.assertListEqual(rv, [])
+
     def tearDown(self):
         self.db.close()