Beispiel #1
0
class TaskPayloadHelperTestSuite(TestCase):
    def setUp(self):
        self.taskPayloadHelper = TaskPayloadHelper(TEST_PAYLOAD)
        
        self.owner = TaskOwner(email='*****@*****.**', key='example')
        self.owner.save()
    
    def test_get_ready_datetime(self):
        self.assertEqual(self.taskPayloadHelper.get_ready_datetime(),
                         TEST_DATE_EXPECT)
    
    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_is_valid(self):
        self.assertTrue(self.taskPayloadHelper.is_valid())
Beispiel #2
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]}
Beispiel #3
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]
    }