From 9fe7993d96517bbe1817792ab3867840f33b5db4 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sat, 5 Sep 2015 13:12:10 +0200 Subject: [PATCH] tests: Add export_one and latest helpers to the Task test interface - The 'export_one' method will export one task matching a filter, raising error if not exactly one task was matched. - The 'latest' property will return the task matching the "+LATEST" filter. --- test/basetest/task.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/basetest/task.py b/test/basetest/task.py index dc6ad8ecc..27d56c3c0 100644 --- a/test/basetest/task.py +++ b/test/basetest/task.py @@ -156,6 +156,32 @@ class Task(object): return json.loads(out) + def export_one(self, export_filter=None): + """ + Return a dictionary representing the exported task. Will + fail if mutliple tasks match the filter. + """ + + result = self.export(export_filter=export_filter) + + if len(result) != 1: + descriptions = [task.get('description') or '[description-missing]' + for task in result] + + raise ValueError( + "One task should match the '{0}' filter, '{1}' " + "matches:\n {2}".format( + export_filter or '', + len(result), + '\n '.join(descriptions) + )) + + return result[0] + + @property + def latest(self): + return self.export_one("+LATEST") + @staticmethod def _split_string_args_if_string(args): """Helper function to parse and split into arguments a single string