Esempio n. 1
0
    def test_cloud_exception(self):

        message = {
            'code': '500',
            'message': 'Bad Request',
            'values': {'invalid_attribute':'data'}
            }

        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(cloud_exp.message, 'Bad Request')
        self.assertEqual(cloud_exp.error, '500')
        self.assertEqual(cloud_exp.data['invalid_attribute'], 'data')

        message = {
            'code': '500',
            'message': {'value': 'Bad Request\nRequest:34875\nTime:1999-12-31T23:59:59-23:59'},
            'values': {'invalid_attribute':'data'}
            }

        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(cloud_exp.message, 'Bad Request')
        self.assertEqual(cloud_exp.error, '500')
        self.assertEqual(cloud_exp.data['invalid_attribute'], 'data')

        message = {
            'code': '500',
            'message': {'value': 'Bad Request\nRequest:34875'},
            'values': {'invalid_attribute':'data'}
            }

        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(cloud_exp.message, 'Bad Request')
        self.assertEqual(cloud_exp.request_id, '34875')
        self.assertEqual(cloud_exp.error, '500')
        self.assertEqual(cloud_exp.data['invalid_attribute'], 'data')

        message = {}
        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(cloud_exp.message, None)
        self.assertEqual(cloud_exp.error, None)

        message = ('{\r\n  "odata.metadata":"https://account.region.batch.azure.com/$metadata#'
                   'Microsoft.Azure.Batch.Protocol.Entities.Container.errors/@Element","code":'
                   '"InvalidHeaderValue","message":{\r\n    "lang":"en-US","value":"The value '
                   'for one of the HTTP headers is not in the correct format.\\nRequestId:5f4c1f05-'
                   '603a-4495-8e80-01f776310bbd\\nTime:2016-01-04T22:12:33.9245931Z"\r\n  },'
                   '"values":[\r\n    {\r\n      "key":"HeaderName","value":"Content-Type"\r\n    }'
                   ',{\r\n      "key":"HeaderValue","value":"application/json; odata=minimalmetadata;'
                   ' charset=utf-8"\r\n    }\r\n  ]\r\n}')
        message = json.loads(message)
        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(
            cloud_exp.message,
            "The value for one of the HTTP headers is not in the correct format.")
Esempio n. 2
0
    def test_cloud_exception(self):

        message = {
            'code': '500',
            'message': 'Bad Request',
            'values': {
                'invalid_attribute': 'data'
            }
        }

        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(cloud_exp.message, 'Bad Request')
        self.assertEqual(cloud_exp.error, '500')
        self.assertEqual(cloud_exp.data['invalid_attribute'], 'data')

        message = {
            'code': '500',
            'message': {
                'value':
                'Bad Request\nRequest:34875\nTime:1999-12-31T23:59:59-23:59'
            },
            'values': {
                'invalid_attribute': 'data'
            }
        }

        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(cloud_exp.message, 'Bad Request')
        self.assertEqual(cloud_exp.error, '500')
        self.assertEqual(cloud_exp.data['invalid_attribute'], 'data')

        message = {
            'code': '500',
            'message': {
                'value': 'Bad Request\nRequest:34875'
            },
            'values': {
                'invalid_attribute': 'data'
            }
        }

        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(cloud_exp.message, 'Bad Request')
        self.assertEqual(cloud_exp.request_id, '34875')
        self.assertEqual(cloud_exp.error, '500')
        self.assertEqual(cloud_exp.data['invalid_attribute'], 'data')

        message = {}
        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(cloud_exp.message, None)
        self.assertEqual(cloud_exp.error, None)

        message = (
            '{\r\n  "odata.metadata":"https://account.region.batch.azure.com/$metadata#'
            'Microsoft.Azure.Batch.Protocol.Entities.Container.errors/@Element","code":'
            '"InvalidHeaderValue","message":{\r\n    "lang":"en-US","value":"The value '
            'for one of the HTTP headers is not in the correct format.\\nRequestId:5f4c1f05-'
            '603a-4495-8e80-01f776310bbd\\nTime:2016-01-04T22:12:33.9245931Z"\r\n  },'
            '"values":[\r\n    {\r\n      "key":"HeaderName","value":"Content-Type"\r\n    }'
            ',{\r\n      "key":"HeaderValue","value":"application/json; odata=minimalmetadata;'
            ' charset=utf-8"\r\n    }\r\n  ]\r\n}')
        message = json.loads(message)
        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(
            cloud_exp.message,
            "The value for one of the HTTP headers is not in the correct format."
        )

        message = {
            "code":
            "BadArgument",
            "message":
            "The provided database 'foo' has an invalid username.",
            "target":
            "query",
            "details": [{
                "code": "301",
                "target": "$search",
                "message": "$search query option not supported",
            }],
            "innererror": {
                "customKey": "customValue"
            },
            "additionalInfo": [{
                "type": "SomeErrorType",
                "info": {
                    "customKey": "customValue"
                }
            }]
        }
        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(cloud_exp.target, 'query')
        self.assertEqual(cloud_exp.details[0].target, '$search')
        self.assertEqual(cloud_exp.innererror['customKey'], 'customValue')
        self.assertEqual(cloud_exp.additionalInfo[0].type, 'SomeErrorType')
        self.assertEqual(cloud_exp.additionalInfo[0].info['customKey'],
                         'customValue')
        self.assertIn('customValue', str(cloud_exp))

        message = {
            "code":
            "BadArgument",
            "message":
            "The provided database 'foo' has an invalid username.",
            "target":
            "query",
            "details": [{
                "code":
                "301",
                "target":
                "$search",
                "message":
                "$search query option not supported",
                "additionalInfo": [{
                    "type": "PolicyViolation",
                    "info": {
                        "policyDefinitionDisplayName": "Allowed locations",
                        "policyAssignmentParameters": {
                            "listOfAllowedLocations": {
                                "value": ["westus"]
                            }
                        }
                    }
                }]
            }],
            "additionalInfo": [{
                "type": "SomeErrorType",
                "info": {
                    "customKey": "customValue"
                }
            }]
        }
        cloud_exp = self._d(CloudErrorData(), message)
        self.assertEqual(cloud_exp.target, 'query')
        self.assertEqual(cloud_exp.details[0].target, '$search')
        self.assertEqual(cloud_exp.additionalInfo[0].type, 'SomeErrorType')
        self.assertEqual(cloud_exp.additionalInfo[0].info['customKey'],
                         'customValue')
        self.assertEqual(cloud_exp.details[0].additionalInfo[0].type,
                         'PolicyViolation')
        self.assertEqual(
            cloud_exp.details[0].additionalInfo[0].
            info['policyDefinitionDisplayName'], 'Allowed locations')
        self.assertEqual(
            cloud_exp.details[0].additionalInfo[0].
            info['policyAssignmentParameters']['listOfAllowedLocations']
            ['value'][0], 'westus')
        self.assertIn('customValue', str(cloud_exp))