• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.LangPack类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mkt.langpacks.models.LangPack的典型用法代码示例。如果您正苦于以下问题:Python LangPack类的具体用法?Python LangPack怎么用?Python LangPack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了LangPack类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_upload_sign_error_existing

    def test_upload_sign_error_existing(self, sign_app_mock):
        sign_app_mock.side_effect = SigningError
        langpack = self.create_langpack()
        eq_(LangPack.objects.count(), 1)
        original_uuid = langpack.uuid
        original_file_path = langpack.file_path
        original_file_version = langpack.file_version
        original_version = langpack.version
        # create_langpack() doesn't create a fake file, let's add one.
        with public_storage.open(langpack.file_path, 'w') as f:
            f.write('.')
        upload = self.upload('langpack')
        with self.assertRaises(SigningError):
            LangPack.from_upload(upload, instance=langpack)
        # Test that we didn't delete the upload file
        ok_(private_storage.exists(upload.path))
        # Test that we didn't delete the existing filename or alter the
        # existing langpack in the database.
        eq_(LangPack.objects.count(), 1)
        langpack.reload()
        eq_(original_uuid, langpack.uuid)
        eq_(langpack.file_path, original_file_path)
        eq_(original_file_version, langpack.file_version)
        eq_(original_version, langpack.version)
        ok_(public_storage.exists(langpack.file_path))

        # Cleanup
        public_storage.delete(langpack.file_path)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:28,代码来源:test_models.py


示例2: test_upload_language_validation

 def test_upload_language_validation(self, get_json_data_mock):
     upload = self.upload('langpack')
     get_json_data_mock.return_value = {
         'name': 'Portuguese Langpack',
         'developer': {
             'name': 'Mozilla'
         },
         'role': 'langpack',
         'languages-provided': {
             'pt-BR': {}
         },
         'languages-target': {
             'app://*.gaiamobile.org/manifest.webapp': '2.2'
         },
         'version': '0.1'
     }
     langpack = LangPack.from_upload(upload)
     ok_(langpack.pk)
     eq_(langpack.language, 'pt-BR')
     get_json_data_mock.return_value['languages-provided'] = {
         'invalid-lang': {}
     }
     expected = [u"Value 'invalid-lang' is not a valid choice."]
     with self.assertRaises(ValidationError) as e:
         LangPack.from_upload(upload)
     eq_(e.exception.messages, expected)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:26,代码来源:test_models.py


示例3: test_upload_sign_error

 def test_upload_sign_error(self, sign_app_mock):
     sign_app_mock.side_effect = SigningError
     eq_(LangPack.objects.count(), 0)
     upload = self.upload('langpack')
     with self.assertRaises(SigningError):
         LangPack.from_upload(upload)
     # Test that we didn't delete the upload file
     ok_(private_storage.exists(upload.path))
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:8,代码来源:test_models.py


示例4: test_upload_existing_same_version

 def test_upload_existing_same_version(self):
     langpack = self.create_langpack()
     upload = self.upload('langpack')
     # Works once.
     ok_(LangPack.from_upload(upload, instance=langpack))
     # Doesn't work twice, since we are re-uploading the same version.
     expected = [u'Your language pack version must be different to the '
                 u'one you are replacing.']
     with self.assertRaises(ValidationError) as e:
         LangPack.from_upload(upload, instance=langpack)
     eq_(e.exception.messages, expected)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:11,代码来源:test_models.py


示例5: test_upload_existing

 def test_upload_existing(self):
     langpack = self.create_langpack()
     original_uuid = langpack.uuid
     original_file_path = langpack.file_path
     original_file_version = langpack.file_version
     original_manifest = langpack.manifest
     with patch('mkt.webapps.utils.public_storage') as storage_mock:
         # mock storage size before building minifest since we haven't
         # created a real file for this langpack yet.
         storage_mock.size.return_value = 666
         original_minifest = langpack.get_minifest_contents()
     upload = self.upload('langpack')
     langpack = LangPack.from_upload(upload, instance=langpack)
     eq_(langpack.uuid, original_uuid)
     eq_(langpack.version, '1.0.3')
     eq_(langpack.language, 'de')
     eq_(langpack.fxos_version, '2.2')
     eq_(langpack.filename, '%s-%s.zip' % (langpack.uuid, langpack.version))
     eq_(langpack.get_manifest_json(), self.expected_manifest)
     ok_(langpack.file_path.startswith(langpack.path_prefix))
     ok_(langpack.filename in langpack.file_path)
     ok_(langpack.file_path != original_file_path)
     ok_(langpack.file_version > original_file_version)
     ok_(public_storage.exists(langpack.file_path))
     ok_(LangPack.objects.get(pk=langpack.uuid))
     eq_(LangPack.objects.count(), 1)
     ok_(langpack.manifest != original_manifest)
     # We're supposed to have busted the old minifest cache.
     ok_(langpack.get_minifest_contents() != original_minifest)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:29,代码来源:test_models.py


