Переглянути джерело

Add partial edit functionality

Still need to work on updating the tags ...
oz123 10 роки тому
батько
коміт
258345e139
2 змінених файлів з 15 додано та 0 видалено
  1. 7 0
      pwman/data/drivers/sqlite.py
  2. 8 0
      pwman/tests/test_sqlite.py

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

@@ -467,6 +467,13 @@ class SQLite(SQLiteDatabaseNewForm):
         nodes = self._cur.fetchall()
         return nodes
 
+    def editnode(self, id, **kwargs):
+        sql = ("UPDATE NODE SET %s WHERE ID = ? "
+               "" % ','.join('%s=?' % k for k in list(kwargs)))
+        self._cur.execute(sql, (list(kwargs.values()) + [id]))
+        self._con.commit()
+        # TODO, update tags lookup
+
     def close(self):
         self._cur.close()
         self._con.close()

+ 8 - 0
pwman/tests/test_sqlite.py

@@ -97,6 +97,14 @@ class TestSQLite(unittest.TestCase):
         nodes = self.db.getnodes([1, 2])
         self.assertEqual(len(nodes), 2)
 
+    def test_9_editnode(self):
+        # delibertly insert clear text into the database
+        node = {'user': 'transparent', 'password': 'notsecret'}
+        self.db.editnode(2, **node)
+        self.db._cur.execute('SELECT USER, PASSWORD FROM NODE WHERE ID=2')
+        rv = self.db._cur.fetchone()
+        self.assertEqual(rv, (u'transparent', u'notsecret'))
+
     def tearDown(self):
         self.db.close()