diff options
author | Stevan Radakovic <stevan.radakovic@linaro.org> | 2017-04-27 16:22:10 +0200 |
---|---|---|
committer | Matt Hart <matthew.hart@linaro.org> | 2017-05-31 12:47:27 +0100 |
commit | 55bf39f5b96a990cae48ddcc7301e3928b2e0b31 (patch) | |
tree | c91b4e32ce8d8b5cc3e0185d09a0437d0a3c63fd /lava_scheduler_app/tests/test_submission.py | |
parent | 71c514d6803cc375cd6268553c8eb277ac8030b3 (diff) |
Add a callback_url functionality to notification schema.
Adds a new field -callback_url- in notification schema and support
for it with TestJob field values substitutions.
Implements LAVA-927 (https://projects.linaro.org/browse/LAVA-927).
[Matt] Added support for pulling auth token from XMLRPC tokens for
submitting user with matching description
Added content-type option to respond in JSON.
Added auth-token to authorization header and fixed up the
docs.
Stop trying to send email if only POST callback is requested, but do
send email if a recipient is also requested.
Added a 'finished' status option that will send notifications on
canceled, complete or incomplete.
Added a status_string property to TestJob that is the string
representation of status. It's a more useful output than an integer.
Use {THING} as substitution to match LAVA elsewhere and not confuse
jinja with {{ }}
Change-Id: Ic567628eab90f1926ba59aed5bfe5a037f118c62
Diffstat (limited to 'lava_scheduler_app/tests/test_submission.py')
-rw-r--r-- | lava_scheduler_app/tests/test_submission.py | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/lava_scheduler_app/tests/test_submission.py b/lava_scheduler_app/tests/test_submission.py index 9d4b5fa87..06e745197 100644 --- a/lava_scheduler_app/tests/test_submission.py +++ b/lava_scheduler_app/tests/test_submission.py @@ -14,6 +14,7 @@ from lava_scheduler_app.models import ( Device, DeviceType, JSONDataError, + Notification, Tag, TestJob, DevicesUnavailableException, @@ -147,7 +148,7 @@ class ModelFactory(object): def make_testjob(self, definition=None, submitter=None, **kwargs): if definition is None: - definition = self.make_job_json() + definition = self.make_job_json(**kwargs) if submitter is None: submitter = self.make_user() if 'user' not in kwargs: @@ -156,6 +157,19 @@ class ModelFactory(object): testjob.save() return testjob + def make_notification(self, job): + notification = Notification() + notification.test_job = job + notification.verbosity = Notification.QUIET + + notification.callback_url = "http://localhost/" + notification.callback_token = "token" + notification.callback_method = Notification.POST + notification.callback_dataset = Notification.MINIMAL + notification.save() + + return notification + class TestCaseWithFactory(TestCase): # pylint: disable=too-many-ancestors @@ -705,6 +719,35 @@ class TestTestJob(TestCaseWithFactory): # pylint: disable=too-many-ancestors,to invalid_job_data = self.factory.make_invalid_job_json() self.assertFalse(is_deprecated_json(invalid_job_data)) + def test_get_callback_data(self): + + device_type = self.factory.ensure_device_type(name='panda') + self.factory.make_device(device_type=device_type, hostname="panda3") + user = self.factory.ensure_user(username='notification-user', email='', password='test', ) + job = self.factory.make_testjob(device_type='panda', submitter=user) + notification = self.factory.make_notification(job) + + test_callback_data = { + 'actual_device_id': None, + 'definition': '{\n "actions": [],\n "device_type": "panda",\n "health_check": false,\n "timeout": 1\n}', + 'description': '', + 'end_time': 'None', + 'failure_comment': None, + 'is_pipeline': False, + 'metadata': [], + 'priority': 50, + 'start_time': 'None', + 'status': 0, + 'status_string': 'submitted', + 'submitter_username': u'notification-user', + 'token': 'token' + } + notification_callback_data = notification.get_callback_data() + del notification_callback_data['submit_time'] + del notification_callback_data['id'] + + self.assertEqual(test_callback_data, notification_callback_data) + class TestHiddenTestJob(TestCaseWithFactory): # pylint: disable=too-many-ancestors |