示例6: validate

 def validate(self, data):
     try:
         self.instance = LangPack.from_upload(data['upload'],
                                              instance=self.instance)
     except forms.ValidationError, e:
         exc = ParseError()
         exc.detail = {u'detail': e.messages}
         raise exc
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:8,代码来源:serializers.py


示例7: test_upload_language_validation

 def test_upload_language_validation(self, get_json_data_mock):
     upload = self.upload("langpack")
     get_json_data_mock.return_value = {
         "name": "Portuguese Langpack",
         "developer": {"name": "Mozilla"},
         "role": "langpack",
         "languages-provided": {"pt-BR": {}},
         "languages-target": {"app://*.gaiamobile.org/manifest.webapp": "2.2"},
         "version": "0.1",
     }
     langpack = LangPack.from_upload(upload)
     ok_(langpack.pk)
     eq_(langpack.language, "pt-BR")
     get_json_data_mock.return_value["languages-provided"] = {"invalid-lang": {}}
     expected = [u"Value 'invalid-lang' is not a valid choice."]
     with self.assertRaises(ValidationError) as e:
         LangPack.from_upload(upload)
     eq_(e.exception.messages, expected)
开发者ID:jobava-mozilla,项目名称:zamboni,代码行数:18,代码来源:test_models.py


示例8: test_get_minifest_contents

    def test_get_minifest_contents(self, storage_mock):
        fake_manifest = {"name": u"Fake LangPäck", "developer": {"name": "Mozilla"}}
        langpack = LangPack(
            pk="12345678123456781234567812345678", fxos_version="2.2", version="0.3", manifest=json.dumps(fake_manifest)
        )
        storage_mock.size.return_value = 666
        minifest_contents = json.loads(langpack.get_minifest_contents()[0])

        eq_(
            minifest_contents,
            {
                "version": "0.3",
                "size": 666,
                "name": u"Fake LangPäck",
                "package_path": langpack.download_url,
                "developer": {"name": "Mozilla"},
            },
        )
        return langpack, minifest_contents
开发者ID:jobava-mozilla,项目名称:zamboni,代码行数:19,代码来源:test_models.py


示例9: test_get_minifest_contents

    def test_get_minifest_contents(self, storage_mock):
        fake_manifest = {
            'name': u'Fake LangPäck',
            'developer': {
                'name': 'Mozilla'
            }
        }
        langpack = LangPack(
            pk='12345678123456781234567812345678',
            fxos_version='2.2',
            version='0.3',
            manifest=json.dumps(fake_manifest))
        storage_mock.size.return_value = 666
        minifest_contents = json.loads(langpack.get_minifest_contents())

        eq_(minifest_contents,
            {'version': '0.3',
             'size': 666,
             'name': u'Fake LangPäck',
             'package_path': langpack.download_url,
             'developer': {'name': 'Mozilla'}})
        return langpack, minifest_contents
开发者ID:atiqueahmedziad,项目名称:zamboni,代码行数:22,代码来源:test_models.py


示例10: test_upload_sign

 def test_upload_sign(self, sign_app_mock, cached_minifest_mock):
     eq_(LangPack.objects.count(), 0)
     upload = self.upload('langpack')
     langpack = LangPack.from_upload(upload)
     ok_(langpack.pk)
     ok_(langpack.file_version)
     ok_(langpack.file_path)
     eq_(LangPack.objects.count(), 1)
     expected_args = (
         langpack.file_path,
         json.dumps({'id': langpack.pk, 'version': langpack.file_version})
     )
     eq_(os.path.join('/', sign_app_mock.call_args[0][0].name), upload.path)
     eq_(sign_app_mock.call_args[0][1:], expected_args)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:14,代码来源:test_models.py


示例11: test_upload_sign

 def test_upload_sign(self, sign_app_mock, cached_minifest_mock):
     eq_(LangPack.objects.count(), 0)
     upload = self.upload('langpack')
     langpack = LangPack.from_upload(upload)
     ok_(langpack.pk)
     ok_(langpack.file_version)
     ok_(langpack.file_path)
     eq_(LangPack.objects.count(), 1)
     expected_args = (
         upload.path,
         langpack.file_path,
         json.dumps({'id': langpack.pk, 'version': langpack.file_version})
     )
     sign_app_mock.assert_called_once_with(*expected_args)
