# Path: ckan_api_client/tests/functional/ckan_api/utils.py
# class CkanClient(object):
#     """Simple client for the Ckan API"""
# 
#     def __init__(self, url, api_key=None):
#         self.url = url
#         self.api_key = api_key
# 
#     def request(self, method, path, **kw):
#         kw = copy.deepcopy(kw)
#         if 'headers' not in kw:
#             kw['headers'] = CaseInsensitiveDict()
#         elif not isinstance(kw['headers'], CaseInsensitiveDict):
#             kw['headers'] = CaseInsensitiveDict(kw['headers'])
#         if 'data' in kw:
#             kw['data'] = json.dumps(kw['data'])
#             kw['headers']['Content-type'] = 'application/json'
#         if self.api_key is not None:
#             kw['headers']['Authorization'] = self.api_key
#         url = urlparse.urljoin(self.url, path)
#         return requests.request(method, url, **kw)
# 
#     def get(self, *a, **kw):
#         return self.request('get', *a, **kw)
# 
#     def post(self, *a, **kw):
#         return self.request('post', *a, **kw)


import cgi
import pytest
from .utils import CkanClient

    for res_id in expected_resources:
        expected_resource = expected_resources[res_id]
        actual_resource = actual_resources[res_id]
        for key_id in expected_resource:
            assert expected_resource[key_id] \
                == actual_resource[key_id]


def check_dataset_tags(expected, actual):
    # Tags have a lot of extra fields, we only care about some of them..
    expected_tags = sorted(x['name'] for x in expected)
    actual_tags = sorted(x['name'] for x in actual)
    assert actual_tags == expected_tags


@pytest.fixture(params=sorted(DUMMY_PACKAGES.keys()))
def dummy_package(request):
    return DUMMY_PACKAGES[request.param]


#  Actual test functions
# ------------------------------------------------------------


def test_simple_package_crud(ckan_instance):
    API_KEY = ckan_instance.get_sysadmin_api_key()

    with ckan_instance.serve():
        client = CkanClient(ckan_instance.server_url, api_key=API_KEY)

# Path: ckan_api_client/tests/functional/ckan_api/utils.py
# class CkanClient(object):
#     """Simple client for the Ckan API"""
# 
#     def __init__(self, url, api_key=None):
#         self.url = url
#         self.api_key = api_key
# 
#     def request(self, method, path, **kw):
#         kw = copy.deepcopy(kw)
#         if 'headers' not in kw:
#             kw['headers'] = CaseInsensitiveDict()
#         elif not isinstance(kw['headers'], CaseInsensitiveDict):
#             kw['headers'] = CaseInsensitiveDict(kw['headers'])
#         if 'data' in kw:
#             kw['data'] = json.dumps(kw['data'])
#             kw['headers']['Content-type'] = 'application/json'
#         if self.api_key is not None:
#             kw['headers']['Authorization'] = self.api_key
#         url = urlparse.urljoin(self.url, path)
#         return requests.request(method, url, **kw)
# 
#     def get(self, *a, **kw):
#         return self.request('get', *a, **kw)
# 
#     def post(self, *a, **kw):
#         return self.request('post', *a, **kw)


# Path: ckan_api_client/tests/functional/ckan_api/test_01_simple_crud.py
import cgi
import pytest
from .utils import CkanClient


    for res_id in expected_resources:
        expected_resource = expected_resources[res_id]
        actual_resource = actual_resources[res_id]
        for key_id in expected_resource:
            assert expected_resource[key_id] \
                == actual_resource[key_id]


def check_dataset_tags(expected, actual):
    # Tags have a lot of extra fields, we only care about some of them..
    expected_tags = sorted(x['name'] for x in expected)
    actual_tags = sorted(x['name'] for x in actual)
    assert actual_tags == expected_tags


@pytest.fixture(params=sorted(DUMMY_PACKAGES.keys()))
def dummy_package(request):
    return DUMMY_PACKAGES[request.param]


#  Actual test functions
# ------------------------------------------------------------


def test_simple_package_crud(ckan_instance):
    API_KEY = ckan_instance.get_sysadmin_api_key()

    with ckan_instance.serve():
        client = CkanClient(ckan_instance.server_url, api_key=API_KEY)

        anon_client = CkanClient(ckan_instance.server_url)