本文整理汇总了Python中pyramid.testing.DummyRequest._process_finished_callbacks方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest._process_finished_callbacks方法的具体用法?Python DummyRequest._process_finished_callbacks怎么用?Python DummyRequest._process_finished_callbacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest._process_finished_callbacks方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSQLCache
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import _process_finished_callbacks [as 别名]
class TestSQLCache(unittest.TestCase):
""" Tests for the SQLAlchemy cache """
@classmethod
def setUpClass(cls):
super(TestSQLCache, cls).setUpClass()
config = MagicMock()
config.get_settings.return_value = {
'pypi.storage': 'tests.DummyStorage',
'db.url': 'sqlite:///:memory:',
}
SQLCache.configure(config)
def setUp(self):
super(TestSQLCache, self).setUp()
self.request = DummyRequest()
self.db = SQLCache(self.request)
self.sql = self.db.db
self.storage = self.db.storage = MagicMock(spec=IStorage)
def tearDown(self):
super(TestSQLCache, self).tearDown()
transaction.abort()
self.sql.query(SQLPackage).delete()
transaction.commit()
self.request._process_finished_callbacks()
def test_upload(self):
""" upload() saves package and uploads to storage """
pkg = make_package(factory=SQLPackage)
self.storage.upload.return_value = pkg.path
self.db.upload(pkg.name, pkg.version, pkg.path, None)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
self.storage.upload.assert_called_with(pkg.name, pkg.version, pkg.path,
None)
def test_save(self):
""" save() puts object into database """
pkg = make_package(factory=SQLPackage)
self.db.save(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
def test_delete(self):
""" delete() removes object from database and deletes from storage """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
transaction.commit()
self.sql.add(pkg)
self.db.delete(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 0)
self.storage.delete.assert_called_with(pkg.path)
def test_clear(self):
""" clear() removes object from database """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
transaction.commit()
self.sql.add(pkg)
self.db.delete(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 0)
def test_reload(self):
""" reload_from_storage() inserts packages into the database """
keys = [
make_package(factory=SQLPackage),
make_package('mypkg2', '1.3.4', 'my/other/path',
factory=SQLPackage),
]
self.storage.list.return_value = keys
self.db.reload_from_storage()
all_pkgs = self.sql.query(SQLPackage).all()
self.assertItemsEqual(all_pkgs, keys)
def test_fetch(self):
""" fetch() retrieves a package from the database """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
saved_pkg = self.db.fetch(pkg.name, pkg.version)
self.assertEqual(saved_pkg, pkg)
def test_fetch_missing(self):
""" fetch() returns None if no package exists """
saved_pkg = self.db.fetch('missing_pkg', '1.2')
self.assertIsNone(saved_pkg)
def test_all_versions(self):
""" all() returns all versions of a package """
pkgs = [
make_package(factory=SQLPackage),
make_package(version='1.3', path='mypath3', factory=SQLPackage),
make_package('mypkg2', '1.3.4', 'my/other/path',
#.........这里部分代码省略.........
示例2: TestSQLCache
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import _process_finished_callbacks [as 别名]
class TestSQLCache(unittest.TestCase):
""" Tests for the SQLAlchemy cache """
@classmethod
def setUpClass(cls):
super(TestSQLCache, cls).setUpClass()
settings = {"pypi.storage": "tests.DummyStorage", "db.url": "sqlite:///:memory:"}
cls.kwargs = SQLCache.configure(settings)
def setUp(self):
super(TestSQLCache, self).setUp()
self.request = DummyRequest()
self.db = SQLCache(self.request, **self.kwargs)
self.sql = self.db.db
self.storage = self.db.storage = MagicMock(spec=IStorage)
def tearDown(self):
super(TestSQLCache, self).tearDown()
transaction.abort()
self.sql.query(SQLPackage).delete()
transaction.commit()
self.request._process_finished_callbacks()
def test_upload(self):
""" upload() saves package and uploads to storage """
pkg = make_package(factory=SQLPackage)
self.db.upload(pkg.filename, None, pkg.name, pkg.version)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
self.storage.upload.assert_called_with(pkg, None)
def test_save(self):
""" save() puts object into database """
pkg = make_package(factory=SQLPackage)
self.db.save(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
def test_delete(self):
""" delete() removes object from database and deletes from storage """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
transaction.commit()
self.sql.add(pkg)
self.db.delete(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 0)
self.storage.delete.assert_called_with(pkg)
def test_clear(self):
""" clear() removes object from database """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
transaction.commit()
self.sql.add(pkg)
self.db.delete(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 0)
def test_reload(self):
""" reload_from_storage() inserts packages into the database """
keys = [make_package(factory=SQLPackage), make_package("mypkg2", "1.3.4", "my/other/path", factory=SQLPackage)]
self.storage.list.return_value = keys
self.db.reload_from_storage()
all_pkgs = self.sql.query(SQLPackage).all()
self.assertItemsEqual(all_pkgs, keys)
def test_fetch(self):
""" fetch() retrieves a package from the database """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
saved_pkg = self.db.fetch(pkg.filename)
self.assertEqual(saved_pkg, pkg)
def test_fetch_missing(self):
""" fetch() returns None if no package exists """
saved_pkg = self.db.fetch("missing_pkg-1.2.tar.gz")
self.assertIsNone(saved_pkg)
def test_all_versions(self):
""" all() returns all versions of a package """
pkgs = [
make_package(factory=SQLPackage),
make_package(version="1.3", filename="mypath3", factory=SQLPackage),
make_package("mypkg2", "1.3.4", "my/other/path", factory=SQLPackage),
]
self.sql.add_all(pkgs)
saved_pkgs = self.db.all("mypkg")
self.assertItemsEqual(saved_pkgs, pkgs[:2])
def test_distinct(self):
""" distinct() returns all unique package names """
pkgs = [
make_package(factory=SQLPackage),
make_package(version="1.3", filename="mypath3", factory=SQLPackage),
#.........这里部分代码省略.........
示例3: TestSQLiteCache
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import _process_finished_callbacks [as 别名]
class TestSQLiteCache(unittest.TestCase):
""" Tests for the SQLCache """
DB_URL = "sqlite://"
@classmethod
def setUpClass(cls):
super(TestSQLiteCache, cls).setUpClass()
settings = {
"pypi.storage": "tests.DummyStorage",
"db.url": cls.DB_URL,
"db.graceful_reload": True,
}
try:
cls.kwargs = SQLCache.configure(settings)
except OperationalError:
raise unittest.SkipTest("Couldn't connect to database")
def setUp(self):
super(TestSQLiteCache, self).setUp()
transaction.begin()
self.request = DummyRequest()
self.request.tm = transaction.manager
self.db = SQLCache(self.request, **self.kwargs)
self.sql = self.db.db
self.storage = self.db.storage = MagicMock(spec=IStorage)
def tearDown(self):
super(TestSQLiteCache, self).tearDown()
transaction.abort()
self.sql.query(SQLPackage).delete()
transaction.commit()
self.request._process_finished_callbacks()
def _make_package(self, *args, **kwargs):
""" Wrapper around make_package """
# Some SQL dbs are rounding the timestamps (looking at you MySQL >:|
# which is a problem if they round UP to the future, as our
# calculations depend on the timestamps being monotonically increasing.
now = datetime.utcnow() - timedelta(seconds=1)
kwargs.setdefault("last_modified", now)
kwargs.setdefault("factory", SQLPackage)
return make_package(*args, **kwargs)
def test_add_missing(self):
""" Add missing packages to cache """
keys = [self._make_package()]
self.storage.list.return_value = keys
self.db.reload_from_storage()
all_pkgs = self.sql.query(SQLPackage).all()
self.assertItemsEqual(all_pkgs, keys)
def test_remove_extra(self):
""" Remove extra packages from cache """
keys = [self._make_package(), self._make_package("mypkg2", "1.3.4")]
self.db.save(keys[0])
self.db.save(keys[1])
self.storage.list.return_value = keys[:1]
self.db.reload_from_storage()
all_pkgs = self.sql.query(SQLPackage).all()
self.assertItemsEqual(all_pkgs, keys[:1])
def test_remove_extra_leave_concurrent(self):
""" Removing extra packages will leave packages that were uploaded concurrently """
pkgs = [self._make_package(), self._make_package("mypkg2")]
self.db.save(pkgs[0])
self.db.save(pkgs[1])
# Return first pkgs[1], then pkgs[1:] because the second time we list
# we will have "uploaded" pkgs[2]
return_values = [lambda: pkgs[1:2], lambda: pkgs[1:]]
def list_storage(package_class):
""" mocked method for listing storage packages """
# The first time we list from storage, concurrently "upload"
# pkgs[2]
if len(return_values) == 2:
nowish = datetime.utcnow() + timedelta(seconds=1)
pkg = self._make_package("mypkg3", last_modified=nowish)
pkgs.append(pkg)
self.db.save(pkg)
return return_values.pop(0)()
self.storage.list.side_effect = list_storage
self.db.reload_from_storage()
all_pkgs = self.sql.query(SQLPackage).all()
self.assertItemsEqual(all_pkgs, pkgs[1:])
def test_remove_extra_concurrent_deletes(self):
""" Remove packages from cache that were concurrently deleted """
pkgs = [self._make_package(), self._make_package("mypkg2")]
self.db.save(pkgs[0])
# Return first pkgs[:], then pkgs[:1] because the second time we list
# we will have "deleted" pkgs[1]
return_values = [pkgs[:], pkgs[:1]]
self.storage.list.side_effect = lambda _: return_values.pop(0)
#.........这里部分代码省略.........
示例4: TestSQLiteCache
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import _process_finished_callbacks [as 别名]
class TestSQLiteCache(unittest.TestCase):
""" Tests for the SQLAlchemy cache """
DB_URL = "sqlite://"
@classmethod
def setUpClass(cls):
super(TestSQLiteCache, cls).setUpClass()
settings = {"pypi.storage": "tests.DummyStorage", "db.url": cls.DB_URL}
try:
cls.kwargs = SQLCache.configure(settings)
except OperationalError:
raise unittest.SkipTest("Couldn't connect to database")
def setUp(self):
super(TestSQLiteCache, self).setUp()
transaction.begin()
self.request = DummyRequest()
self.request.tm = transaction.manager
self.db = SQLCache(self.request, **self.kwargs)
self.sql = self.db.db
self.storage = self.db.storage = MagicMock(spec=IStorage)
def tearDown(self):
super(TestSQLiteCache, self).tearDown()
transaction.abort()
self.sql.query(SQLPackage).delete()
transaction.commit()
self.request._process_finished_callbacks()
def test_upload(self):
""" upload() saves package and uploads to storage """
pkg = make_package(factory=SQLPackage)
self.db.upload(pkg.filename, None, pkg.name, pkg.version)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
self.storage.upload.assert_called_with(pkg, None)
def test_upload_overwrite(self):
""" Uploading a preexisting packages overwrites current package """
self.db.allow_overwrite = True
name, filename = "a", "a-1.tar.gz"
self.db.upload(filename, "old", name)
self.db.upload(filename, "new", name)
all_versions = self.db.all(name)
self.assertEqual(len(all_versions), 1)
def test_save(self):
""" save() puts object into database """
pkg = make_package(factory=SQLPackage)
self.db.save(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
def test_save_unicode(self):
""" save() can store packages with unicode in the names """
pkg = make_package("mypackage™", factory=SQLPackage)
self.db.save(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
def test_delete(self):
""" delete() removes object from database and deletes from storage """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
transaction.commit()
self.sql.add(pkg)
self.db.delete(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 0)
self.storage.delete.assert_called_with(pkg)
def test_clear(self):
""" clear() removes object from database """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
transaction.commit()
self.sql.add(pkg)
self.db.delete(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 0)
def test_reload(self):
""" reload_from_storage() inserts packages into the database """
keys = [
make_package(factory=SQLPackage),
make_package("mypkg2", "1.3.4", "my/other/path", factory=SQLPackage),
]
self.storage.list.return_value = keys
self.db.reload_from_storage()
all_pkgs = self.sql.query(SQLPackage).all()
self.assertItemsEqual(all_pkgs, keys)
#.........这里部分代码省略.........
示例5: TestSQLiteCache
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import _process_finished_callbacks [as 别名]
class TestSQLiteCache(unittest.TestCase):
""" Tests for the SQLAlchemy cache """
DB_URL = 'sqlite:///:memory:'
@classmethod
def setUpClass(cls):
super(TestSQLiteCache, cls).setUpClass()
settings = {
'pypi.storage': 'tests.DummyStorage',
'db.url': cls.DB_URL,
}
try:
cls.kwargs = SQLCache.configure(settings)
except OperationalError:
raise unittest.SkipTest("Couldn't connect to database")
def setUp(self):
super(TestSQLiteCache, self).setUp()
self.request = DummyRequest()
self.db = SQLCache(self.request, **self.kwargs)
self.sql = self.db.db
self.storage = self.db.storage = MagicMock(spec=IStorage)
def tearDown(self):
super(TestSQLiteCache, self).tearDown()
transaction.abort()
self.sql.query(SQLPackage).delete()
transaction.commit()
self.request._process_finished_callbacks()
def test_upload(self):
""" upload() saves package and uploads to storage """
pkg = make_package(factory=SQLPackage)
self.db.upload(pkg.filename, None, pkg.name, pkg.version)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
self.storage.upload.assert_called_with(pkg, None)
def test_upload_overwrite(self):
""" Uploading a preexisting packages overwrites current package """
self.db.allow_overwrite = True
name, filename = 'a', 'a-1.tar.gz'
self.db.upload(filename, 'old', name)
self.db.upload(filename, 'new', name)
all_versions = self.db.all(name)
self.assertEqual(len(all_versions), 1)
def test_save(self):
""" save() puts object into database """
pkg = make_package(factory=SQLPackage)
self.db.save(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
def test_save_unicode(self):
""" save() can store packages with unicode in the names """
pkg = make_package(u'mypackage™', factory=SQLPackage)
self.db.save(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
def test_delete(self):
""" delete() removes object from database and deletes from storage """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
transaction.commit()
self.sql.add(pkg)
self.db.delete(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 0)
self.storage.delete.assert_called_with(pkg)
def test_clear(self):
""" clear() removes object from database """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
transaction.commit()
self.sql.add(pkg)
self.db.delete(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 0)
def test_reload(self):
""" reload_from_storage() inserts packages into the database """
keys = [
make_package(factory=SQLPackage),
make_package('mypkg2', '1.3.4', 'my/other/path',
factory=SQLPackage),
]
self.storage.list.return_value = keys
self.db.reload_from_storage()
#.........这里部分代码省略.........
示例6: TestSQLCache
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import _process_finished_callbacks [as 别名]
class TestSQLCache(unittest.TestCase):
""" Tests for the SQLAlchemy cache """
@classmethod
def setUpClass(cls):
super(TestSQLCache, cls).setUpClass()
settings = {
'pypi.storage': 'tests.DummyStorage',
'db.url': 'sqlite:///:memory:',
}
cls.kwargs = SQLCache.configure(settings)
def setUp(self):
super(TestSQLCache, self).setUp()
self.request = DummyRequest()
self.db = SQLCache(self.request, **self.kwargs)
self.sql = self.db.db
self.storage = self.db.storage = MagicMock(spec=IStorage)
def tearDown(self):
super(TestSQLCache, self).tearDown()
transaction.abort()
self.sql.query(SQLPackage).delete()
transaction.commit()
self.request._process_finished_callbacks()
def test_upload(self):
""" upload() saves package and uploads to storage """
pkg = make_package(factory=SQLPackage)
self.db.upload(pkg.filename, None, pkg.name, pkg.version)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
self.storage.upload.assert_called_with(pkg, None)
def test_upload_overwrite(self):
""" Uploading a preexisting packages overwrites current package """
self.db.allow_overwrite = True
name, filename = 'a', 'a-1.tar.gz'
self.db.upload(filename, 'old', name)
self.db.upload(filename, 'new', name)
all_versions = self.db.all(name)
self.assertEqual(len(all_versions), 1)
def test_save(self):
""" save() puts object into database """
pkg = make_package(factory=SQLPackage)
self.db.save(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 1)
saved_pkg = self.sql.query(SQLPackage).first()
self.assertEqual(saved_pkg, pkg)
def test_delete(self):
""" delete() removes object from database and deletes from storage """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
transaction.commit()
self.sql.add(pkg)
self.db.delete(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 0)
self.storage.delete.assert_called_with(pkg)
def test_clear(self):
""" clear() removes object from database """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
transaction.commit()
self.sql.add(pkg)
self.db.delete(pkg)
count = self.sql.query(SQLPackage).count()
self.assertEqual(count, 0)
def test_reload(self):
""" reload_from_storage() inserts packages into the database """
keys = [
make_package(factory=SQLPackage),
make_package('mypkg2', '1.3.4', 'my/other/path',
factory=SQLPackage),
]
self.storage.list.return_value = keys
self.db.reload_from_storage()
all_pkgs = self.sql.query(SQLPackage).all()
self.assertItemsEqual(all_pkgs, keys)
def test_fetch(self):
""" fetch() retrieves a package from the database """
pkg = make_package(factory=SQLPackage)
self.sql.add(pkg)
saved_pkg = self.db.fetch(pkg.filename)
self.assertEqual(saved_pkg, pkg)
def test_fetch_missing(self):
""" fetch() returns None if no package exists """
saved_pkg = self.db.fetch('missing_pkg-1.2.tar.gz')
self.assertIsNone(saved_pkg)
#.........这里部分代码省略.........