# 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
    assert get_data_from_response(client.get('/api/pets')) == []


@pytest.mark.django_db
def test_optional_trailing_slash(client, api_urls):
    assert get_data_from_response(client.get('/api/pets/')) == []


@pytest.mark.django_db
@pytest.mark.parametrize('with_tag', (False, True))
def test_post_pet(client, api_urls, with_tag):
    payload = {
        'name': get_random_string(15),
    }
    if with_tag:
        payload['tag'] = get_random_string(15)

    pet = get_data_from_response(
        client.post(
            '/api/pets',
            json.dumps(payload),
            content_type='application/json'
        )
    )
    assert pet['name'] == payload['name']
    assert pet['id']
    if with_tag:
        assert pet['tag'] == payload['tag']

    # Test we can get the pet from the API now

# 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

    assert get_data_from_response(client.get('/api/pets')) == []


@pytest.mark.django_db
def test_optional_trailing_slash(client, api_urls):
    assert get_data_from_response(client.get('/api/pets/')) == []


@pytest.mark.django_db
@pytest.mark.parametrize('with_tag', (False, True))
def test_post_pet(client, api_urls, with_tag):
    payload = {
        'name': get_random_string(15),
    }
    if with_tag:
        payload['tag'] = get_random_string(15)

    pet = get_data_from_response(
        client.post(
            '/api/pets',
            json.dumps(payload),
            content_type='application/json'
        )
    )
    assert pet['name'] == payload['name']
    assert pet['id']
    if with_tag:
        assert pet['tag'] == payload['tag']

    # Test we can get the pet from the API now

    assert get_data_from_response(client.get('/api/pets')) == [pet]