# 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/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_group(group, expected):
#     """Make sure ``group`` matches the ``expected`` one"""
#     from ckan_api_client.objects import CkanGroup
#     return _check_obj(CkanGroup, group, expected)


import copy
import pytest
from ckan_api_client.exceptions import HTTPError
from ckan_api_client.tests.utils.strings import gen_random_id
from ckan_api_client.tests.utils.validation import check_group




@pytest.mark.xfail(run=False, reason='Work in progress')
def test_group_crud(ckan_client_ll):
    client = ckan_client_ll
    code = gen_random_id()
    group = {
        'name': 'group-{0}'.format(code),
        'title': 'Group {0}'.format(code),
    }
    created = client.post_group(group)
    check_group(created, group)
    group_id = created['id']

    # Retrieve & check
    retrieved = client.get_group(group_id)
    assert retrieved == created

    # Update & check
    updated = client.put_group({'id': group_id, 'title': 'My Group'})
    assert updated['name'] == group['name']
    assert updated['title'] == 'My Group'

    # Check differences
    expected = copy.deepcopy(created)
    expected['title'] = 'My Group'

# 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/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_group(group, expected):
#     """Make sure ``group`` matches the ``expected`` one"""
#     from ckan_api_client.objects import CkanGroup
#     return _check_obj(CkanGroup, group, expected)


# Path: ckan_api_client/tests/functional/client_lowlev/test_group_crud.py
import copy
import pytest
from ckan_api_client.exceptions import HTTPError
from ckan_api_client.tests.utils.strings import gen_random_id
from ckan_api_client.tests.utils.validation import check_group





@pytest.mark.xfail(run=False, reason='Work in progress')
def test_group_crud(ckan_client_ll):
    client = ckan_client_ll
    code = gen_random_id()
    group = {
        'name': 'group-{0}'.format(code),
        'title': 'Group {0}'.format(code),
    }
    created = client.post_group(group)
    check_group(created, group)
    group_id = created['id']

    # Retrieve & check
    retrieved = client.get_group(group_id)
    assert retrieved == created

    # Update & check
    updated = client.put_group({'id': group_id, 'title': 'My Group'})
    assert updated['name'] == group['name']
    assert updated['title'] == 'My Group'

    # Check differences
    expected = copy.deepcopy(created)
    expected['title'] = 'My Group'

    check_group(updated, expected)