Selaa lähdekoodia

Add some more testing for tags

oz123 10 vuotta sitten
vanhempi
commit
4a61399b2f
2 muutettua tiedostoa jossa 13 lisäystä ja 3 poistoa
  1. 3 2
      pwman/data/drivers/sqlite.py
  2. 10 1
      pwman/tests/test_sqlite.py

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

@@ -427,8 +427,9 @@ class SQLite(SQLiteDatabaseNewForm):
     def _get_or_create_tag(self, tagcipher):
         sql_search = "SELECT ID FROM TAG WHERE DATA LIKE (?)"
         self._cur.execute(sql_search, ([tagcipher]))
-        if self._cur.fetchone():
-            return self._cur.lastrowid
+        rv = self._cur.fetchone()
+        if rv:
+            return rv[0]
         else:
             sql_insert = "INSERT INTO TAG(DATA) VALUES(?)"
             self._cur.execute(sql_insert, ([tagcipher]))

+ 10 - 1
pwman/tests/test_sqlite.py

@@ -57,8 +57,17 @@ class TestSQLite(unittest.TestCase):
         ce = CryptoEngine.get()
         res = rv.fetchone()
         self.assertIn(ce.encrypt(u'alice'), res[1])
+
+    def test_4_test_tags(self):
+        node = Node(clear_text=True,
+                    **{'username': u"alice", 'password': u"secret",
+                       'url': u"wonderland.com",
+                       'notes': u"a really great place",
+                       'tags': [u'foo', u'bar']})
+        ce = CryptoEngine.get()
         self.db._get_or_create_tag(node._tags[0])
-        self.db._get_or_create_tag(node._tags[0])
+        self.assertEqual(1, self.db._get_or_create_tag(node._tags[0]))
+        self.assertEqual(3, self.db._get_or_create_tag(ce.encrypt('baz')))
 
     def tearDown(self):
         self.db.close()