# Path: ckan_api_client/exceptions.py
# class HTTPError(Exception):
#     """
#     Exception representing an HTTP response error.
# 
#     .. attribute:: status_code
# 
#         HTTP status code
# 
#     .. attribute:: message
# 
#         Informative error message, if available
#     """
# 
#     def __init__(self, status_code, message, original=None):
#         self.args = (status_code, message, original)
# 
#     @property
#     def status_code(self):
#         return self.args[0]
# 
#     @property
#     def message(self):
#         return self.args[1]
# 
#     @property
#     def original(self):
#         return self.args[2]
# 
#     def __str__(self):
#         return ("{0}({1!r}, {2!r}, original={3!r})"
#                 .format(self.__class__.__name__,
#                         self.status_code, self.message, self.original))
# 
# Path: ckan_api_client/tests/utils/generate.py
# def generate_dataset():
#     """
#     Generate a dataset, populated with random data.
# 
#     **Fields:**
# 
#     - ``name`` -- random string, in the form ``dataset-{random}``
#     - ``title`` -- random string, in the form ``Dataset {random}``
# 
#     - ``author`` -- random-generated name
#     - ``author_email`` -- random-generated email address
#     - ``license_id`` -- random license id. One of ``cc-by``, ``cc-zero``,
#       ``cc-by-sa`` or ``notspecified``.
#     - ``maintainer`` -- random-generated name
#     - ``maintainer_email`` -- random-generated email address
#     - ``notes`` -- random string, containing some markdown
#     - ``owner_org`` -- set to None
#     - ``private`` -- Fixed to ``False``
#     - ``tags`` -- random list of tags (strings)
#     - ``type`` -- fixed string: ``"dataset"``
#     - ``url`` -- random url of dataset on an "external source"
# 
#     - ``extras`` -- dictionary containing random key / value pairs
#     - ``groups`` -- empty list
#     - ``resources`` -- list of random resources
#     - ``relationships`` -- empty list
# 
#     .. note::
#         The ``owner_org`` and ``groups`` fields will be blank,
#         as they must match with existing groups / organizations
#         and we don't have access to database from here (nor
#         is it in the scope of this function!)
#     """
# 
#     random_id = gen_random_id(15)
#     license_id = random.choice((
#         'cc-by', 'cc-zero', 'cc-by-sa', 'notspecified'))
#     resources = []
#     for i in xrange(random.randint(1, 8)):
#         resources.append(generate_resource())
#     return {
#         # ------------------------------------------------------------
#         # WARNING! This is the **internal** id of the external
#         # service, which will need to be moved to
#         # dataset['extras']['_harvest_source_id']
#         # ------------------------------------------------------------
#         # "id": random_id,
# 
#         # Name should be taken as a "suggestion": in case of naming conflict
#         # with an existing dataset, it just be changed (todo: how?)
#         "name": "dataset-{0}".format(random_id),
# 
#         "title": "Dataset {0}".format(random_id),
#         "url": "http://www.example.com/dataset/{0}".format(random_id),
#         "type": "dataset",
# 
#         "maintainer_email": "maintainer-{0}@example.com".format(random_id),
#         "maintainer": "Maintainer {0}".format(random_id),
# 
#         "author_email": "author-{0}@example.com".format(random_id),
#         "author": "Author {0}".format(random_id),
# 
#         "license_id": license_id,
# 
#         "private": False,
#         "notes": "Notes for **dataset** {0}.".format(random_id),
# 
#         # "state": "active",  # automatic
# 
#         # Let's generate some tags
#         "tags": generate_tags(random.randint(0, 10)),
# 
#         # Let's put some random stuff in here..
#         "extras": generate_extras(random.randint(0, 30)),
# 
#         # Some dummy resources
#         "resources": resources,
# 
#         # Need to be randomized later, to match existing groups
#         "groups": [],
# 
#         # Need to be randomized later, to match existing orgs
#         "owner_org": None,
# 
#         # WTF is this thing?
#         "relationships": [],
#     }
# 
# Path: ckan_api_client/tests/utils/strings.py
# def gen_random_id(length=10):
#     """Generate a random id, made of lowercase ascii letters + digits"""
#     charset = string.ascii_lowercase + string.digits
#     return ''.join(random.choice(charset) for _ in xrange(length))
# 
# Path: ckan_api_client/tests/utils/validation.py
# def check_dataset(dataset, expected):
#     """Make sure ``dataset`` matches the ``expected`` one"""
#     from ckan_api_client.objects import CkanDataset
#     return _check_obj(CkanDataset, dataset, expected)


import datetime
import copy
import pytest
from ckan_api_client.exceptions import HTTPError
from ckan_api_client.tests.utils.generate import generate_dataset
from ckan_api_client.tests.utils.strings import gen_random_id
from ckan_api_client.tests.utils.validation import check_dataset
"""
Tests to pin-point exact behavior of datasets CRUD, in particular
updates.
"""





