def test_receive_task_failure(self):
        # cleaning tasks_dirs
        tasks_dir = os.path.join(self.c_dir, 'test_receive_task_failure')
        to_proc_dir = os.path.join(tasks_dir, 'to_proc')
        ready_dir = os.path.join(tasks_dir, 'ready')
        shutil.rmtree(tasks_dir, ignore_errors=True)
        # creating tasks
        os.makedirs(to_proc_dir)
        os.makedirs(ready_dir)
        task_name = '100'
        with open(os.path.join(to_proc_dir, task_name), 'w') as f:
            f.write('one\n')
            f.write('two\n')
        # testing task receive
        tm = TaskManager(to_proc_dir, ready_dir)
        self.assertTrue(task_name in os.listdir(to_proc_dir))
        self.assertTrue(task_name not in os.listdir(ready_dir))

        fake_task = Task('fake')
        self.assertRaises(UnknownTaskReceived, tm.receive_task, fake_task)

        wrong_content_task = Task.from_file(to_proc_dir, task_name)
        wrong_content_task.content = 'fake_%s' % wrong_content_task.content
        self.assertRaises(ResultTaskContentMismatch, tm.receive_task,
            wrong_content_task)

        # cleaning tasks_dirs
        shutil.rmtree(tasks_dir, ignore_errors=True)
 def test_from_file(self):
     c_dir = os.path.dirname(__file__)
     tasks_dir = os.path.join(c_dir, 'tasks', 'to_proc')
     task_name = 'one'
     t = Task.from_file(tasks_dir, task_name)
     exp_content = 'some content'
     self.assertEquals(task_name, t.name)
     self.assertEquals(exp_content, t.content)
     self.assertEquals(None, t.result)