# Path: tests/fake_model.py
# @contextmanager
# def define_fake_app():
#     """Creates and registers a fake Django app."""
# 
#     name = "app_" + str(uuid.uuid4()).replace("-", "")[:8]
# 
#     app_config_cls = type(
#         name + "Config",
#         (AppConfig,),
#         {"name": name, "path": os.path.dirname(__file__)},
#     )
# 
#     app_config = app_config_cls(name, "")
#     app_config.apps = apps
#     app_config.models = {}
# 
#     apps.app_configs[name] = app_config
#     sys.modules[name] = {}
# 
#     try:
#         yield app_config
#     finally:
#         del apps.app_configs[name]
#         del sys.modules[name]


import pytest
from django.contrib.postgres.signals import register_type_handlers
from django.db import connection
from .fake_model import define_fake_app




@pytest.fixture(scope="function", autouse=True)
def database_access(db):
    """Automatically enable database access for all tests."""

    # enable the hstore extension on our database because
    # our tests rely on it...
    with connection.schema_editor() as schema_editor:
        schema_editor.execute("CREATE EXTENSION IF NOT EXISTS hstore")
        register_type_handlers(schema_editor.connection)


@pytest.fixture
def fake_app():
    """Creates a fake Django app and deletes it at the end of the test."""


# Path: tests/fake_model.py
# @contextmanager
# def define_fake_app():
#     """Creates and registers a fake Django app."""
# 
#     name = "app_" + str(uuid.uuid4()).replace("-", "")[:8]
# 
#     app_config_cls = type(
#         name + "Config",
#         (AppConfig,),
#         {"name": name, "path": os.path.dirname(__file__)},
#     )
# 
#     app_config = app_config_cls(name, "")
#     app_config.apps = apps
#     app_config.models = {}
# 
#     apps.app_configs[name] = app_config
#     sys.modules[name] = {}
# 
#     try:
#         yield app_config
#     finally:
#         del apps.app_configs[name]
#         del sys.modules[name]


# Path: tests/conftest.py
import pytest
from django.contrib.postgres.signals import register_type_handlers
from django.db import connection
from .fake_model import define_fake_app





@pytest.fixture(scope="function", autouse=True)
def database_access(db):
    """Automatically enable database access for all tests."""

    # enable the hstore extension on our database because
    # our tests rely on it...
    with connection.schema_editor() as schema_editor:
        schema_editor.execute("CREATE EXTENSION IF NOT EXISTS hstore")
        register_type_handlers(schema_editor.connection)


@pytest.fixture
def fake_app():
    """Creates a fake Django app and deletes it at the end of the test."""


    with define_fake_app() as fake_app: