Преглед изворни кода

Add clean orphans to postgresql drivers

oz123 пре 10 година
родитељ
комит
3dad1f9575
3 измењених фајлова са 29 додато и 8 уклоњено
  1. 10 6
      .travis.yml
  2. 14 2
      pwman/data/drivers/postgresql.py
  3. 5 0
      pwman/tests/test_postgresql.py

+ 10 - 6
.travis.yml

@@ -2,17 +2,21 @@ language: python
 python:
 python:
   - 2.7
   - 2.7
   - 3.4 
   - 3.4 
+
+before_script:
+  - psql -c 'create database pwman;' -U postgres
+
 # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
 # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
 install: 
 install: 
-     - "pip install -r requirements.txt"
-     - "pip install coveralls"
-     - "pip install ."
+  - "pip install -r requirements.txt"
+  - "pip install coveralls"
+  - "pip install ."
 # command to run tests, e.g. python setup.py test
 # command to run tests, e.g. python setup.py test
 script:  
 script:  
-    coverage run --source=pwman setup.py test
+  coverage run --source=pwman setup.py test
     
     
-    #coverage run --omit="pwman/tests/*.py,pwman/ui/mac.py,pwman/ui/win.py,pwman/data/convertdb.py,pwman/data/nodes_multiple_approach.py,pwman/data/models.py,pwman/data/drivers/postgresql.py,pwman/data/drivers/mysql.py,pwman/exchange/importer.py,pwman/ui/base.py" --source=pwman setup.py test 
+#coverage run --omit="pwman/tests/*.py,pwman/ui/mac.py,pwman/ui/win.py,pwman/data/convertdb.py,pwman/data/nodes_multiple_approach.py,pwman/data/models.py,pwman/data/drivers/postgresql.py,pwman/data/drivers/mysql.py,pwman/exchange/importer.py,pwman/ui/base.py" --source=pwman setup.py test 
 
 
 
 
 after_success:
 after_success:
-      coveralls
+  coveralls

+ 14 - 2
pwman/data/drivers/postgresql.py

@@ -90,8 +90,14 @@ class PostgresqlDatabase(Database):
             rid = self._cur.fetchone()[0]
             rid = self._cur.fetchone()[0]
             return rid
             return rid
 
 
+    def _clean_orphands(self):
+        clean = ("delete from tag where not exists "
+                 "(select 'x' from lookup l where l.tagid = tag.id)")
+        self._cur.execute(clean)
+        self._con.commit()
+
     def close(self):
     def close(self):
-        # TODO: implement _clean_orphands
+        self._clean_orphands()
         self._cur.close()
         self._cur.close()
         self._con.close()
         self._con.close()
 
 
@@ -141,7 +147,13 @@ class PostgresqlDatabase(Database):
         pass
         pass
 
 
     def listtags(self):
     def listtags(self):
-        pass
+        self._clean_orphands()
+        get_tags = "select data from tag"
+        self._cur.execute(get_tags)
+        tags = self._cur.fetchall()
+        if tags:
+            return [t[0] for t in tags]
+        return []
 
 
     def _create_tables(self):
     def _create_tables(self):
 
 

+ 5 - 0
pwman/tests/test_postgresql.py

@@ -77,6 +77,11 @@ class TestPostGresql(unittest.TestCase):
 
 
         self.assertEqual(s, s1)
         self.assertEqual(s, s1)
 
 
+    def test_7a_clean_orphands(self):
+
+        self.db._clean_orphands()
+        rv = self.db._get_tag("SECRET")
+        self.assertIsNone(rv)
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':