Commit 626d38a6 by Rafael Monnerat

slapos/tests: Add tests for promises history

1 parent 1cccbb42
......@@ -404,7 +404,7 @@ class PromiseLauncher(object):
history_file = os.path.join(
self.promise_history_output_dir,
'%s.history.json' % result.name
'%s.history.json' % result.title
)
# Remove useless informations
......
......@@ -40,6 +40,7 @@ from slapos.grid.promise import (interface, PromiseLauncher, PromiseProcess,
PromiseError, PROMISE_CACHE_FOLDER_NAME)
from slapos.grid.promise.generic import (GenericPromise, TestResult, AnomalyResult,
PromiseQueueResult, PROMISE_STATE_FOLDER_NAME,
PROMISE_HISTORY_RESULT_FOLDER_NAME,
PROMISE_RESULT_FOLDER_NAME,
PROMISE_PARAMETER_NAME)
......@@ -356,6 +357,26 @@ class RunPromise(GenericPromise):
result_dict['result'].pop('date')
self.assertEqual(json.loads(expected_result), result_dict)
expected_history = """{
"data": [{
"execution-time": 0.05,
"failed": false,
"message": "success",
"name": "my_promise.py",
"status": "OK",
"title": "my_promise"
}]
}"""
history_file = os.path.join(self.partition_dir, PROMISE_HISTORY_RESULT_FOLDER_NAME, 'my_promise.history.json')
self.assertTrue(os.path.exists(history_file))
with open(history_file) as f:
result_dict = json.loads(f.read())
result_dict.pop('date')
d = result_dict["data"][0].pop("date")
self.assertEqual(d, result_dict["data"][0].pop("change-date"))
self.assertEqual(json.loads(expected_history), result_dict)
def test_runpromise_multiple(self):
promise_name = 'my_promise.py'
second_name = 'my_second_promise.py'
......@@ -399,6 +420,52 @@ class RunPromise(GenericPromise):
expected_dict = expected_result % {'promise_dir': self.plugin_dir, 'name': 'my_second_promise'}
self.assertEqual(json.loads(expected_dict), result_dict)
expected_history = """{
"data": [{
"execution-time": 0.05,
"failed": false,
"message": "success",
"name": "%(name)s.py",
"status": "OK",
"title": "%(name)s"
}]
}"""
history_file = os.path.join(self.partition_dir, PROMISE_HISTORY_RESULT_FOLDER_NAME, 'my_promise.history.json')
self.assertTrue(os.path.exists(history_file))
with open(history_file) as f:
result_dict = json.loads(f.read())
result_dict.pop('date')
d = result_dict["data"][0].pop("date")
self.assertEqual(d, result_dict["data"][0].pop("change-date"))
expected_dict = expected_history % {'promise_dir': self.plugin_dir, 'name': 'my_promise'}
self.assertEqual(json.loads(expected_dict), result_dict)
expected_history = """{
"data": [{
"execution-time": 0.05,
"failed": false,
"message": "success",
"name": "%(name)s.py",
"status": "OK",
"title": "%(name)s"
}]
}"""
history_file = os.path.join(self.partition_dir, PROMISE_HISTORY_RESULT_FOLDER_NAME, 'my_second_promise.history.json')
self.assertTrue(os.path.exists(history_file))
with open(history_file) as f:
result_dict = json.loads(f.read())
result_dict.pop('date')
d = result_dict["data"][0].pop("date")
self.assertEqual(d, result_dict["data"][0].pop("change-date"))
expected_dict = expected_history % {'promise_dir': self.plugin_dir, 'name': 'my_second_promise'}
self.assertEqual(json.loads(expected_dict), result_dict)
def test_runpromise_no_logdir(self):
promise_name = 'my_promise.py'
# no promise log output dir
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!