Parcourir la source

Add list tag method

oz123 il y a 10 ans
Parent
commit
908a5bfb7f
2 fichiers modifiés avec 6 ajouts et 5 suppressions
  1. 6 3
      pwman/data/drivers/mongodb.py
  2. 0 2
      tests/test_mongodb.py

+ 6 - 3
pwman/data/drivers/mongodb.py

@@ -47,8 +47,10 @@ class MongoDB(Database):
         return nodeid['seq']
 
     def getnodes(self, ids):
-
-        node_dicts = self._db.nodes.find({'_id': {'$in': ids}})
+        if ids:
+            node_dicts = self._db.nodes.find({'_id': {'$in': ids}})
+        else:
+            node_dicts = self._db.nodes.find({})
         nodes = []
         for node in node_dicts:
             n = [node['_id'],
@@ -85,7 +87,8 @@ class MongoDB(Database):
         return nid
 
     def listtags(self):
-        pass
+        tags = self._db.nodes.distinct('tags')
+        return tags
 
     def editnode(self, nid, **kwargs):
         pass

+ 0 - 2
tests/test_mongodb.py

@@ -86,12 +86,10 @@ class TestMongoDB(unittest.TestCase):
         ret = self.db.listnodes("footag")
         self.assertEqual(ret, [1])
 
-    @unittest.skip("")
     def test_6a_list_tags(self):
         ret = self.db.listtags()
         self.assertListEqual(ret, ['bartag', 'footag'])
 
-    @unittest.skip("")
     def test_6b_get_nodes(self):
         ret = self.db.getnodes([1])
         retb = self.db.getnodes([])