Commits

Yuriy Netesov committed cccba75

+++

Comments (0)

Files changed (5)

 #
 
 import sys
+import unittest
 
 from config import config
 from tagsystem.tagsystem import TagSystem
+import tagjumper_test
 
 tagSys = TagSystem(config.dbUri)
 
+def test_command(args):
+    tagjumper_test.main()
+
 def jump_command(args):
-    print 'jumping over tag'
+    for payloadData in tagSys.jump_tags(args):
+        print payloadData
 
 def tag_command(args):
     tagSys.tag_payloads([args[0]], args[1:])
     commands = {'jmp' : jump_command,
                 'tag' : tag_command,
                 'untag' : untag_command,
-                'rename_tag' : rename_tag_command}
+                'rename_tag' : rename_tag_command,
+                'unittest' : test_command}
     commandName = args[0]
     return commands[commandName](args[1:])
     

tagjumper_test.py

+
+import unittest
+
+testsVerbosity = 2
+
+class TagJumperTest(unittest.TestCase):
+    def setUp(self):
+        pass
+
+    def test_tag_system(self):
+        suite = unittest.TestLoader().discover("./tagsystem", "*_test.py")
+        unittest.TextTestRunner(verbosity = testsVerbosity).run(suite)
+        
+
+def main():
+    suite = unittest.TestLoader().loadTestsFromTestCase(TagJumperTest)
+    unittest.TextTestRunner(verbosity = testsVerbosity).run(suite)
+
+if __name__ == '__main__':
+    main()

tagsystem/payloads.py

+from payload import Payload
+
+
+class Payloads:
+    def __init__(self):
+        pass
+
+    def touch(self, payloadData):
+        payload = Payload.get_by(data=payloadData)
+        if payload:
+            return payload
+        else:
+            return Payload(data = payloadData, tags = [])
+
+    def get_payloads_by_tags(self, requiredTags):
+        return Payload.query.filter(Payload.tags.contains(requiredTags))
+

tagsystem/tagsystem.py

         payload = self._payloads.touch(payloadData)
         payload.untag([self._tags.get(tagName) for tagName in tagsNames])
 
+
     def tag_payloads(self, payloadsDatas, tagsNames):
         """ tags multiply payloads with multiply tags """
         for payloadData in payloadsDatas:
         """ toggle tags off on specified payloads """
         for payloadData in payloadsDatas:
             self._untag_payload(payloadData, tagsNames)
+        elixir.session.commit()
 
     def rename_tag(self, oldTagName, newTagName):
         """ renames specified tag with newName """
         #TODO : implement me
         pass
 
-    def jump_tags(self, tags):
+    def jump_tags(self, tagsNames):
         """ return list of payloads relevant to tags """
-        pass
+        tags = [self._tags.get(tagName) for tagName in tagsNames]
+        return [payload.data for payload in self._payloads.get_payloads_by_tags(tags)]

tagsystem/tagsystem_test.py

+import unittest
+from tagsystem import TagSystem
+
+dbUri = "mysql://root:QAZxsw123@localhost/tags"
+
+class TagSystemTests(unittest.TestCase):
+    def setUp(self):
+        self.tagsystem = TagSystem(dbUri)
+
+    def test_tag_payload(self):
+        self.tagsystem.tag_payloads(['testData_1'], ['test_tag1'])
+
+    def test_doubletag_payload(self):
+        self.tagsystem.tag_payloads(['testData_2'], ['test_tag1', 'test_tag2'])
+
+def main():
+    unittest.main()
+
+if __name__ == '__main__':
+    main()