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


Python models.LangPack类代码示例

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


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


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