Explorar o código

Add node to the new database format

oz123 %!s(int64=10) %!d(string=hai) anos
pai
achega
7a27c57afb
Modificáronse 2 ficheiros con 13 adicións e 1 borrados
  1. 7 1
      pwman/data/drivers/sqlite.py
  2. 6 0
      pwman/tests/test_sqlite.py

+ 7 - 1
pwman/data/drivers/sqlite.py

@@ -394,7 +394,7 @@ class SQLite(SQLiteDatabaseNewForm):
 
         # create a table to hold DB version info
         self._cur.execute("CREATE TABLE DBVERSION"
-                          "(DBVERSION TEXT NOT NULL DEFAULT '%s')" %
+                          "(DB VERSION TEXT NOT NULL DEFAULT '%s')" %
                           self.dbformat)
         self._cur.execute("INSERT INTO DBVERSION VALUES('%s')" %
                           self.dbformat)
@@ -415,3 +415,9 @@ class SQLite(SQLiteDatabaseNewForm):
         self._cur.execute("DELETE  FROM CRYPTO")
         self._cur.execute("INSERT INTO CRYPTO VALUES(?, ?)", [seed, digest])
         self._con.commit()
+
+    def add_node(self, node):
+        sql = ("INSERT INTO NODE(USER, PASSWORD, URL, NOTES)"
+               "VALUES(?, ?, ?, ?)")
+        self._cur.execute(sql, node)
+        self._con.commit()

+ 6 - 0
pwman/tests/test_sqlite.py

@@ -42,6 +42,12 @@ class TestSQLite(unittest.TestCase):
         f = self.db.fetch_crypto_info()
         self.assertListEqual([u'foo', u'bar'], list(f))
 
+    def test_3_add_node(self):
+        node = ("alice", "secret", "wonderland.com", "a really great place")
+        self.db.add_node(node)
+        rv = self.db._cur.execute("select * from node")
+        self.assertIn('alice', rv.fetchone())
+
     def tearDown(self):
         self.db.close()