Пример #1
0
    def test_grab_tickets_timeout(self) -> None:
        with patch('base_class.requests') as mock_requests:
            from deployment_log_UAT import DeployExtractor, NAME

            json_res = {
                'total':
                1,
                'issues': [{
                    "key": 'T2L-422',
                    "fields": {
                        'summary': 'Test Summary',
                        'customfield_13191': None
                    }
                }]
            }

            # Create a new Mock to imitate a Response
            response_mock = Mock()
            response_mock.json.return_value = json_res

            # Set the side effect of requests.get()
            mock_requests.get.side_effect = [
                Timeout, response_mock, response_mock
            ]
            instance = DeployExtractor(NAME, False)
            if not found_cache():
                with self.assertRaises(Timeout):
                    inst = instance.grab_tickets(dict())
                    assert isinstance(inst, dict)
                    assert inst == json_res
                    mock_requests.get.assert_called_once()
                assert instance.grab_tickets(
                    dict())['T2L-422']['summary'] == 'Test Summary'
                assert mock_requests.get.call_count == 3
Пример #2
0
    def test_clean_json_linkedIssues_JSONDecodeError_real_data(self) -> None:
        with patch('base_class.requests') as mock_requests:
            from test_extraction_V2 import TestExtractor, NAME
            from deployment_log_UAT import DeployExtractor
            from barros_request import BarrosExtractor
            dic = dict()
            dic['T2L-249'] = grab_tickets_json['T2L-249']
            # Create a new Mock to imitate a JSONDecodeError Response once the requests.get.json is triggered
            response_mock = Mock()
            response_mock.json.return_value = JSONDecodeError

            mock_requests.get.side_effect = [
                response_mock, response_mock, response_mock, response_mock,
                response_mock, response_mock
            ]
            with self.assertRaises(
                    TypeError
            ):  # testing 2 linked tickets so the asynchronous call is triggered
                print(TestExtractor(NAME, False).clean_json(dic))
            with self.assertRaises(
                    TypeError
            ):  # testing 2 linked tickets so the asynchronous call is triggered
                DeployExtractor(NAME, False).clean_json(dic)
            with self.assertRaises(
                    TypeError
            ):  # testing 2 linked tickets so the asynchronous call is triggered
                BarrosExtractor(NAME, False).clean_json(dic)
Пример #3
0
    def test_clean_json_linkedIssues_ConnectionError_real_data(self) -> None:
        with patch('base_class.requests') as mock_requests:
            from test_extraction_V2 import TestExtractor, NAME
            from deployment_log_UAT import DeployExtractor
            from barros_request import BarrosExtractor
            dic = dict()
            dic['T2L-249'] = grab_tickets_json['T2L-249']

            mock_requests.get.side_effect = [
                ConnectionError, ConnectionError, ConnectionError,
                ConnectionError, ConnectionError, ConnectionError
            ]
            with self.assertRaises(
                    ConnectionError
            ):  # testing 2 linked tickets so the asynchronous call is triggered
                TestExtractor(NAME, False).clean_json(dic)
            with self.assertRaises(
                    ConnectionError
            ):  # testing 2 linked tickets so the asynchronous call is triggered
                DeployExtractor(NAME, False).clean_json(dic)
            with self.assertRaises(
                    ConnectionError
            ):  # testing 2 linked tickets so the asynchronous call is triggered
                BarrosExtractor(NAME, False).clean_json(dic)
            configuration = Loader.grab_configuration(self)
            creds = f"Basic {configuration.u}"
            mock_requests.assert_has_calls([
                call.get(self.TEST_call_2,
                         headers={
                             'Authorization': creds,
                             'Content-Type': 'application/json'
                         },
                         verify=False)
            ])
Пример #4
0
 def test_remove_custom_fields_signature_synthetic_data(self) -> None:
     grab_tickets_json = {
         'T2L-255': {
             'customfield_14791': None,
             'customfield_14792': None,
             'customfield_14795': None,
             'customfield_14796': None
         }
     }
     from deployment_log_UAT import DeployExtractor, NAME
     inst = DeployExtractor(NAME, False)
     partial_function = partial(inst.remove_custom_fields,
                                grab_tickets_json)
     assert len(partial_function('customfield_14791')['T2L-255']) == 1
     assert len(
         partial_function('customfield_14791',
                          'customfield_14792')['T2L-255']) == 2
     assert len(
         partial_function('customfield_14791', 'customfield_14792',
                          'customfield_14795')['T2L-255']) == 3
     assert len(
         partial_function('customfield_14791', 'customfield_14792',
                          'customfield_14795',
                          'customfield_14796')['T2L-255']) == 4
     assert partial_function('customfield_14791')['T2L-255'] == {
         'customfield_14791': None
     }
Пример #5
0
 def test_remove_custom_fields_signature_real_data(self) -> None:
     from deployment_log_UAT import DeployExtractor, NAME
     inst = DeployExtractor(NAME, False)
     dic = dict()
     dic['T2L-255'] = grab_tickets_json['T2L-255']
     partial_function = partial(inst.remove_custom_fields, dic)
     assert len(partial_function('resolution')['T2L-255']) == 33
     assert len(
         partial_function('aggregatetimeestimate', 'aggregateprogress',
                          'votes')['T2L-255']) == 33
     assert len(partial_function('customfield_12706')['T2L-255']) == 34
