Пример #1
0
 def test_from_json(self):
     name = 'a'
     content = 'cccdd o'
     result = 'res'
     json_task = json.dumps({'name': name, 'content': content,
         'result': result})
     t = Task.from_json(json_task)
     self.assertEquals(name, t.name)
     self.assertEquals(content, t.content)
     self.assertEquals(result, t.result)
Пример #2
0
def receive_task(tm, env):
    try:
        raw_data = env['wsgi.input'].read()
        task = Task.from_json(raw_data)
        tm.receive_task(task)
        result = {'action': 'get_task'}
    except TaskFromJsonLoadingError:
        result = {'action': 'exit_client', 'reason': 'wrong request format'}
    except (UnknownTaskReceived, ResultTaskContentMismatch, SavingResultTaskError):
        result = {'action': 'get_task'}
    return result