def test_dataset_simple_crud(ckan_client_ll):
    # Let's try creating a dataset

    now = datetime.datetime.now()
    now_str = now.strftime('%F %T')

    _dataset = {

# Path: ckan_api_client/exceptions.py
# class HTTPError(Exception):
#     """
#     Exception representing an HTTP response error.
# 
#     .. attribute:: status_code
# 
#         HTTP status code
# 
#     .. attribute:: message
# 
#         Informative error message, if available
#     """
# 
#     def __init__(self, status_code, message, original=None):
#         self.args = (status_code, message, original)
# 
#     @property
#     def status_code(self):
#         return self.args[0]
# 
#     @property
#     def message(self):
#         return self.args[1]
# 
#     @property
#     def original(self):
#         return self.args[2]
# 
#     def __str__(self):
#         return ("{0}({1!r}, {2!r}, original={3!r})"
#                 .format(self.__class__.__name__,
#                         self.status_code, self.message, self.original))
# 
# Path: ckan_api_client/tests/utils/generate.py
# def generate_dataset():
#     """
#     Generate a dataset, populated with random data.
# 
#     **Fields:**
# 
#     - ``name`` -- random string, in the form ``dataset-{random}``
#     - ``title`` -- random string, in the form ``Dataset {random}``
# 
#     - ``author`` -- random-generated name
#     - ``author_email`` -- random-generated email address
#     - ``license_id`` -- random license id. One of ``cc-by``, ``cc-zero``,
#       ``cc-by-sa`` or ``notspecified``.
#     - ``maintainer`` -- random-generated name
#     - ``maintainer_email`` -- random-generated email address
#     - ``notes`` -- random string, containing some markdown
#     - ``owner_org`` -- set to None
#     - ``private`` -- Fixed to ``False``
#     - ``tags`` -- random list of tags (strings)
#     - ``type`` -- fixed string: ``"dataset"``
#     - ``url`` -- random url of dataset on an "external source"
# 
#     - ``extras`` -- dictionary containing random key / value pairs
#     - ``groups`` -- empty list
#     - ``resources`` -- list of random resources
#     - ``relationships`` -- empty list
# 
#     .. note::
#         The ``owner_org`` and ``groups`` fields will be blank,
#         as they must match with existing groups / organizations
#         and we don't have access to database from here (nor
#         is it in the scope of this function!)
#     """
# 
#     random_id = gen_random_id(15)
#     license_id = random.choice((
#         'cc-by', 'cc-zero', 'cc-by-sa', 'notspecified'))
#     resources = []
#     for i in xrange(random.randint(1, 8)):
#         resources.append(generate_resource())
#     return {
#         # ------------------------------------------------------------
#         # WARNING! This is the **internal** id of the external
#         # service, which will need to be moved to
#         # dataset['extras']['_harvest_source_id']
#         # ------------------------------------------------------------
#         # "id": random_id,
# 
#         # Name should be taken as a "suggestion": in case of naming conflict
#         # with an existing dataset, it just be changed (todo: how?)
#         "name": "dataset-{0}".format(random_id),
# 
#         "title": "Dataset {0}".format(random_id),
#         "url": "http://www.example.com/dataset/{0}".format(random_id),
#         "type": "dataset",
# 
#         "maintainer_email": "maintainer-{0}@example.com".format(random_id),
#         "maintainer": "Maintainer {0}".format(random_id),
# 
#         "author_email": "author-{0}@example.com".format(random_id),
#         "author": "Author {0}".format(random_id),
# 
#         "license_id": license_id,
# 
#         "private": False,
#         "notes": "Notes for **dataset** {0}.".format(random_id),
# 
#         # "state": "active",  # automatic
# 
#         # Let's generate some tags
#         "tags": generate_tags(random.randint(0, 10)),
# 
#         # Let's put some random stuff in here..
#         "extras": generate_extras(random.randint(0, 30)),
# 
#         # Some dummy resources
#         "resources": resources,
# 
#         # Need to be randomized later, to match existing groups
#         "groups": [],
# 
#         # Need to be randomized later, to match existing orgs
#         "owner_org": None,
# 
#         # WTF is this thing?
#         "relationships": [],
#     }
# 
# Path: ckan_api_client/tests/utils/strings.py
# def gen_random_id(length=10):
#     """Generate a random id, made of lowercase ascii letters + digits"""
#     charset = string.ascii_lowercase + string.digits
#     return ''.join(random.choice(charset) for _ in xrange(length))
# 
# Path: ckan_api_client/tests/utils/validation.py
# def check_dataset(dataset, expected):
#     """Make sure ``dataset`` matches the ``expected`` one"""
#     from ckan_api_client.objects import CkanDataset
#     return _check_obj(CkanDataset, dataset, expected)


# Path: ckan_api_client/tests/functional/client_lowlev/test_dataset_crud.py
import datetime
import copy
import pytest
from ckan_api_client.exceptions import HTTPError
from ckan_api_client.tests.utils.generate import generate_dataset
from ckan_api_client.tests.utils.strings import gen_random_id
from ckan_api_client.tests.utils.validation import check_dataset

"""
Tests to pin-point exact behavior of datasets CRUD, in particular
updates.
"""





def test_dataset_simple_crud(ckan_client_ll):
    # Let's try creating a dataset

    now = datetime.datetime.now()
    now_str = now.strftime('%F %T')

    _dataset = {

        'name': 'dataset-{0}'.format(gen_random_id()),