Coverage for CIResults/tests/test_helpers.py: 100%
19 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-19 09:20 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-19 09:20 +0000
1from django.test import TestCase
2from unittest.mock import MagicMock
4from CIResults.templatetags.helpers import list_custom_fields, issues_list_custom_fields, lookup
7class list_custom_fieldsTests(TestCase):
8 def test_basic_scenario(self):
9 bug1 = MagicMock(custom_fields={'hello': 'world'})
10 bug2 = MagicMock(custom_fields={'foo': 'bar'})
12 self.assertEqual(list_custom_fields([bug1, bug2]), ['foo', 'hello'])
15class issues_list_custom_fieldsTests(TestCase):
16 def test_basic_scenario(self):
17 issue1 = MagicMock(bugs_cached=[MagicMock(custom_fields={'toto': 'tata'}),
18 MagicMock(custom_fields={'42': 'answer to life the universe and everything'})])
19 issue2 = MagicMock(bugs_cached=[MagicMock(custom_fields={'hello': 'world'}),
20 MagicMock(custom_fields={'foo': 'bar'})])
22 self.assertEqual(issues_list_custom_fields([issue1, issue2]), ['42', 'foo', 'hello', 'toto'])
25class lookupTestsTests(TestCase):
26 def test_when_key_exists(self):
27 obj = {'hello': 'world'}
28 self.assertEqual(lookup(obj, 'hello'), 'world')
30 def test_when_key_doesnt_exist(self):
31 self.assertEqual(lookup({}, '42'), None)