def test_get_task_success(self): with patch('salt.utils.http.query', return_value={'body': '{"foo":"bar"}'}) as http_mock: task = kapacitor.get_task('taskname') http_mock.assert_called_once_with( 'http://localhost:9092/task?name=taskname') assert {'foo': 'bar'} == task
def test_get_task_not_found(self): with patch('salt.utils.http.query', return_value={'body': '{"Error":"unknown task taskname"}' }) as http_mock: task = kapacitor.get_task('taskname') http_mock.assert_called_once_with( 'http://localhost:9092/task?name=taskname') assert None == task
def test_get_task_not_found(self): query_ret = {"body": '{"Error":"unknown task taskname"}', "status": 404} with patch("salt.utils.http.query", return_value=query_ret) as http_mock: task = kapacitor.get_task("taskname") http_mock.assert_called_once_with( "http://localhost:9092/kapacitor/v1/tasks/taskname?skip-format=true", status=True, ) self.assertEqual(None, task)
def test_get_task_success(self): http_body = salt.utils.json.dumps({ 'script': 'test', 'type': 'stream', 'dbrps': [{'db': 'db', 'rp': 'rp'}], 'status': 'enabled', }) query_ret = {'body': http_body, 'status': 200} with patch('salt.utils.http.query', return_value=query_ret) as http_mock: task = kapacitor.get_task('taskname') http_mock.assert_called_once_with('http://localhost:9092/kapacitor/v1/tasks/taskname?skip-format=true', status=True) self.assertEqual('test', task['script'])
def test_get_task_not_found(self): query_ret = { 'body': '{"Error":"unknown task taskname"}', 'status': 404 } with patch('salt.utils.http.query', return_value=query_ret) as http_mock: task = kapacitor.get_task('taskname') http_mock.assert_called_once_with( 'http://localhost:9092/kapacitor/v1/tasks/taskname?skip-format=true', status=True) self.assertEqual(None, task)
def test_get_task_success(self): http_body = salt.utils.json.dumps( { "script": "test", "type": "stream", "dbrps": [{"db": "db", "rp": "rp"}], "status": "enabled", } ) query_ret = {"body": http_body, "status": 200} with patch("salt.utils.http.query", return_value=query_ret) as http_mock: task = kapacitor.get_task("taskname") http_mock.assert_called_once_with( "http://localhost:9092/kapacitor/v1/tasks/taskname?skip-format=true", status=True, ) self.assertEqual("test", task["script"])