# Path: lepo/excs.py
# class ErroneousParameters(Exception):
#     def __init__(self, error_map, parameters):
#         self.errors = error_map
#         self.parameters = parameters
# 
# class InvalidBodyContent(ValueError):
#     pass
# 
# class InvalidBodyFormat(ValueError):
#     pass
# 
# Path: lepo_tests/models.py
# class Pet(models.Model):
#     name = models.CharField(max_length=128)
#     tag = models.CharField(max_length=128, blank=True)
# 
# Path: lepo_tests/tests/utils.py
# def get_data_from_response(response, status=200):
#     if status and response.status_code != status:
#         raise ValueError(f'failed status check ({response.status_code} != expected {status})')  # pragma: no cover
#     return json.loads(response.content.decode('utf-8'))
# 
# Path: lepo_tests/utils.py
# def get_urlpatterns(handler_module, definition_file='swagger2/petstore-expanded.yaml'):
# def generate_urlconf_module(handler_style, version):
# def generate_urlconf_modules(handler_styles, versions):
# URLCONF_TEMPLATE = '''
# from lepo_tests.handlers import %(module)s
# from lepo_tests.utils import get_urlpatterns
# urlpatterns = get_urlpatterns(%(module)s, %(file)r)
# '''


import json
import django.conf
import pytest
from django.utils.crypto import get_random_string
from lepo.excs import ErroneousParameters, InvalidBodyContent, InvalidBodyFormat
from lepo_tests.models import Pet
from lepo_tests.tests.utils import get_data_from_response
from lepo_tests.utils import urlconf_map
    from django.urls import clear_url_caches, set_urlconf
    from django.core.urlresolvers import clear_url_caches, set_urlconf
    resp = client.patch(
        f'/api/pets/{pet1.id}',
        json.dumps(payload),
        content_type='application/json'
    )
    assert resp.status_code == 200

    pet_data = get_data_from_response(client.get('/api/pets'))[0]
    assert pet_data['name'] == 'worl'
    assert pet_data['tag'] == 'bunner'


@pytest.mark.django_db
def test_invalid_operation(client, api_urls):
    assert client.patch('/api/pets').status_code == 405


@pytest.mark.django_db
def test_invalid_body_format(client, api_urls):
    with pytest.raises(ErroneousParameters) as ei:
        client.post(
            '/api/pets',
            b'<pet></pet>',
            content_type='application/xml'
        )
    assert isinstance(ei.value.errors['pet'], InvalidBodyFormat)


@pytest.mark.django_db
def test_invalid_body_content(client, api_urls):

# Path: lepo/excs.py
# class ErroneousParameters(Exception):
#     def __init__(self, error_map, parameters):
#         self.errors = error_map
#         self.parameters = parameters
# 
# class InvalidBodyContent(ValueError):
#     pass
# 
# class InvalidBodyFormat(ValueError):
#     pass
# 
# Path: lepo_tests/models.py
# class Pet(models.Model):
#     name = models.CharField(max_length=128)
#     tag = models.CharField(max_length=128, blank=True)
# 
# Path: lepo_tests/tests/utils.py
# def get_data_from_response(response, status=200):
#     if status and response.status_code != status:
#         raise ValueError(f'failed status check ({response.status_code} != expected {status})')  # pragma: no cover
#     return json.loads(response.content.decode('utf-8'))
# 
# Path: lepo_tests/utils.py
# def get_urlpatterns(handler_module, definition_file='swagger2/petstore-expanded.yaml'):
# def generate_urlconf_module(handler_style, version):
# def generate_urlconf_modules(handler_styles, versions):
# URLCONF_TEMPLATE = '''
# from lepo_tests.handlers import %(module)s
# from lepo_tests.utils import get_urlpatterns
# urlpatterns = get_urlpatterns(%(module)s, %(file)r)
# '''


# Path: lepo_tests/tests/test_pet_api.py
import json
import django.conf
import pytest
from django.utils.crypto import get_random_string
from lepo.excs import ErroneousParameters, InvalidBodyContent, InvalidBodyFormat
from lepo_tests.models import Pet
from lepo_tests.tests.utils import get_data_from_response
from lepo_tests.utils import urlconf_map
    from django.urls import clear_url_caches, set_urlconf
    from django.core.urlresolvers import clear_url_caches, set_urlconf

    resp = client.patch(
        f'/api/pets/{pet1.id}',
        json.dumps(payload),
        content_type='application/json'
    )
    assert resp.status_code == 200

    pet_data = get_data_from_response(client.get('/api/pets'))[0]
    assert pet_data['name'] == 'worl'
    assert pet_data['tag'] == 'bunner'


@pytest.mark.django_db
def test_invalid_operation(client, api_urls):
    assert client.patch('/api/pets').status_code == 405


@pytest.mark.django_db
def test_invalid_body_format(client, api_urls):
    with pytest.raises(ErroneousParameters) as ei:
        client.post(
            '/api/pets',
            b'<pet></pet>',
            content_type='application/xml'
        )
    assert isinstance(ei.value.errors['pet'], InvalidBodyFormat)


@pytest.mark.django_db
def test_invalid_body_content(client, api_urls):

    with pytest.raises(ErroneousParameters) as ei: