# Path: papaye/models.py
# class Model(Persistent):
# 
#     def __repr__(self):
#         return '<{}.{} "{}" at {}>'.format(
#             self.__module__,
#             self.__class__.__name__,
#             self.__name__,
#             id(self)
#         )
# 
#     def __init__(self, *args, **kwargs):
#         # Breaks the super() calls chain
#         pass
# 
#     def __getattr__(self, attribute):
#         # Breaks the super() calls chain
#         return self.__getattribute__(attribute)
# 
# Path: papaye/scripts/initialize.py
# def create_app_root(dbconn):
#     zodb_root = get_database_root(dbconn)
#     manager = get_manager(None)
#     if manager.key not in zodb_root:
#         zodb_root[manager.key] = {manager.package_name: manager.sw_version}
#     if '{}_root'.format(APP_NAME) not in zodb_root:
#         zodb_root['{}_root'.format(APP_NAME)] = Root('{}_root'.format(APP_NAME))
#     if 'user' not in zodb_root['{}_root'.format(APP_NAME)]:
#         zodb_root['{}_root'.format(APP_NAME)]['user'] = Root('user_root')
#     if 'repository' not in zodb_root['{}_root'.format(APP_NAME)]:
#         zodb_root['{}_root'.format(APP_NAME)]['repository'] = Root(
#             'repository_root'
#         )
# 
# Path: papaye/serializers.py
# class Serializer(object):
#     fields = None
#     _schema = None
# 
#     def __new__(cls, *args, **kwargs):
#         attributes = {attribute_name: getattr(cls, attribute_name) for attribute_name in dir(cls)}
#         cls.fields = {attribute_name: attribute for attribute_name, attribute in attributes.items()
#                       if isinstance(attribute, colander.SchemaNode)}
#         return super(Serializer, cls).__new__(cls)
# 
#     @property
#     def schema(self):
#         if self._schema is None:
#             schema = colander.SchemaNode(colander.Mapping())
#             nodes = {name: node for name, node in self.fields.items() if isinstance(node, colander.SchemaNode)}
#             if nodes:
#                 for name, node in nodes.items():
#                     node.name = name
#                     schema.add(node)
#                 self._schema = schema
#         return self._schema
# 
#     def serialize(self, obj):
#         data = self.get_data(obj)
#         cstruct = self.schema.serialize(data)
#         return self.schema.deserialize(cstruct)
# 
#     def get_data(self, obj):
#         return {key: getattr(obj, key) for key in self.fields.keys() if getattr(obj, key, None) is not None}


import colander
import os
import shutil
import tempfile
        import transaction
from pyramid import testing
from pyramid_beaker import set_cache_regions_from_settings
from ZODB.blob import BlobStorage
from ZODB.DB import DB
from ZODB.MappingStorage import MappingStorage
from papaye.models import Model
from papaye.scripts.initialize import create_app_root
from papaye.serializers import Serializer
    def __init__(self, name):
        self.name = name


class FakeProducer(object):

    def __init__(self, *args, **kwargs):
        pass

    def send_pyobj(self, val):
        pass


def create_test_app(config):
    """ This function returns a Pyramid WSGI application for functional tests.
    """
    config.include('pyramid_jinja2')
    set_cache_regions_from_settings(config.registry.settings)
    config.add_jinja2_search_path("papaye:templates")
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('simple', '/simple/*traverse', factory='papaye:root_factory')
    config.scan()
    return config.make_wsgi_app()


def get_db_connection(blob_dir):
    storage = MappingStorage('test')
    blob_storage = BlobStorage(blob_dir, storage)
    db = DB(blob_storage)
    conn = db.open()

# Path: papaye/models.py
# class Model(Persistent):
# 
#     def __repr__(self):
#         return '<{}.{} "{}" at {}>'.format(
#             self.__module__,
#             self.__class__.__name__,
#             self.__name__,
#             id(self)
#         )
# 
#     def __init__(self, *args, **kwargs):
#         # Breaks the super() calls chain
#         pass
# 
#     def __getattr__(self, attribute):
#         # Breaks the super() calls chain
#         return self.__getattribute__(attribute)
# 
# Path: papaye/scripts/initialize.py
# def create_app_root(dbconn):
#     zodb_root = get_database_root(dbconn)
#     manager = get_manager(None)
#     if manager.key not in zodb_root:
#         zodb_root[manager.key] = {manager.package_name: manager.sw_version}
#     if '{}_root'.format(APP_NAME) not in zodb_root:
#         zodb_root['{}_root'.format(APP_NAME)] = Root('{}_root'.format(APP_NAME))
#     if 'user' not in zodb_root['{}_root'.format(APP_NAME)]:
#         zodb_root['{}_root'.format(APP_NAME)]['user'] = Root('user_root')
#     if 'repository' not in zodb_root['{}_root'.format(APP_NAME)]:
#         zodb_root['{}_root'.format(APP_NAME)]['repository'] = Root(
#             'repository_root'
#         )
# 
# Path: papaye/serializers.py
# class Serializer(object):
#     fields = None
#     _schema = None
# 
#     def __new__(cls, *args, **kwargs):
#         attributes = {attribute_name: getattr(cls, attribute_name) for attribute_name in dir(cls)}
#         cls.fields = {attribute_name: attribute for attribute_name, attribute in attributes.items()
#                       if isinstance(attribute, colander.SchemaNode)}
#         return super(Serializer, cls).__new__(cls)
# 
#     @property
#     def schema(self):
#         if self._schema is None:
#             schema = colander.SchemaNode(colander.Mapping())
#             nodes = {name: node for name, node in self.fields.items() if isinstance(node, colander.SchemaNode)}
#             if nodes:
#                 for name, node in nodes.items():
#                     node.name = name
#                     schema.add(node)
#                 self._schema = schema
#         return self._schema
# 
#     def serialize(self, obj):
#         data = self.get_data(obj)
#         cstruct = self.schema.serialize(data)
#         return self.schema.deserialize(cstruct)
# 
#     def get_data(self, obj):
#         return {key: getattr(obj, key) for key in self.fields.keys() if getattr(obj, key, None) is not None}


# Path: papaye/tests/tools.py
import colander
import os
import shutil
import tempfile
        import transaction
from pyramid import testing
from pyramid_beaker import set_cache_regions_from_settings
from ZODB.blob import BlobStorage
from ZODB.DB import DB
from ZODB.MappingStorage import MappingStorage
from papaye.models import Model
from papaye.scripts.initialize import create_app_root
from papaye.serializers import Serializer

    def __init__(self, name):
        self.name = name


class FakeProducer(object):

    def __init__(self, *args, **kwargs):
        pass

    def send_pyobj(self, val):
        pass


def create_test_app(config):
    """ This function returns a Pyramid WSGI application for functional tests.
    """
    config.include('pyramid_jinja2')
    set_cache_regions_from_settings(config.registry.settings)
    config.add_jinja2_search_path("papaye:templates")
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_route('simple', '/simple/*traverse', factory='papaye:root_factory')
    config.scan()
    return config.make_wsgi_app()


def get_db_connection(blob_dir):
    storage = MappingStorage('test')
    blob_storage = BlobStorage(blob_dir, storage)
    db = DB(blob_storage)
    conn = db.open()

    create_app_root(conn)