From 26bf0af6371d365211407fe6873eb923c910e57e Mon Sep 17 00:00:00 2001 From: Guillaume Tucker Date: Mon, 29 Oct 2018 14:43:19 +0000 Subject: [PATCH] lava_results_app: add test case for YAML Decimal object conversion The test case metadata may contain measurements which are stored as Decimal objects in the database. By default, they get dumped in YAML as a Decimal Python object which makes it incompatible with standard parsers when the results are exported (in YAML or CSV). Add a test case to catch this problem with arbitrary metadata, checking the actual YAML text stored in the TestCase object. Signed-off-by: Guillaume Tucker --- lava_results_app/tests/test_metadata.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lava_results_app/tests/test_metadata.py b/lava_results_app/tests/test_metadata.py index fd40cf63b7..7ce217ed5e 100644 --- a/lava_results_app/tests/test_metadata.py +++ b/lava_results_app/tests/test_metadata.py @@ -114,6 +114,19 @@ def test_duration(self): action_data.save(update_fields=['timeout']) self.assertEqual(action_data.timeout, 300) + def test_decimal_yaml_dump(self): + job = TestJob.from_yaml_and_user( + self.factory.make_job_yaml(), self.user) + test_dict = { + 'definition': 'unit-test', + 'case': 'unit-test', + 'measurement': decimal.Decimal(1234.5), + 'result': 'pass', + } + test_case = map_scanned_results(test_dict, job, {}, None) + metadata_yaml_ref = "{case: unit-test, definition: unit-test, measurement: '1234.5', result: pass}" + self.assertEqual(metadata_yaml_ref, test_case.metadata.strip()) + def test_case_as_url(self): job = TestJob.from_yaml_and_user( self.factory.make_job_yaml(), self.user)