# Path: libcloud_rest/api/versions.py

# 
# Path: libcloud_rest/application.py
# class LibcloudRestApp(object):
#     url_map = urls
#     storage_url = re.compile('/[v0-9.]+/storage/.*')
# 
#     def preprocess_request(self, request):
#         request_header_validator = valid.DictValidator({
#             'Content-Length': valid.IntegerValidator(max=MAX_BODY_LENGTH),
#             'Content-Type': valid.ConstValidator('application/json'),
#         })
#         if request.method in ['POST', 'PUT'] and\
#                 not re.match(self.storage_url, request.path):
#             request_header_validator(dict(request.headers))
#             #TODO: FIXME GK
#         if request.method == 'GET':
#             data = url_decode(request.query_string, cls=dict)
#             request.data = json.dumps(data)
# 
#     def dispatch_request(self, handler, request):
#         self.preprocess_request(request)
#         return handler(request)
# 
#     def make_response(self, *args):
#         """
#         Can take response or tuple of body, status, headers
#         """
#         rv, status, headers = args + (None, ) * (3 - len(args))
#         if rv is None:
#             raise ValueError('Empty response')
#         if not isinstance(rv, Response):
#             if isinstance(rv, basestring):
#                 rv = Response(rv, status, headers)
#                 status, headers = None, None
#             else:
#                 raise ValueError('Response return value does not supported')
#         if status is not None:
#             if isinstance(status, basestring):
#                 rv.status = status
#             else:
#                 rv.status_code = status
#         if headers is not None:
#             rv.headers.extend(headers)
# 
#         return rv
# 
#     def handle_exception(self, e, request):
#         #TODO: make this handler defined function
#         exc_type, exc_value, tb = sys.exc_info()
#         assert exc_value is e
# 
#         if issubclass(exc_type, LibcloudRestError):
#             error = e
#             logger.debug('Exception on %s [%s]' % (
#                 request.path,
#                 request.method),
#                 exc_info=(exc_type, exc_value, tb)
#             )
#         else:
#             error = InternalError(detail=str(e))
#             logger.error('Exception on %s [%s]' % (
#                 request.path,
#                 request.method),
#                 exc_info=(exc_type, exc_value, tb)
#             )
#         return self.make_response(error.to_json(), error.http_status_code)
# 
#     def __call__(self, environ, start_response):
#         request = Request(environ)
#         logger.debug('%s - %s %s' %
#                      (request.remote_addr, request.method, request.url))
#         urls = self.url_map.bind_to_environ(environ)
#         try:
#             handler, request.args = urls.match()
#             response = self.dispatch_request(handler, request)
#         except Exception, e:
#             response = self.handle_exception(e, request)
#         return response(environ, start_response)
# 
# Path: tests/file_fixtures.py
# FIXTURES_ROOT = {
#     'compute': 'compute/fixtures',
#     'storage': 'storage/fixtures',
#     'loadbalancer': 'loadbalancer/fixtures',
#     'dns': 'dns/fixtures',
# }
# FIXTURES_PREFIX_DIR = {
#     '0.10.1': 'v0_10',  # libcloud version:folder
#     '0.10.0': 'v0_10',
#     libcloud.__version__: 'v0_10',  # FIXME: remove in first release
# }
# class FileFixtures(object):
#     def __init__(self, fixtures_type, sub_dir=''):
#     def load(self, file):


import sys
import os
import unittest2
import httplib
    import simplejson as json
    import json
import libcloud
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse
from libcloud.test.compute.test_gogrid import GoGridMockHttp
from libcloud_rest.api.versions import versions as rest_versions
from libcloud_rest.application import LibcloudRestApp
from libcloud_rest.errors import NoSuchOperationError, ValidationError,\
    MalformedJSONError
from tests.file_fixtures import ComputeFixtures
        url = self.url_tmpl % ('nodes')
        headers = {'x-auth-user': 1, 'x-api-key': 2, 'x-dummy-creds': 3}
        resp = self.client.get(url, headers=headers)
        resp_data = json.loads(resp.data)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_list_nodes(self):
        url = self.url_tmpl % ('nodes')
        resp = self.client.get(url, headers=self.headers)
        resp_data = json.loads(resp.data)
        test_data = json.loads(self.fixtures.load('list_nodes.json'))
        self.assertEqual(resp.status_code, httplib.OK)
        self.assertItemsEqual(resp_data, test_data)

    def test_list_sizes(self):
        url = self.url_tmpl % ('sizes')
        resp = self.client.get(url, headers=self.headers)
        resp_data = json.loads(resp.data)
        test_data = json.loads(self.fixtures.load('list_sizes.json'))
        self.assertEqual(resp.status_code, httplib.OK)
        self.assertItemsEqual(resp_data, test_data)

    def test_list_images(self):
        url = self.url_tmpl % ('images')
        resp = self.client.get(url, headers=self.headers)
        resp_data = json.loads(resp.data)
        test_data = json.loads(self.fixtures.load('list_images.json'))
        self.assertEqual(resp.status_code, httplib.OK)
        self.assertItemsEqual(resp_data, test_data)
        location_id = 'gogrid/GSI-939ef909-84b8-4a2f-ad56-02ccd7da05ff.img'

# Path: libcloud_rest/api/versions.py

