Browse Source

100% test cover for sqlite driver

oz123 10 năm trước cách đây
mục cha
commit
8348935eb7

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

@@ -29,6 +29,7 @@ import sqlite3 as sqlite
 import pwman.util.config as config
 import pwman.util.config as config
 import itertools
 import itertools
 
 
+
 def check_db_version():
 def check_db_version():
     """
     """
     check the data base version query the right table
     check the data base version query the right table
@@ -208,7 +209,8 @@ class SQLiteDatabaseNewForm(Database):
                         " TAGS.ID WHERE TAGS.DATA LIKE ? ")
                         " TAGS.ID WHERE TAGS.DATA LIKE ? ")
                 # this is correct if tags are ciphertext
                 # this is correct if tags are ciphertext
                 p = t._name.strip()
                 p = t._name.strip()
-                # this is wrong, it will work when tags are stored as plain text
+                # this is wrong, it will work when tags are stored as plain
+                # text
                 # p = t.name.strip()
                 # p = t.name.strip()
                 p = '%'+p+'%'
                 p = '%'+p+'%'
                 params = [p]
                 params = [p]
@@ -266,8 +268,9 @@ class SQLiteDatabaseNewForm(Database):
                     self._cur.execute(sql, [tag])
                     self._cur.execute(sql, [tag])
                 else:
                 else:
                     self._cur.execute(sql, [tag._name+'%'])
                     self._cur.execute(sql, [tag._name+'%'])
+
                 values = self._cur.fetchall()
                 values = self._cur.fetchall()
-                if values:
+                if values:  # tags already exist in the database
                     ids.extend(list(itertools.chain(*values)))
                     ids.extend(list(itertools.chain(*values)))
                 else:
                 else:
                     self._create_tag(tag)
                     self._create_tag(tag)

+ 17 - 1
pwman/tests/db_tests.py

@@ -20,7 +20,7 @@
 from pwman.data.nodes import NewNode
 from pwman.data.nodes import NewNode
 from pwman.data.tags import TagNew
 from pwman.data.tags import TagNew
 from pwman.data import factory
 from pwman.data import factory
-from pwman.data.drivers.sqlite import DatabaseException
+from pwman.data.drivers.sqlite import DatabaseException, SQLiteDatabaseNewForm
 from pwman.util import config
 from pwman.util import config
 from pwman.util.generator import leetlist
 from pwman.util.generator import leetlist
 from pwman.util.crypto import CryptoEngine, CryptoBadKeyException
 from pwman.util.crypto import CryptoEngine, CryptoBadKeyException
@@ -167,6 +167,9 @@ class DBTests(unittest.TestCase):
         self.db.open()
         self.db.open()
         self.db.addnodes([node])
         self.db.addnodes([node])
 
 
+    def test_sqlite_init(self):
+        db = SQLiteDatabaseNewForm("test")
+        self.assertEquals("test", db._filename)
 
 
 class TestDBFalseConfig(unittest.TestCase):
 class TestDBFalseConfig(unittest.TestCase):
 
 
@@ -271,6 +274,19 @@ class CLITests(unittest.TestCase):
         # This will pass only when running all the tests then ...
         # This will pass only when running all the tests then ...
         self.assertEqual(len(rows), 2)
         self.assertEqual(len(rows), 2)
 
 
+        node = NewNode()
+        node.username = 'alice'
+        node.password = 'dough!'
+        node.url = 'example.com'
+        node.notes = 'somenotes'
+        node.tags = 'lorem ipsum'
+
+        tags = self.tester.cli.get_tags(reader=lambda: u'looking glass')
+        node.tags = tags
+        self.tester.cli._db.addnodes([node])
+
+
+
     def test_get_ids(self):
     def test_get_ids(self):
         # used by do_cp or do_open,
         # used by do_cp or do_open,
         # this spits many time could not understand your input
         # this spits many time could not understand your input

+ 1 - 1
pwman/util/callback.py

@@ -52,7 +52,7 @@ class Callback(object):  # pragma: no cover
         pass
         pass
 
 
 
 
-class CLICallback(Callback):
+class CLICallback(Callback):  # pragma: no cover
     def getinput(self, question):
     def getinput(self, question):
         return raw_input(question)
         return raw_input(question)