# Path: papaye/tests/tools.py
# class FakeGRequestResponse():
# 
#     def __init__(self, status_code, content, url="https://fake/url/"):
#         self.status_code = status_code
#         self.content = content
#         self.url = url
# 
# class FakeRoute():
# 
#     def __init__(self, name):
#         self.name = name
# 
# def disable_cache(settings=None):
#     cache_settings = {
#         'cache.regions': 'pypi',
#         'cache.enabled': 'false',
#     }
#     if settings:
#         settings.update(cache_settings)
#     else:
#         settings = cache_settings
#     set_cache_regions_from_settings(settings)
#     return settings
# 
# def remove_blob_dir(blob_dir):
#     shutil.rmtree(blob_dir)
# 
# def set_database_connection(request, blob_dir=None, config=None):
#     if not blob_dir:
#         blob_dir = tempfile.mkdtemp('blobs')
#     conn = get_db_connection(blob_dir)
#     request._primary_zodb_conn = conn
#     if config:
#         import transaction
#         conn.root()['repository'] = {}
#         conn.root()['user'] = {}
#         transaction.commit()
#         config.registry._zodb_databases = {'': conn._db}
#     return blob_dir
# 
# def get_resource(*args):
#     return os.path.join(TEST_RESOURCES, *args)
# 
# Path: papaye/factories/models.py
# class RootFactory(factory.Factory):
#     class Meta:
# class PackageFactory(factory.Factory):
#     class Meta:
# class ReleaseFactory(factory.Factory):
#     class Meta:
# class ReleaseFileFactory(factory.Factory):
#     class Meta:


import types
import unittest
from mock import patch
from pyramid import testing
from pyramid.response import Response
from pyramid.threadlocal import get_current_request
from papaye.tests.tools import (
    FakeGRequestResponse,
    FakeRoute,
    disable_cache,
    remove_blob_dir,
    set_database_connection,
    get_resource,
)
from papaye.factories import models as factories
        from papaye.models import Package
        from papaye.models import Package
        from papaye.models import Package
        from papaye.models import Package
        from papaye.models import Package
        from papaye.models import Release
        from papaye.models import Release
        from papaye.models import Release
        from papaye.factories.root import repository_root_factory
        from papaye.models import Release
        from papaye.models import Release
        from papaye.models import Release, ReleaseFile
        from papaye.models import Release
        from papaye.models import Release, ReleaseFile
        from papaye.models import Release, ReleaseFile
        from papaye.models import ReleaseFile
        from papaye.models import ReleaseFile, STATUS
        from papaye.models import ReleaseFile, STATUS
        from papaye.models import ReleaseFile
        from papaye.models import User
        from papaye.models import User
        from papaye.factories.root import user_root_factory
        from papaye.models import User
    from papaye.models import SubscriptableBaseModel, Model
    from papaye.models import Model, ClonableModelMixin




class TestRoot(unittest.TestCase):

    def test_iter(self):
        package = factories.PackageFactory()
        root = package.__parent__

        result = iter(root)

        assert isinstance(result, types.GeneratorType)
        assert list(result) == [package, ]

    def test_get_index(self):
        package = factories.PackageFactory()
        root = package.__parent__

        result = root[0]

        assert result == package


class PackageTest(unittest.TestCase):

    def setUp(self):
        self.request = testing.DummyRequest(matched_route=FakeRoute('simple'))
        self.root = factories.RootFactory()
        self.request.root = self.root

# Path: papaye/tests/tools.py
# class FakeGRequestResponse():
# 
#     def __init__(self, status_code, content, url="https://fake/url/"):
#         self.status_code = status_code
#         self.content = content
#         self.url = url
# 
# class FakeRoute():
# 
#     def __init__(self, name):
#         self.name = name
# 
# def disable_cache(settings=None):
#     cache_settings = {
#         'cache.regions': 'pypi',
#         'cache.enabled': 'false',
#     }
#     if settings:
#         settings.update(cache_settings)
#     else:
#         settings = cache_settings
#     set_cache_regions_from_settings(settings)
#     return settings
# 
# def remove_blob_dir(blob_dir):
#     shutil.rmtree(blob_dir)
# 
# def set_database_connection(request, blob_dir=None, config=None):
#     if not blob_dir:
#         blob_dir = tempfile.mkdtemp('blobs')
#     conn = get_db_connection(blob_dir)
#     request._primary_zodb_conn = conn
#     if config:
#         import transaction
#         conn.root()['repository'] = {}
#         conn.root()['user'] = {}
#         transaction.commit()
#         config.registry._zodb_databases = {'': conn._db}
#     return blob_dir
# 
# def get_resource(*args):
#     return os.path.join(TEST_RESOURCES, *args)
# 
# Path: papaye/factories/models.py
# class RootFactory(factory.Factory):
#     class Meta:
# class PackageFactory(factory.Factory):
#     class Meta:
# class ReleaseFactory(factory.Factory):
#     class Meta:
# class ReleaseFileFactory(factory.Factory):
#     class Meta:


# Path: papaye/tests/test_models.py
import types
import unittest
from mock import patch
from pyramid import testing
from pyramid.response import Response
from pyramid.threadlocal import get_current_request
from papaye.tests.tools import (
    FakeGRequestResponse,
    FakeRoute,
    disable_cache,
    remove_blob_dir,
    set_database_connection,
    get_resource,
)
from papaye.factories import models as factories
        from papaye.models import Package
        from papaye.models import Package
        from papaye.models import Package
        from papaye.models import Package
        from papaye.models import Package
        from papaye.models import Release
        from papaye.models import Release
        from papaye.models import Release
        from papaye.factories.root import repository_root_factory
        from papaye.models import Release
        from papaye.models import Release
        from papaye.models import Release, ReleaseFile
        from papaye.models import Release
        from papaye.models import Release, ReleaseFile
        from papaye.models import Release, ReleaseFile
        from papaye.models import ReleaseFile
        from papaye.models import ReleaseFile, STATUS
        from papaye.models import ReleaseFile, STATUS
        from papaye.models import ReleaseFile
        from papaye.models import User
        from papaye.models import User
        from papaye.factories.root import user_root_factory
        from papaye.models import User
    from papaye.models import SubscriptableBaseModel, Model
    from papaye.models import Model, ClonableModelMixin





class TestRoot(unittest.TestCase):

    def test_iter(self):
        package = factories.PackageFactory()
        root = package.__parent__

        result = iter(root)

        assert isinstance(result, types.GeneratorType)
        assert list(result) == [package, ]

    def test_get_index(self):
        package = factories.PackageFactory()
        root = package.__parent__

        result = root[0]

        assert result == package


class PackageTest(unittest.TestCase):

    def setUp(self):
        self.request = testing.DummyRequest(matched_route=FakeRoute('simple'))
        self.root = factories.RootFactory()
        self.request.root = self.root

        self.blob_dir = set_database_connection(self.request)