本文整理汇总了Python中models.package.Package.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Package.get_by_key_name方法的具体用法?Python Package.get_by_key_name怎么用?Python Package.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.package.Package
的用法示例。
在下文中一共展示了Package.get_by_key_name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_uploadership_is_case_insensitive
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def test_uploadership_is_case_insensitive(self):
self.be_normal_oauth_user('NAme')
self.post_package_version(name='new-package', version='0.0.1')
version = Package.get_by_key_name('new-package').latest_version
self.assertIsNotNone(version)
self.assertEqual(version.version, SemanticVersion('0.0.1'))
self.be_normal_oauth_user('naME')
self.post_package_version(name='new-package', version='0.0.2')
version = Package.get_by_key_name('new-package').latest_version
self.assertIsNotNone(version)
self.assertEqual(version.version, SemanticVersion('0.0.2'))
示例2: _get_result
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def _get_result(self, resource_item):
"""Convert a Custom Search API result into a map of package metadata
that can be rendered.
If the result does not reference a valid package, return None.
Arguments:
resource_item: The API result. It is expected to be a map containing
a "link" key which will likely be a package URL.
"""
link = resource_item["link"]
match = PACKAGE_URL_PATTERN.match(link)
if not match:
logging.warning('could not parse search result URL "%s"' % link)
return None
package = Package.get_by_key_name(match.group(1))
if not package:
logging.warning('could not find search result package "%s"' %
match.group(1))
return None
return {
"name": package.name,
"version": package.latest_version.version,
"desc": package.ellipsized_description,
"url": "/packages/" + package.name,
"last_uploaded": package.latest_version.relative_created
}
示例3: test_api_get_package_with_versions
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def test_api_get_package_with_versions(self):
self.be_admin_user()
self.create_package('test-package', '1.1.0')
self.create_package('test-package', '1.1.1')
self.create_package('test-package', '1.2.0')
self.be_normal_user()
package = Package.get_by_key_name('test-package')
response = self.testapp.get('/api/packages/test-package')
self.assertEqual(response.headers['Content-Type'], 'application/json')
self.assertEqual(json.loads(response.body), {
"name": "test-package",
"url": "http://localhost:80/api/packages/test-package",
"uploaders_url": "http://localhost:80/api/packages/test-package/" +
"uploaders",
"version_url": "http://localhost:80/api/packages/test-package/" +
"versions/{version}",
"new_version_url":
"http://localhost:80/api/packages/test-package/versions/new",
"downloads": 0,
"uploaders": [self.admin_user().email()],
"created": package.created.isoformat(),
"versions": [
self.package_version_dict("test-package", "1.1.0"),
self.package_version_dict("test-package", "1.1.1"),
self.package_version_dict("test-package", "1.2.0"),
],
"latest": self.package_version_dict("test-package", "1.2.0")
})
示例4: _compute_version_order
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def _compute_version_order(self, name):
"""Compute the sort order for all versions of a given package."""
versions = list(Package.get_by_key_name(name).version_set.run())
versions.sort(key=lambda version: version.version)
for i, version in enumerate(versions):
version.sort_order = i
with models.transaction():
for version in versions: version.put()
示例5: test_uploader_deletes_uploader
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def test_uploader_deletes_uploader(self):
self.be_normal_oauth_user('uploader1')
response = self.testapp.delete(
'/packages/test-package/uploaders/%s.json' %
self.normal_user('uploader1').email())
self.assert_json_success(response)
package = Package.get_by_key_name('test-package')
self.assertEquals(
package.uploaders, [self.normal_user('uploader2')])
示例6: test_delete_is_case_insensitive
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def test_delete_is_case_insensitive(self):
self.be_normal_oauth_user('uploader1')
response = self.testapp.delete(
'/api/packages/test-package/uploaders/' +
self.normal_user('UpLoAdEr1').email())
self.assert_json_success(response)
package = Package.get_by_key_name('test-package')
self.assertEquals(
package.uploaders, [self.normal_user('uploader2')])
示例7: test_uploader_creates_new_uploader
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def test_uploader_creates_new_uploader(self):
self.be_normal_oauth_user('uploader1')
response = self.testapp.post('/packages/test-package/uploaders.json',
{'email': self.normal_user().email()})
self.assert_json_success(response)
package = Package.get_by_key_name('test-package')
self.assertEquals(package.uploaders, [
self.normal_user('uploader1'),
self.normal_user('uploader2'),
self.normal_user()
])
示例8: maybe_package
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def maybe_package(self):
"""Load the current package object.
This auto-detects the package name from the request parameters. If the
package doesn't exist, returns None.
"""
if self._package: return self._package
name = self._package_name
if name is None: return None
self._package = Package.get_by_key_name(name)
if self._package: return self._package
return None
示例9: test_create_is_case_insensitive
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def test_create_is_case_insensitive(self):
self.be_normal_oauth_user('uploader1')
response = self.testapp.post(
'/api/packages/test-package/uploaders',
{'email': self.normal_user('NAme').email()})
self.assert_json_success(response)
response = self.testapp.post(
'/api/packages/test-package/uploaders',
{'email': self.normal_user('naME').email()},
status=400)
self.assert_json_error(response)
package = Package.get_by_key_name('test-package')
self.assertEquals(package.uploaders, [
self.normal_user('uploader1'),
self.normal_user('uploader2'),
self.normal_user('NAme')
])
示例10: test_user_creates_new_package
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def test_user_creates_new_package(self):
self.be_normal_oauth_user()
self.post_package_version(name='new-package', version='0.0.1')
package = Package.get_by_key_name('new-package')
self.assertIsNotNone(package)
self.assertEqual(package.name, 'new-package')
self.assertEqual(package.uploaders, [handlers.get_current_user()])
version = package.version_set.get()
self.assertIsNotNone(version)
self.assertEqual(version.version, SemanticVersion('0.0.1'))
self.assertEqual(version.package.name, 'new-package')
version = package.latest_version
self.assertIsNotNone(version)
self.assertEqual(version.version, SemanticVersion('0.0.1'))
self.assertEqual(version.package.name, 'new-package')
self.assertEqual(package.updated, version.created)
示例11: test_admin_creates_new_package_with_json
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def test_admin_creates_new_package_with_json(self):
self.be_admin_oauth_user()
self.post_package_version_with_json(name="new-package", version="0.0.1")
package = Package.get_by_key_name("new-package")
self.assertIsNotNone(package)
self.assertEqual(package.name, "new-package")
self.assertEqual(package.uploaders, [handlers.get_current_user()])
version = package.version_set.get()
self.assertIsNotNone(version)
self.assertEqual(version.version, SemanticVersion("0.0.1"))
self.assertEqual(version.package.name, "new-package")
version = package.latest_version
self.assertIsNotNone(version)
self.assertEqual(version.version, SemanticVersion("0.0.1"))
self.assertEqual(version.package.name, "new-package")
self.assertEqual(package.updated, version.created)
示例12: test_reload_reloads_a_package_version
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def test_reload_reloads_a_package_version(self):
self.be_admin_user()
self.post_package_version("1.2.3")
version = PackageVersion.get_by_name_and_version("test-package", "1.2.3")
version.libraries = ["wrong"]
version.put()
response = self.testapp.post("/packages/versions/reload", status=302)
self.assertEqual(response.headers["Location"], "http://localhost:80/admin#tab-packages")
self.run_deferred_tasks()
version = PackageVersion.get_by_name_and_version("test-package", "1.2.3")
self.assertEqual([], version.libraries)
# The latest_version of the parent package should also be updated
version = Package.get_by_key_name("test-package").latest_version
self.assertEqual([], version.libraries)
self.assert_package_updated_is_latest_version_created()
示例13: assert_package_updated_is_latest_version_created
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def assert_package_updated_is_latest_version_created(self):
package = Package.get_by_key_name('test-package')
self.assertEqual(package.updated, package.latest_version.created)
示例14: latest_version
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def latest_version(self):
return Package.get_by_key_name('test-package').latest_version.version
示例15: set_latest_version
# 需要导入模块: from models.package import Package [as 别名]
# 或者: from models.package.Package import get_by_key_name [as 别名]
def set_latest_version(self, package_name, version):
"""Set the latest version of the given package."""
package = Package.get_by_key_name(package_name)
package.latest_version = self.package_version(package, version)
package.latest_version.put()
package.put()