source: OpenWorkouts-current/ow/tests/tasks/test_run.py @ b5d87e0

currentfeature/docs
Last change on this file since b5d87e0 was b5d87e0, checked in by Borja Lopez <borja@…>, 5 years ago

(#29) Added a tasks module, implemented a task to run the mail queue processor,
sending any automatically generated emails in the queue.

Tasks can be run manually, with the virtual env active:

python ow/tasks/run.py development.ini TASK_NAME

(where TASK_NAME is the name of a task, like send_emails)

Running the run.py script without parameters gives an usage-like message
with instructions on how to properly call the script.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1from unittest.mock import Mock, patch
2
3import pytest
4
5from pyramid.testing import DummyRequest
6
7from ow.tasks.manager import TasksManager
8from ow.tasks.run import command_line
9
10
11@patch('ow.tasks.manager.setup_logging')
12@patch('ow.tasks.manager.bootstrap')
13@patch('ow.tasks.run.sys')
14@patch('ow.tasks.run.TasksManager')
15class TestCommandLine(object):
16    """
17    Tests covering the command_line method that allows users to execute the
18    tasks manager from a CLI.
19    """
20
21    @pytest.fixture
22    def registry(self):
23        """
24        Mock a pyramid registry
25        """
26        registry = Mock()
27        registry.settings = {}
28        return registry
29
30    @pytest.fixture
31    def env(self, registry):
32        env = {'request': DummyRequest(),
33               'root': {},
34               'closer': Mock(),
35               'registry': registry}
36        return env
37
38    @pytest.fixture
39    def manager(self):
40        tm = TasksManager()
41        tm.usage = Mock()
42        tm.usage.return_value = 'faked manager usage'
43        return tm
44
45    def test_wrong_params(self, tm, mysys, b, manager, env):
46        mysys.argv = ['script', 'one', 'two', 'three']
47        mysys.exit.side_effect = ValueError('sysexit')
48        tm.return_value = manager
49        b.return_value = env
50        with pytest.raises(ValueError):
51            command_line()
52        mysys.exit.assert_called_with(1)
53
54    @patch('ow.tasks.run.queue_processor')
55    def test_right_params_send_emails(
56            self, qp, tm, mysys, b, sl, manager, env):
57        mysys.argv = ['tasks-script', 'tests.ini', 'send_emails']
58        qp.return_value = None
59        tm.return_value = manager
60        b.return_value = env
61        command_line()
62        qp.assert_called_with(env)
Note: See TracBrowser for help on using the repository browser.