def test_ready_and_delete_tasks(self): task_1 = Task( owner=self.taskowner, source="@handle_a", dest="@handle_b", content="some message", ready_time=datetime.utcnow() + timedelta(minutes=10), ) task_1.save() task_2 = Task( owner=self.taskowner, source="*****@*****.**", dest="*****@*****.**", content="some message", ready_time=datetime.utcnow(), ) task_2.save() ready_tasks = pushQueue._get_ready_tasks() self.assertEqual(len(ready_tasks), 1) self.assertEqual(ready_tasks[0].source, "*****@*****.**") pushQueue._delete_processed_tasks(ready_tasks) ready_tasks_after = pushQueue._get_ready_tasks() self.assertEqual(len(ready_tasks_after), 0)
def POST(task_owner, task_id, request_payload): if task_owner is None: return {const.KEY_RESP_STATUS: "ERROR", const.KEY_RESP_STATUS_TEXT: "specified TaskOwner object not found"} taskPayloadHelper = TaskPayloadHelper(request_payload) if not taskPayloadHelper.is_valid() or taskPayloadHelper.is_duplicate(): return {const.KEY_RESP_STATUS: "ERROR", const.KEY_RESP_STATUS_TEXT: "payload is invalid or already exists"} if task_id is None: task = Task(owner=task_owner, source=taskPayloadHelper[const.KEY_SOURCE], dest=taskPayloadHelper[const.KEY_DEST], content=taskPayloadHelper[const.KEY_CONTENT], ready_time=taskPayloadHelper.get_ready_datetime()) task.save() task_id = task.id else: task = _get_task_by_id(task_id) task.source = taskPayloadHelper[const.KEY_SOURCE] task.dest = taskPayloadHelper[const.KEY_DEST] task.content = taskPayloadHelper[const.KEY_CONTENT] task.ready_time = taskPayloadHelper.get_ready_datetime() task.save() return {const.KEY_ID: task_id, const.KEY_SOURCE: taskPayloadHelper[const.KEY_SOURCE], const.KEY_DEST: taskPayloadHelper[const.KEY_DEST], const.KEY_CONTENT: taskPayloadHelper[const.KEY_CONTENT], const.KEY_READY_TIME: taskPayloadHelper[const.KEY_READY_TIME]}
def test_is_duplicate(self): self.assertFalse(self.taskPayloadHelper.is_duplicate()) task = Task(owner=self.owner, source=TEST_PAYLOAD[const.KEY_SOURCE], dest=TEST_PAYLOAD[const.KEY_DEST], content=TEST_PAYLOAD[const.KEY_CONTENT], ready_time=TEST_DATE_EXPECT) task.save() self.assertTrue(self.taskPayloadHelper.is_duplicate())
def test_queue_task_creation(self): task_1 = Task(owner=self.taskowner, source="@handle_a", dest="@handle_b", content="some message", ready_time=datetime.now()) task_1.save() ready_tasks = pushQueue._get_ready_tasks() queue_Task = pushQueue._create_task_from_db(ready_tasks[0]) self.assertTrue(queue_Task)
def test_queue_task_creation(self): task_1 = Task( owner=self.taskowner, source="@handle_a", dest="@handle_b", content="some message", ready_time=datetime.now(), ) task_1.save() ready_tasks = pushQueue._get_ready_tasks() queue_Task = pushQueue._create_task_from_db(ready_tasks[0]) self.assertTrue(queue_Task)
def test_ready_and_delete_tasks(self): task_1 = Task(owner=self.taskowner, source="@handle_a", dest="@handle_b", content="some message", ready_time=datetime.utcnow() + timedelta(minutes=10)) task_1.save() task_2 = Task(owner=self.taskowner, source="*****@*****.**", dest="*****@*****.**", content="some message", ready_time=datetime.utcnow()) task_2.save() ready_tasks = pushQueue._get_ready_tasks() self.assertEqual(len(ready_tasks), 1) self.assertEqual(ready_tasks[0].source, "*****@*****.**") pushQueue._delete_processed_tasks(ready_tasks) ready_tasks_after = pushQueue._get_ready_tasks() self.assertEqual(len(ready_tasks_after), 0)
def POST(task_owner, task_id, request_payload): if task_owner is None: return { const.KEY_RESP_STATUS: "ERROR", const.KEY_RESP_STATUS_TEXT: "specified TaskOwner object not found" } taskPayloadHelper = TaskPayloadHelper(request_payload) if not taskPayloadHelper.is_valid() or taskPayloadHelper.is_duplicate(): return { const.KEY_RESP_STATUS: "ERROR", const.KEY_RESP_STATUS_TEXT: "payload is invalid or already exists" } if task_id is None: task = Task(owner=task_owner, source=taskPayloadHelper[const.KEY_SOURCE], dest=taskPayloadHelper[const.KEY_DEST], content=taskPayloadHelper[const.KEY_CONTENT], ready_time=taskPayloadHelper.get_ready_datetime()) task.save() task_id = task.id else: task = _get_task_by_id(task_id) task.source = taskPayloadHelper[const.KEY_SOURCE] task.dest = taskPayloadHelper[const.KEY_DEST] task.content = taskPayloadHelper[const.KEY_CONTENT] task.ready_time = taskPayloadHelper.get_ready_datetime() task.save() return { const.KEY_ID: task_id, const.KEY_SOURCE: taskPayloadHelper[const.KEY_SOURCE], const.KEY_DEST: taskPayloadHelper[const.KEY_DEST], const.KEY_CONTENT: taskPayloadHelper[const.KEY_CONTENT], const.KEY_READY_TIME: taskPayloadHelper[const.KEY_READY_TIME] }