Пример #1
0
    def test_aws_health_try_catch(self, session_mock, client_mock,
                                  describe_events_mock):
        region = self.region_mock
        services = self.ec2_mock
        codes = "200"
        api = self.health_mock

        mock_response = {
            'events': [
                {
                    'arn': 'arn:health:1212',
                    'service': 'health',
                    'eventTypeCode': '200',
                    'eventTypeCategory': 'accountNotification',
                    'region': 'mock_region',
                    'statusCode': 'open',
                },
            ],
        }

        self.boto3_mock = Mock()
        session_mock.return_value = "session for client mocked "

        # handling the try code block
        describe_events_mock.return_value = mock_response
        instance = AbstractionLayer(region)
        instance.aws_health(api, region, services, codes)
Пример #2
0
    def test_aws_health_exception_handling(self, session_mock, client_mock):

        region = self.region_mock
        services = ["ec2_mock", "s3_mock", "sts_mock"]
        codes = ["200", "302", "301"]

        with self.assertRaises(SystemExit) as sys_exit:
            self.boto3_mock = Mock()
            session_mock.return_value = "boto3 client mocked "

            # handling the try code block
            instance = AbstractionLayer(region)
            instance.aws_health("health_mock", region, services, codes)

        self.assertEqual(sys_exit.exception.code, 1)