# 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
# 
# 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 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)
#     return conn
# 
# def get_resource(*args):
#     return os.path.join(TEST_RESOURCES, *args)


import io
import os
import pytest
import shutil
import tempfile
import transaction
import unittest
from mock import patch
from pyramid import testing
from papaye.tests.tools import (
    FakeGRequestResponse,
    disable_cache,
    get_db_connection,
    get_resource,
)
        from papaye.tasks.download import download_release_from_pypi
        from papaye.factories.root import repository_root_factory
        from papaye.tasks.download import download_release_from_pypi
        from papaye.factories.root import repository_root_factory
        from papaye.models import Package, Release, ReleaseFile
        from papaye.tasks.download import download_release_from_pypi
        from papaye.models import Package, Release, ReleaseFile
        from papaye.tasks.download import download_release_from_pypi




class TestDownloadTask(unittest.TestCase):

    def setUp(self):
        self.blob_dir = tempfile.mkdtemp()
        self.conn = get_db_connection(self.blob_dir)
        self.root = self.conn.root()['papaye_root']['repository']
        self.maxDiff = None

    def tearDown(self):
        shutil.rmtree(self.blob_dir)

    @patch('requests.get')
    @patch('papaye.factories.root.repository_root_factory')
    def test_download_release_from_pypi(self, get_connection_mock, request_mock):
        get_connection_mock.return_value = self.root

        json_request_response = open(get_resource('pyramid1.4.json'), 'rb')
        release_file_content = open(get_resource('pyramid-1.5.tar.gz'), 'rb')
        request_mock.side_effect = [

# 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
# 
# 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 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)
#     return conn
# 
# def get_resource(*args):
#     return os.path.join(TEST_RESOURCES, *args)


# Path: papaye/tests/test_tasks.py
import io
import os
import pytest
import shutil
import tempfile
import transaction
import unittest
from mock import patch
from pyramid import testing
from papaye.tests.tools import (
    FakeGRequestResponse,
    disable_cache,
    get_db_connection,
    get_resource,
)
        from papaye.tasks.download import download_release_from_pypi
        from papaye.factories.root import repository_root_factory
        from papaye.tasks.download import download_release_from_pypi
        from papaye.factories.root import repository_root_factory
        from papaye.models import Package, Release, ReleaseFile
        from papaye.tasks.download import download_release_from_pypi
        from papaye.models import Package, Release, ReleaseFile
        from papaye.tasks.download import download_release_from_pypi





class TestDownloadTask(unittest.TestCase):

    def setUp(self):
        self.blob_dir = tempfile.mkdtemp()
        self.conn = get_db_connection(self.blob_dir)
        self.root = self.conn.root()['papaye_root']['repository']
        self.maxDiff = None

    def tearDown(self):
        shutil.rmtree(self.blob_dir)

    @patch('requests.get')
    @patch('papaye.factories.root.repository_root_factory')
    def test_download_release_from_pypi(self, get_connection_mock, request_mock):
        get_connection_mock.return_value = self.root

        json_request_response = open(get_resource('pyramid1.4.json'), 'rb')
        release_file_content = open(get_resource('pyramid-1.5.tar.gz'), 'rb')
        request_mock.side_effect = [

            FakeGRequestResponse(200, json_request_response.read()),