def test_constructor_kwargs(self): task_obj = Task(TestTask.f_kwargs, Priority.default) assert task_obj.name == 'tests.test_task_manager.f_kwargs' assert task_obj.fn is TestTask.f_kwargs assert task_obj.priority is Priority.default assert task_obj._accepts_metadata is True assert task_obj._accepts_headers is True
def test_constructor(self): task_obj = Task(TestTask.f, Priority.default) assert task_obj.name == 'tests.test_task_manager.f' assert task_obj.fn is TestTask.f assert task_obj.priority is Priority.default assert task_obj._accepts_metadata is False assert task_obj._accepts_headers is False
def test_constructor_accepts_metadata_and_headers(self): task_obj = Task(TestTask.f_metadata_headers, Priority.default, 'name') assert task_obj.name == 'name' assert task_obj.fn is TestTask.f_metadata_headers assert task_obj.priority is Priority.default assert task_obj._accepts_metadata is True assert task_obj._accepts_headers is True
def validate(self) -> None: """ Validate that message object contains all the right things. :raises exceptions.ValidationError: when message fails validation """ from taskhawk.task_manager import Task if (not self.id or not self.version or self.version not in self.VERSIONS or not self.timestamp or self.headers is None or not self.task_name or self.args is None or self.kwargs is None): raise ValidationError try: self._task = Task.find_by_name(self.task_name) except TaskNotFound: raise ValidationError
def test_find_by_name_fail(self): with pytest.raises(TaskNotFound): Task.find_by_name('invalid')
def test_find_by_name(self): assert Task.find_by_name('tests.tasks.send_email') == send_email.task
def test_dispatch(self, mock_dispatch): task_obj = Task(TestTask.f, Priority.default) task_obj.dispatch(1, 2) mock_dispatch.assert_called_once() assert mock_dispatch.call_args[0][1:] == (1, 2)
def test_with_priority(self): task_obj = Task(TestTask.f, Priority.default) assert task_obj.with_priority(Priority.high)._priority == Priority.high
def test_with_headers(self): task_obj = Task(TestTask.f, Priority.default) request_id = str(uuid.uuid4()) assert task_obj.with_headers(request_id=request_id)._headers == {'request_id': request_id}
def test_constructor_bad_annotation(self): with pytest.raises(ConfigurationError): Task(TestTask.f_invalid_annotation, Priority.default)
def test_constructor_disallow_args(self): with pytest.raises(ConfigurationError): Task(TestTask.f_args, Priority.default)