开发者ID:atiqueahmedziad,项目名称:zamboni,代码行数:14,代码来源:test_models.py


示例12: test_upload_sign_existing

 def test_upload_sign_existing(self, sign_app_mock, cached_minifest_mock):
     langpack = self.create_langpack()
     eq_(LangPack.objects.count(), 1)
     upload = self.upload("langpack")
     langpack = LangPack.from_upload(upload, instance=langpack)
     ok_(langpack.pk)
     ok_(langpack.file_version)
     ok_(langpack.file_path)
     eq_(LangPack.objects.count(), 1)
     expected_args = (
         upload.path,
         langpack.file_path,
         json.dumps({"id": langpack.pk, "version": langpack.file_version}),
     )
     sign_app_mock.assert_called_once_with(*expected_args)
开发者ID:jobava-mozilla,项目名称:zamboni,代码行数:15,代码来源:test_models.py


示例13: test_upload_new

 def test_upload_new(self):
     eq_(LangPack.objects.count(), 0)
     upload = self.upload('langpack')
     langpack = LangPack.from_upload(upload)
     ok_(langpack.uuid)
     eq_(langpack.file_version, 1)
     eq_(langpack.version, '1.0.3')
     eq_(langpack.language, 'de')
     eq_(langpack.fxos_version, '2.2')
     eq_(langpack.filename, '%s-%s.zip' % (langpack.uuid, langpack.version))
     ok_(langpack.filename in langpack.file_path)
     ok_(langpack.file_path.startswith(langpack.path_prefix))
     ok_(public_storage.exists(langpack.file_path))
     eq_(langpack.get_manifest_json(), self.expected_manifest)
     ok_(LangPack.objects.get(pk=langpack.uuid))
     eq_(LangPack.objects.count(), 1)
     return langpack
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:17,代码来源:test_models.py


示例14: test_upload_new

 def test_upload_new(self):
     eq_(LangPack.objects.count(), 0)
     upload = self.upload("langpack")
     langpack = LangPack.from_upload(upload)
     ok_(langpack.uuid)
     eq_(langpack.file_version, 1)
     eq_(langpack.version, "1.0.3")
     eq_(langpack.language, "de")
     eq_(langpack.fxos_version, "2.2")
     eq_(langpack.filename, "%s-%s.zip" % (langpack.uuid, langpack.version))
     ok_(langpack.filename in langpack.file_path)
     ok_(langpack.file_path.startswith(langpack.path_prefix))
     ok_(os.path.exists(langpack.file_path))
     eq_(langpack.get_manifest_json(), self.expected_manifest)
     ok_(LangPack.objects.no_cache().get(pk=langpack.uuid))
     eq_(LangPack.objects.count(), 1)
     return langpack
开发者ID:jobava-mozilla,项目名称:zamboni,代码行数:17,代码来源:test_models.py


示例15: test_manifest_url

 def test_manifest_url(self):
     langpack = LangPack(pk='12345678123456781234567812345678')
     eq_(langpack.manifest_url, '')  # Inactive langpack.
     langpack.active = True
     ok_(langpack.manifest_url.endswith(
         '/12345678-1234-5678-1234-567812345678/manifest.webapp'))
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:6,代码来源:test_models.py


示例16: reset_uuid

 def reset_uuid(self):
     langpack = LangPack(uuid="12345678123456781234567812345678")
     eq_(langpack.pk, "12345678123456781234567812345678")
     langpack.reset_uuid()
     ok_(langpack.pk != "12345678123456781234567812345678")
开发者ID:jobava-mozilla,项目名称:zamboni,代码行数:5,代码来源:test_models.py


示例17: restore_object

 def restore_object(self, attrs, instance=None):
     try:
         return LangPack.from_upload(attrs['upload'], instance=instance)
     except serializers.ValidationError, e:
         raise ParseError(e.messages)
开发者ID:Witia1,项目名称:zamboni,代码行数:5,代码来源:serializers.py


示例18: test_manifest_url

 def test_manifest_url(self):
     langpack = LangPack(pk="12345678123456781234567812345678")
     eq_(langpack.manifest_url, "")  # Inactive langpack.
     langpack.active = True
     ok_(langpack.manifest_url.endswith("/12345678-1234-5678-1234-567812345678/manifest.webapp"))
开发者ID:jobava-mozilla,项目名称:zamboni,代码行数:5,代码来源:test_models.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python views._transaction_summary函数代码示例发布时间:2022-05-27
下一篇:
Python models.InappPayment类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap