Ejemplo n.º 1
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 = niftycloud.request_to_api(self.mockModule, method, action,
                                             params)

        error_info = niftycloud.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.º 2
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 = niftycloud.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.º 3
0
	def test_request_to_api_get(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.mockRequestsGetDescribeInstance):
			info = niftycloud.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['describeInstance'])))