Ejemplo n.º 1
0
    def test_request_to_api_error(self):
        method = 'GET'
        action = 'DescribeInstances'
        params = dict(ImageId=self.mockModule.params['image_id'],
                      KeyName=self.mockModule.params['key_name'],
                      InstanceId=self.mockModule.params['instance_id'])

        with mock.patch('requests.get', self.mockRequestsInternalServerError):
            info = nifcloud.request_to_api(self.mockModule, method, action,
                                           params)

        self.assertEqual(info['status'], 500)
        self.assertEqual(
            etree.tostring(info['xml_body']),
            etree.tostring(etree.fromstring(self.xml['internalServerError'])))
Ejemplo n.º 2
0
    def test_get_api_error(self):
        method = 'GET'
        action = 'DescribeInstances'
        params = dict(ImageId=self.mockModule.params['image_id'],
                      KeyName=self.mockModule.params['key_name'],
                      InstanceId=self.mockModule.params['instance_id'])

        with mock.patch('requests.get', self.mockRequestsInternalServerError):
            info = nifcloud.request_to_api(self.mockModule, method, action,
                                           params)

        error_info = nifcloud.get_api_error(info['xml_body'])
        self.assertEqual(error_info['code'], 'Server.InternalError')
        self.assertEqual(error_info['message'],
                         'An error has occurred. Please try again later.')
Ejemplo n.º 3
0
    def test_request_to_api_post(self):
        method = 'POST'
        action = 'RunInstances'
        params = dict(ImageId=self.mockModule.params['image_id'],
                      KeyName=self.mockModule.params['key_name'],
                      InstanceId=self.mockModule.params['instance_id'])

        with mock.patch('requests.post', self.mockRequestsPostRunInstance):
            info = nifcloud.request_to_api(self.mockModule, method, action,
                                           params)

        self.assertEqual(info['status'], 200)
        self.assertEqual(info['xml_namespace'], dict(nc=self.xmlnamespace))
        self.assertEqual(
            etree.tostring(info['xml_body']),
            etree.tostring(etree.fromstring(self.xml['runInstance'])))