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

1from django.test import TestCase 

2from unittest.mock import MagicMock 

3 

4from CIResults.templatetags.helpers import list_custom_fields, issues_list_custom_fields, lookup 

5 

6 

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'}) 

11 

12 self.assertEqual(list_custom_fields([bug1, bug2]), ['foo', 'hello']) 

13 

14 

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'})]) 

21 

22 self.assertEqual(issues_list_custom_fields([issue1, issue2]), ['42', 'foo', 'hello', 'toto']) 

23 

24 

25class lookupTestsTests(TestCase): 

26 def test_when_key_exists(self): 

27 obj = {'hello': 'world'} 

28 self.assertEqual(lookup(obj, 'hello'), 'world') 

29 

30 def test_when_key_doesnt_exist(self): 

31 self.assertEqual(lookup({}, '42'), None)