Commits

Marcin Kasperski committed 763072f

Added move_task method (+ sample, + test)

Comments (0)

Files changed (3)

sample/sample_client.py

                   (u"Strzela", u"krokodyl zielony\nbawi się z tej owej strony") ])
     print "Created task", task
 
+    task2 = client.create_task(
+        u"Zażółć gęślą jaźń")
+    print "Created task", task2
+    
+    task2 = client.move_task(
+        task2.key, test_list.id)
+    print "Moved task", task2
+
     print "Tasks on test list"
     tlist_task = list(client.find_tasks(test_list.id))
     for t in tlist_task:

src/mekk/rtm/rtm_client.py

 
         return task
 
+    def move_task(self, task_key, new_list_id):
+        """
+        Moves given task to new list. Returns current task state.
+        Note that task key changes after this operation!
+        """
+        timeline = self._get_timeline()
+        r = self.connector.call(
+            "rtm.tasks.moveTo",
+            timeline = timeline,
+            from_list_id = task_key.list_id,
+            to_list_id = new_list_id,
+            taskseries_id = task_key.taskseries_id,
+            task_id = task_key.task_id)
+        task = RtmClient._parse_task(
+            new_list_id,
+            RtmClient._ensure_element_is_singular(r['list']['taskseries']))
+        return task
+
     def add_task_note(self, task_key, 
                       note_title, note_text):
         """

tests/test_client.py

 
     raise SkipTest
 
+@patch.object(httplib2.Http, 'request')
+def test_moveTask(mock_req):
+    connector = RtmConnector("api-key", "api-sec", "write", "33423")
+    client  = RtmClient(connector)
+    client._timeline = '337369522'
+
+    mock_req.return_value = (
+        dict(status='200'),
+        r"""
+{"rsp":{"stat":"ok","transaction":{"id":"2554995402","undoable":"1"},"list":{"id":"16150681","taskseries":{"id":"93467164","created":"2010-11-14T10:53:04Z","modified":"2010-11-14T10:53:05Z","name":"Za\u017c\u00f3\u0142\u0107 g\u0119\u015bl\u0105 ja\u017a\u0144","source":"api","url":"","location_id":"","tags":[],"participants":[],"notes":[],"task":{"id":"139580828","due":"","has_due_time":"0","added":"2010-11-14T10:53:04Z","completed":"","deleted":"","priority":"N","postponed":"0","estimate":""}}}}}
+""")
+    old_id = TaskKey(
+        task_id='139580828', taskseries_id='93467164', list_id='5384544')
+    new_id = TaskKey(
+        task_id='139580828', taskseries_id='93467164', list_id='16150681')
+    t = client.move_task(
+        old_id,
+        new_list_id = new_id.list_id)
+
+    nt.assert_equal(t.key, new_id)
+    nt.assert_equal(t.name,  u"Zażółć gęślą jaźń")
+    nt.assert_equal(t.tags, [])
+    nt.assert_equal(t.notes, [])
+    nt.assert_equal(t.due, None)
+    nt.assert_equal(t.estimate, None)
+    nt.assert_equal(t.priority, None)
+    nt.assert_equal(t.completed, None)
+    nt.assert_equal(t.deleted, None)
+    nt.assert_equal(t.postponed, 0)
+    nt.assert_equal(t.repeat, None)
+
+    nt.assert_equal(
+        mock_req.call_args, 
+        (('http://api.rememberthemilk.com/services/rest/?api_key=api-key&auth_token=33423&format=json&from_list_id=5384544&method=rtm.tasks.moveTo&task_id=139580828&taskseries_id=93467164&timeline=337369522&to_list_id=16150681&api_sig=cff6742ae43d75d4079bd28484fff27b',),
+         {'headers': {'Cache-Control': 'no-cache, max-age=0'}})
+        )