Пример #6
0
 def test_super_call(self) -> None:
     from base_class import BaseExtractor
     from barros_request import BarrosExtractor, NAME
     instance = BarrosExtractor(NAME, False)
     assert isinstance(instance, BaseExtractor) is True
     from test_extraction_V2 import TestExtractor, NAME
     instance = TestExtractor(NAME, False)
     assert isinstance(instance, BaseExtractor) is True
     from jira_routine_V2 import LogExtractor, NAME
     instance = LogExtractor(NAME, False)
     assert isinstance(instance, BaseExtractor) is True
     from release_notes import ReleaseNoteExtractor, NAME
     instance = ReleaseNoteExtractor(NAME, False)
     assert isinstance(instance, BaseExtractor) is True
     from deployment_log_UAT import DeployExtractor, NAME
     instance = DeployExtractor(NAME, False)
     assert isinstance(instance, BaseExtractor) is True
Пример #7
0
    def test_clean_json_linkedIssues_ConnectionError_2links(self) -> None:
        with patch('base_class.BaseExtractor.grab_linked_tickets'
                   ) as mock_grab_linked_tickets:
            from test_extraction_V2 import TestExtractor, NAME
            from deployment_log_UAT import DeployExtractor
            from barros_request import BarrosExtractor
            # testing 2 linked tickets so that the asynchronous call is triggered
            dic = dict()
            dic['T2L-249'] = {
                'issuelinks': [{
                    'id': '419070',
                    'self': 'https://jira.com/rest/api/2/issueLink/419070',
                    'type': {
                        'id': '10031',
                        'name': 'Cause',
                        'inward': 'is caused by',
                        'outward': 'causes',
                        'self':
                        'https://jira.com/rest/api/2/issueLinkType/10031'
                    },
                    'outwardIssue': {
                        'id': '430893',
                        'key': 'CM-31975',
                        'self': 'https://jira.com/rest/api/2/issue/430893',
                        'fields': {
                            'summary': 'T24 TEMOS MCO changes',
                            'status': {
                                'self': 'https://jira.com/rest/api/2/status/6',
                                'description':
                                'The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.',
                                'iconUrl':
                                'https://jira.com/images/icons/statuses/closed.png',
                                'name': 'Closed',
                                'id': '6',
                                'statusCategory': {
                                    'self':
                                    'https://jira.com/rest/api/2/statuscategory/3',
                                    'id': 3,
                                    'key': 'done',
                                    'colorName': 'green',
                                    'name': 'Done'
                                }
                            },
                            'issuetype': {
                                'self':
                                'https://jira.com/rest/api/2/issuetype/21',
                                'id': '21',
                                'description': 'Request for a Normal Change',
                                'iconUrl':
                                'https://jira.com/secure/viewavatar?size=xsmall&avatarId=18724&avatarType=issuetype',
                                'name': 'Normal Change',
                                'subtask': False,
                                'avatarId': 18724
                            }
                        }
                    }
                }, {
                    'id': '418945',
                    'self': 'https://jira.com/rest/api/2/issueLink/418945',
                    'type': {
                        'id': '10031',
                        'name': 'Cause',
                        'inward': 'is caused by',
                        'outward': 'causes',
                        'self':
                        'https://jira.com/rest/api/2/issueLinkType/10031'
                    },
                    'inwardIssue': {
                        'id': '433704',
                        'key': 'EUHT-7091',
                        'self': 'https://jira.com/rest/api/2/issue/433704',
                        'fields': {
                            'summary':
                            'T24 - Interface - Temos : Negative MD amounts for Guarantees',
                            'status': {
                                'self': 'https://jira.com/rest/api/2/status/6',
                                'description':
                                'The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.',
                                'iconUrl':
                                'https://jira.com/images/icons/statuses/closed.png',
                                'name': 'Closed',
                                'id': '6',
                                'statusCategory': {
                                    'self':
                                    'https://jira.com/rest/api/2/statuscategory/3',
                                    'id': 3,
                                    'key': 'done',
                                    'colorName': 'green',
                                    'name': 'Done'
                                }
                            },
                            'priority': {
                                'self':
                                'https://jira.com/rest/api/2/priority/3',
                                'iconUrl':
                                'https://jira.com/images/icons/priorities/major.svg',
                                'name': 'Major',
                                'id': '3'
                            },
                            'issuetype': {
                                'self':
                                'https://jira.com/rest/api/2/issuetype/1',
                                'id': '1',
                                'description':
                                'A problem which impairs or prevents the functions of the product.',
                                'iconUrl':
                                'https://jira.com/secure/viewavatar?size=xsmall&avatarId=15923&avatarType=issuetype',
                                'name': 'Bug',
                                'subtask': False,
                                'avatarId': 15923
                            }
                        }
                    }
                }]
            }
            # Create a new Mock to imitate a Response

            mock_grab_linked_tickets.side_effect = [
                ConnectionError, ConnectionError, ConnectionError,
                ConnectionError
            ]
            with self.assertRaises(
                    ConnectionError
            ):  # testing 2 linked tickets so the asynchronous call is triggered
                TestExtractor(NAME, False).clean_json(dic)
            with self.assertRaises(
                    ConnectionError
            ):  # testing 2 linked tickets so the asynchronous call is triggered
                DeployExtractor(NAME, False).clean_json(dic)
            with self.assertRaises(
                    ConnectionError
            ):  # testing 2 linked tickets so the asynchronous call is triggered
                BarrosExtractor(NAME, False).clean_json(dic)
Пример #8
0
 def test_call_count(self) -> None:
     with patch('base_class.requests') as mock_requests:
         from deployment_log_UAT import DeployExtractor, NAME
         DeployExtractor(NAME, False).grab_tickets(dict())
         assert mock_requests.get.call_count == 2