# 
# Path: libcloud_rest/application.py
# class LibcloudRestApp(object):
#     url_map = urls
#     storage_url = re.compile('/[v0-9.]+/storage/.*')
# 
#     def preprocess_request(self, request):
#         request_header_validator = valid.DictValidator({
#             'Content-Length': valid.IntegerValidator(max=MAX_BODY_LENGTH),
#             'Content-Type': valid.ConstValidator('application/json'),
#         })
#         if request.method in ['POST', 'PUT'] and\
#                 not re.match(self.storage_url, request.path):
#             request_header_validator(dict(request.headers))
#             #TODO: FIXME GK
#         if request.method == 'GET':
#             data = url_decode(request.query_string, cls=dict)
#             request.data = json.dumps(data)
# 
#     def dispatch_request(self, handler, request):
#         self.preprocess_request(request)
#         return handler(request)
# 
#     def make_response(self, *args):
#         """
#         Can take response or tuple of body, status, headers
#         """
#         rv, status, headers = args + (None, ) * (3 - len(args))
#         if rv is None:
#             raise ValueError('Empty response')
#         if not isinstance(rv, Response):
#             if isinstance(rv, basestring):
#                 rv = Response(rv, status, headers)
#                 status, headers = None, None
#             else:
#                 raise ValueError('Response return value does not supported')
#         if status is not None:
#             if isinstance(status, basestring):
#                 rv.status = status
#             else:
#                 rv.status_code = status
#         if headers is not None:
#             rv.headers.extend(headers)
# 
#         return rv
# 
#     def handle_exception(self, e, request):
#         #TODO: make this handler defined function
#         exc_type, exc_value, tb = sys.exc_info()
#         assert exc_value is e
# 
#         if issubclass(exc_type, LibcloudRestError):
#             error = e
#             logger.debug('Exception on %s [%s]' % (
#                 request.path,
#                 request.method),
#                 exc_info=(exc_type, exc_value, tb)
#             )
#         else:
#             error = InternalError(detail=str(e))
#             logger.error('Exception on %s [%s]' % (
#                 request.path,
#                 request.method),
#                 exc_info=(exc_type, exc_value, tb)
#             )
#         return self.make_response(error.to_json(), error.http_status_code)
# 
#     def __call__(self, environ, start_response):
#         request = Request(environ)
#         logger.debug('%s - %s %s' %
#                      (request.remote_addr, request.method, request.url))
#         urls = self.url_map.bind_to_environ(environ)
#         try:
#             handler, request.args = urls.match()
#             response = self.dispatch_request(handler, request)
#         except Exception, e:
#             response = self.handle_exception(e, request)
#         return response(environ, start_response)
# 
# Path: tests/file_fixtures.py
# FIXTURES_ROOT = {
#     'compute': 'compute/fixtures',
#     'storage': 'storage/fixtures',
#     'loadbalancer': 'loadbalancer/fixtures',
#     'dns': 'dns/fixtures',
# }
# FIXTURES_PREFIX_DIR = {
#     '0.10.1': 'v0_10',  # libcloud version:folder
#     '0.10.0': 'v0_10',
#     libcloud.__version__: 'v0_10',  # FIXME: remove in first release
# }
# class FileFixtures(object):
#     def __init__(self, fixtures_type, sub_dir=''):
#     def load(self, file):


# Path: tests/compute/test_gogrid.py
import sys
import os
import unittest2
import httplib
    import simplejson as json
    import json
import libcloud
from werkzeug.test import Client
from werkzeug.wrappers import BaseResponse
from libcloud.test.compute.test_gogrid import GoGridMockHttp
from libcloud_rest.api.versions import versions as rest_versions
from libcloud_rest.application import LibcloudRestApp
from libcloud_rest.errors import NoSuchOperationError, ValidationError,\
    MalformedJSONError
from tests.file_fixtures import ComputeFixtures

        url = self.url_tmpl % ('nodes')
        headers = {'x-auth-user': 1, 'x-api-key': 2, 'x-dummy-creds': 3}
        resp = self.client.get(url, headers=headers)
        resp_data = json.loads(resp.data)
        self.assertEqual(resp.status_code, httplib.OK)

    def test_list_nodes(self):
        url = self.url_tmpl % ('nodes')
        resp = self.client.get(url, headers=self.headers)
        resp_data = json.loads(resp.data)
        test_data = json.loads(self.fixtures.load('list_nodes.json'))
        self.assertEqual(resp.status_code, httplib.OK)
        self.assertItemsEqual(resp_data, test_data)

    def test_list_sizes(self):
        url = self.url_tmpl % ('sizes')
        resp = self.client.get(url, headers=self.headers)
        resp_data = json.loads(resp.data)
        test_data = json.loads(self.fixtures.load('list_sizes.json'))
        self.assertEqual(resp.status_code, httplib.OK)
        self.assertItemsEqual(resp_data, test_data)

    def test_list_images(self):
        url = self.url_tmpl % ('images')
        resp = self.client.get(url, headers=self.headers)
        resp_data = json.loads(resp.data)
        test_data = json.loads(self.fixtures.load('list_images.json'))
        self.assertEqual(resp.status_code, httplib.OK)
        self.assertItemsEqual(resp_data, test_data)
        location_id = 'gogrid/GSI-939ef909-84b8-4a2f-ad56-02ccd7da05ff.img'

        url = rest_versions[libcloud.__version__] + '/compute/gogrid/images'