# 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
# `urlconf_map` is a map of dynamically generated URLconf modules
# that don't actually exist on disk, and this fixture ensures all
# tests in this module which request the `api_urls` fixture (defined below)
# actually get parametrized to include all versions in the map.


def pytest_generate_tests(metafunc):
    if 'api_urls' in metafunc.fixturenames:
        module_names = [m.__name__ for m in urlconf_map.values()]
        metafunc.parametrize('api_urls', module_names, indirect=True)


@pytest.fixture
def api_urls(request):
    urls = request.param
    original_urlconf = django.conf.settings.ROOT_URLCONF
    django.conf.settings.ROOT_URLCONF = urls
    clear_url_caches()
    set_urlconf(None)

    def restore():
        django.conf.settings.ROOT_URLCONF = original_urlconf
        clear_url_caches()
        set_urlconf(None)

    request.addfinalizer(restore)


@pytest.mark.django_db
def test_get_empty_list(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

# `urlconf_map` is a map of dynamically generated URLconf modules
# that don't actually exist on disk, and this fixture ensures all
# tests in this module which request the `api_urls` fixture (defined below)
# actually get parametrized to include all versions in the map.


def pytest_generate_tests(metafunc):
    if 'api_urls' in metafunc.fixturenames:
        module_names = [m.__name__ for m in urlconf_map.values()]
        metafunc.parametrize('api_urls', module_names, indirect=True)


@pytest.fixture
def api_urls(request):
    urls = request.param
    original_urlconf = django.conf.settings.ROOT_URLCONF
    django.conf.settings.ROOT_URLCONF = urls
    clear_url_caches()
    set_urlconf(None)

    def restore():
        django.conf.settings.ROOT_URLCONF = original_urlconf
        clear_url_caches()
        set_urlconf(None)

    request.addfinalizer(restore)


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

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