# Path: ckan_api_client/tests/utils/generate.py
# def generate_organization():
#     """
#     Generate a random organization object, with:
# 
#     - ``name``, random, example: ``"org-abc123"``
#     - ``title``, random, example: ``"Organization abc123"``
#     - ``description``, random
#     - ``image``, url pointing to a random-generated pic
#     """
# 
#     random_id = gen_random_id(10)
#     return {
#         "name": "org-{0}".format(random_id),  # Used as key
#         "title": "Organization {0}".format(random_id),
#         "description": "Description of organization {0}".format(random_id),
#         "image_url": gen_picture(random_id),
#         # "extras": [],
#         # "tags": [],
#     }
# 
# def generate_group():
#     """
#     Generate a random group object, with:
# 
#     - ``name``, random, example: ``"grp-abc123"``
#     - ``title``, random, example: ``"Group abc123"``
#     - ``description``, random
#     - ``image``, url pointing to a random-generated pic
#     """
# 
#     random_id = gen_random_id(10)
#     return {
#         "name": "grp-{0}".format(random_id),  # Used as key
#         "title": "Group {0}".format(random_id),
#         "description": "Description of group {0}".format(random_id),
#         "image_url": gen_picture(random_id),
#         # "extras": [],
#         # "tags": [],
#     }
# 
# 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": [],
#     }
# 
# def generate_id(length=10):
#     pool = string.ascii_lowercase + string.digits
#     return ''.join(random.choice(pool) for _ in xrange(length))


import random
from ckan_api_client.tests.utils.generate import (
    generate_organization, generate_group, generate_dataset, generate_id)
# from .utils.harvest_source import HarvestSource


def generate_data():
    organizations = generate_organizations(5)
    groups = generate_groups(10)

    datasets = generate_datasets(
        groups=groups, organizations=organizations, amount=20)

    return {
        'organization': organizations,
        'group': groups,
        'dataset': datasets,
    }


def generate_organizations(amount=10):
    organizations = {}
    for i in xrange(3):
        org = generate_organization()
        org['id'] = org['name'] = 'org-{0}'.format(generate_id())
        organizations[org['name']] = org
    return organizations


def generate_groups(amount=10):
    groups = {}
    for i in xrange(10):
        grp = generate_group()

# Path: ckan_api_client/tests/utils/generate.py
# def generate_organization():
#     """
#     Generate a random organization object, with:
# 
#     - ``name``, random, example: ``"org-abc123"``
#     - ``title``, random, example: ``"Organization abc123"``
#     - ``description``, random
#     - ``image``, url pointing to a random-generated pic
#     """
# 
#     random_id = gen_random_id(10)
#     return {
#         "name": "org-{0}".format(random_id),  # Used as key
#         "title": "Organization {0}".format(random_id),
#         "description": "Description of organization {0}".format(random_id),
#         "image_url": gen_picture(random_id),
#         # "extras": [],
#         # "tags": [],
#     }
# 
# def generate_group():
#     """
#     Generate a random group object, with:
# 
#     - ``name``, random, example: ``"grp-abc123"``
#     - ``title``, random, example: ``"Group abc123"``
#     - ``description``, random
#     - ``image``, url pointing to a random-generated pic
#     """
# 
#     random_id = gen_random_id(10)
#     return {
#         "name": "grp-{0}".format(random_id),  # Used as key
#         "title": "Group {0}".format(random_id),
#         "description": "Description of group {0}".format(random_id),
#         "image_url": gen_picture(random_id),
#         # "extras": [],
#         # "tags": [],
#     }
# 
# 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": [],
#     }
# 
# def generate_id(length=10):
#     pool = string.ascii_lowercase + string.digits
#     return ''.join(random.choice(pool) for _ in xrange(length))


# Path: ckan_api_client/tests/functional/client_sync/test_simple_harvesting_scenario.py
import random
from ckan_api_client.tests.utils.generate import (
    generate_organization, generate_group, generate_dataset, generate_id)

# from .utils.harvest_source import HarvestSource


def generate_data():
    organizations = generate_organizations(5)
    groups = generate_groups(10)

    datasets = generate_datasets(
        groups=groups, organizations=organizations, amount=20)

    return {
        'organization': organizations,
        'group': groups,
        'dataset': datasets,
    }


def generate_organizations(amount=10):
    organizations = {}
    for i in xrange(3):
        org = generate_organization()
        org['id'] = org['name'] = 'org-{0}'.format(generate_id())
        organizations[org['name']] = org
    return organizations


def generate_groups(amount=10):
    groups = {}
    for i in xrange(10):
        grp = generate_group()

        grp['id'] = grp['name'] = 'group-{0}'.format(generate_id())