diff options
author | BonfaceKilz | 2021-02-16 20:25:54 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-02-16 20:25:54 +0300 |
commit | 53d81e0d9f66f09b63e5b36bd33c79e8bc930215 (patch) | |
tree | cb7e3c42573a3332bb9b63b3351cc049f31e704b /tests/unit/test_commands.py | |
parent | 9e638622d93cc405ecd14c3a5f4288e08aecdddb (diff) | |
download | genenetwork3-53d81e0d9f66f09b63e5b36bd33c79e8bc930215.tar.gz |
Add extra option to set email when queueing CMD
The e-mail field will be used to send the results of the computation when it
is completed.
Diffstat (limited to 'tests/unit/test_commands.py')
-rw-r--r-- | tests/unit/test_commands.py | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/tests/unit/test_commands.py b/tests/unit/test_commands.py index b0c217d..9dfa9f9 100644 --- a/tests/unit/test_commands.py +++ b/tests/unit/test_commands.py @@ -46,15 +46,15 @@ class TestCommands(unittest.TestCase): """Test that the correct error is raised when Redis is unavailable""" self.assertRaises(RedisConnectionError, queue_cmd, - "ls", - MockRedis(ping=lambda: False, - hset=mock.MagicMock(), - rpush=mock.MagicMock())) + cmd="ls", + conn=MockRedis(ping=lambda: False, + hset=mock.MagicMock(), + rpush=mock.MagicMock())) @mock.patch("gn3.commands.datetime") @mock.patch("gn3.commands.uuid4") - def test_queue_cmd_right_correct_calls_to_redis(self, mock_uuid4, - mock_datetime): + def test_queue_cmd_correct_calls_to_redis(self, mock_uuid4, + mock_datetime): """Test that the cmd is queued properly""" mock_uuid4.return_value = 1234 mock_datetime.now.return_value = datetime.fromisoformat('2021-02-12 ' @@ -64,7 +64,9 @@ class TestCommands(unittest.TestCase): hset=mock.MagicMock(), rpush=mock.MagicMock()) actual_unique_id = "cmd::2021-02-1217-3224-3224-1234" - self.assertEqual(queue_cmd("ls", mock_redis_conn), actual_unique_id) + self.assertEqual(queue_cmd(cmd="ls", + conn=mock_redis_conn), + actual_unique_id) mock_redis_conn.hset.assert_has_calls( [mock.call("cmd", "ls", actual_unique_id), mock.call("result", "", actual_unique_id), @@ -72,6 +74,32 @@ class TestCommands(unittest.TestCase): mock_redis_conn.rpush.assert_has_calls( [mock.call("GN2::job-queue", actual_unique_id)]) + @mock.patch("gn3.commands.datetime") + @mock.patch("gn3.commands.uuid4") + def test_queue_cmd_right_calls_to_redis_with_email(self, + mock_uuid4, + mock_datetime): + """Test that the cmd is queued properly when given the email""" + mock_uuid4.return_value = 1234 + mock_datetime.now.return_value = datetime.fromisoformat('2021-02-12 ' + '17:32:24.' + '859097') + mock_redis_conn = MockRedis(ping=lambda: True, + hset=mock.MagicMock(), + rpush=mock.MagicMock()) + actual_unique_id = "cmd::2021-02-1217-3224-3224-1234" + self.assertEqual(queue_cmd(cmd="ls", + conn=mock_redis_conn, + email="me@me.com"), + actual_unique_id) + mock_redis_conn.hset.assert_has_calls( + [mock.call("cmd", "ls", actual_unique_id), + mock.call("result", "", actual_unique_id), + mock.call("status", "queued", actual_unique_id), + mock.call("email", "me@me.com", actual_unique_id)]) + mock_redis_conn.rpush.assert_has_calls( + [mock.call("GN2::job-queue", actual_unique_id)]) + def test_run_cmd_correct_input(self): """Test that a correct cmd is processed correctly""" self.assertEqual(run_cmd("echo test"), |