当前位置: 首页>>代码示例>>Python>>正文


Python Package.get_by_key_name方法代码示例

本文整理汇总了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'))
开发者ID:kwalrath,项目名称:pub-dartlang,代码行数:16,代码来源:test_package_versions.py

示例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
        }
开发者ID:a14n,项目名称:pub-dartlang,代码行数:31,代码来源:search.py

示例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")
        })
开发者ID:a14n,项目名称:pub-dartlang,代码行数:34,代码来源:test_packages.py

示例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()
开发者ID:butlermatt,项目名称:pub-dartlang,代码行数:10,代码来源:package_versions.py

示例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')])
开发者ID:Mixbook,项目名称:pub-dartlang,代码行数:12,代码来源:test_package_uploaders.py

示例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')])
开发者ID:Mixbook,项目名称:pub-dartlang,代码行数:12,代码来源:test_package_uploaders.py

示例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()
        ])
开发者ID:Mixbook,项目名称:pub-dartlang,代码行数:14,代码来源:test_package_uploaders.py

示例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
开发者ID:dart-lang,项目名称:pub-dartlang,代码行数:17,代码来源:__init__.py

示例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')
        ])
开发者ID:Mixbook,项目名称:pub-dartlang,代码行数:21,代码来源:test_package_uploaders.py

示例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)
开发者ID:kwalrath,项目名称:pub-dartlang,代码行数:22,代码来源:test_package_versions.py

示例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)
开发者ID:butlermatt,项目名称:pub-dartlang,代码行数:22,代码来源:test_package_versions.py

示例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()
开发者ID:butlermatt,项目名称:pub-dartlang,代码行数:22,代码来源:test_package_versions.py

示例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)
开发者ID:kwalrath,项目名称:pub-dartlang,代码行数:5,代码来源:test_package_versions.py

示例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
开发者ID:kwalrath,项目名称:pub-dartlang,代码行数:4,代码来源:test_package_versions.py

示例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()
开发者ID:kaisellgren,项目名称:pub-dartlang,代码行数:8,代码来源:testcase.py


注:本文中的models.package.Package.get_by_key_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。