# Path: libcloud_rest/api/providers.py
# def get_driver_instance(Driver, kwargs):
#     """
# 
#     @param Driver:
#     @param kwargs:
#     @return:
#     """
#     try:
#         json_data = json.dumps(kwargs)
#         driver_method = DriverMethod(Driver, '__init__')
#         return driver_method.invoke(json_data)
#     except MissingArguments, error:
#         str_repr = ', '.join([ARGS_TO_XHEADERS_DICT.get(arg, arg)
#                               for arg in error.arguments])
#         raise MissingHeadersError(headers=str_repr)
# 
# Path: tests/compute/drivers_patches.py
# PATCHES = {
#     DummyNodeDriver.__name__: ConnClassDriverPatch(ConnectionKey,
#                                                    ConnectionKey),
#     GoGridNodeDriver.__name__: ConnClassDriverPatch(None,
#                                                     GoGridMockHttp),
#     CloudStackNodeDriver.__name__: ConnClassDriverPatch(None,
#                                                         CloudStackMockHttp),
#     RackspaceNodeDriver.__name__: RackspaceComputePatch(),
# }
# 
# Path: tests/dns/drivers_patches.py
# PATCHES = {
#     RackspaceUSDNSDriver.__name__: RackspaceDNSPatch(),
#     ZerigoDNSDriver.__name__: ConnClassDriverPatch(None, ZerigoMockHttp),
#     LinodeDNSDriver.__name__: ConnClassDriverPatch(None, LinodeMockHttp),
# }
# 
# Path: tests/loadbalancer/drivers_patches.py
# PATCHES = {
#     RackspaceLBDriver.__name__: RackspaceLBPatch(),
# }
# 
# Path: tests/storage/drivers_patches.py
# PATCHES = {
#     CloudFilesUSStorageDriver.__name__: CloudFilesPatch(),
# }


import copy
from libcloud_rest.api.providers import get_driver_instance
from tests.compute.drivers_patches import PATCHES as COMPUTE_PATCHES
from tests.dns.drivers_patches import PATCHES as DNS_PATCHES
from tests.loadbalancer.drivers_patches import PATCHES as LB_PATCHES
from tests.storage.drivers_patches import PATCHES as STORAGE_PATCHES
# -*- coding:utf-8 -*-




def get_test_driver_instance(Driver, data):
    if Driver.__name__ not in DRIVERS_PATCHES:
        raise NotImplementedError('Unknown driver %s' % (Driver.__name__))
    Driver_copy = copy.deepcopy(Driver)
    driver_patch = DRIVERS_PATCHES[Driver_copy.__name__]
    driver_patch.pre_process(Driver_copy)
    driver_instance = get_driver_instance(Driver_copy, data)

# Path: libcloud_rest/api/providers.py
# def get_driver_instance(Driver, kwargs):
#     """
# 
#     @param Driver:
#     @param kwargs:
#     @return:
#     """
#     try:
#         json_data = json.dumps(kwargs)
#         driver_method = DriverMethod(Driver, '__init__')
#         return driver_method.invoke(json_data)
#     except MissingArguments, error:
#         str_repr = ', '.join([ARGS_TO_XHEADERS_DICT.get(arg, arg)
#                               for arg in error.arguments])
#         raise MissingHeadersError(headers=str_repr)
# 
# Path: tests/compute/drivers_patches.py
# PATCHES = {
#     DummyNodeDriver.__name__: ConnClassDriverPatch(ConnectionKey,
#                                                    ConnectionKey),
#     GoGridNodeDriver.__name__: ConnClassDriverPatch(None,
#                                                     GoGridMockHttp),
#     CloudStackNodeDriver.__name__: ConnClassDriverPatch(None,
#                                                         CloudStackMockHttp),
#     RackspaceNodeDriver.__name__: RackspaceComputePatch(),
# }
# 
# Path: tests/dns/drivers_patches.py
# PATCHES = {
#     RackspaceUSDNSDriver.__name__: RackspaceDNSPatch(),
#     ZerigoDNSDriver.__name__: ConnClassDriverPatch(None, ZerigoMockHttp),
#     LinodeDNSDriver.__name__: ConnClassDriverPatch(None, LinodeMockHttp),
# }
# 
# Path: tests/loadbalancer/drivers_patches.py
# PATCHES = {
#     RackspaceLBDriver.__name__: RackspaceLBPatch(),
# }
# 
# Path: tests/storage/drivers_patches.py
# PATCHES = {
#     CloudFilesUSStorageDriver.__name__: CloudFilesPatch(),
# }


# Path: tests/utils.py
import copy
from libcloud_rest.api.providers import get_driver_instance
from tests.compute.drivers_patches import PATCHES as COMPUTE_PATCHES
from tests.dns.drivers_patches import PATCHES as DNS_PATCHES
from tests.loadbalancer.drivers_patches import PATCHES as LB_PATCHES
from tests.storage.drivers_patches import PATCHES as STORAGE_PATCHES

# -*- coding:utf-8 -*-




def get_test_driver_instance(Driver, data):
    if Driver.__name__ not in DRIVERS_PATCHES:
        raise NotImplementedError('Unknown driver %s' % (Driver.__name__))
    Driver_copy = copy.deepcopy(Driver)
    driver_patch = DRIVERS_PATCHES[Driver_copy.__name__]
    driver_patch.pre_process(Driver_copy)
    driver_instance = get_driver_instance(Driver_copy, data)

    driver_patch.post_process(driver_instance)