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


Python private_storage.exists函数代码示例

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


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

示例1: test_removed

 def test_removed(self):
     # At least one public app must exist for dump_apps to run.
     app_factory(name='second app', status=mkt.STATUS_PUBLIC)
     app_path = os.path.join(self.export_directory, self.app_path)
     app = Webapp.objects.get(pk=337141)
     app.update(status=mkt.STATUS_PUBLIC)
     self.create_export('tarball-name')
     assert private_storage.exists(app_path)
     app.update(status=mkt.STATUS_PENDING)
     self.create_export('tarball-name')
     assert not private_storage.exists(app_path)
开发者ID:shahbaz17,项目名称:zamboni,代码行数:11,代码来源:test_tasks.py

示例2: test_delete_with_file

 def test_delete_with_file(self):
     """Test that when a Extension instance is deleted, the corresponding
     file on the filesystem is also deleted."""
     extension = Extension.objects.create(version='0.1')
     file_path = extension.file_path
     with private_storage.open(file_path, 'w') as f:
         f.write('sample data\n')
     assert private_storage.exists(file_path)
     try:
         extension.delete()
         assert not private_storage.exists(file_path)
     finally:
         if private_storage.exists(file_path):
             private_storage.delete(file_path)
开发者ID:shahbaz17,项目名称:zamboni,代码行数:14,代码来源:test_models.py

示例3: reviewer_sign_file

 def reviewer_sign_file(self):
     """Sign the original file (`file_path`) with reviewer certs, then move
     the signed file to the reviewers-specific signed path
     (`reviewer_signed_file_path`) on private storage."""
     if not self.extension.uuid:
         raise SigningError('Need uuid to be set to sign')
     if not self.pk:
         raise SigningError('Need version pk to be set to sign')
     ids = json.dumps({
         'id': self.review_id,
         'version': self.pk
     })
     with statsd.timer('extensions.sign_reviewer'):
         try:
             # This will read the file from self.file_path, generate a
             # reviewer signature and write the signed file to
             # self.reviewer_signed_file_path.
             sign_app(private_storage.open(self.file_path),
                      self.reviewer_signed_file_path, ids, reviewer=True)
         except SigningError:
             log.info(
                 '[ExtensionVersion:%s] Reviewer Signing failed' % self.pk)
             if private_storage.exists(self.reviewer_signed_file_path):
                 private_storage.delete(self.reviewer_signed_file_path)
             raise
开发者ID:Witia1,项目名称:zamboni,代码行数:25,代码来源:models.py

示例4: 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

示例5: reviewer_sign_file

 def reviewer_sign_file(self):
     """Sign the original file (`file_path`) with reviewer certs, then move
     the signed file to the reviewers-specific signed path
     (`reviewer_signed_file_path`) on private storage."""
     if not self.extension.uuid:
         raise SigningError('Need uuid to be set to sign')
     if not self.pk:
         raise SigningError('Need version pk to be set to sign')
     ids = json.dumps({
         # Reviewers get a unique 'id' so the reviewer installed add-on
         # won't conflict with the public add-on, and also so even multiple
         # versions of the same add-on can be installed side by side with
         # other versions.
         'id': 'reviewer-{guid}-{version_id}'.format(
             guid=self.extension.uuid, version_id=self.pk),
         'version': self.pk
     })
     with statsd.timer('extensions.sign_reviewer'):
         try:
             # This will read the file from self.file_path, generate a
             # reviewer signature and write the signed file to
             # self.reviewer_signed_file_path.
             sign_app(private_storage.open(self.file_path),
                      self.reviewer_signed_file_path, ids, reviewer=True)
         except SigningError:
             log.info(
                 '[ExtensionVersion:%s] Reviewer Signing failed' % self.pk)
             if private_storage.exists(self.reviewer_signed_file_path):
                 private_storage.delete(self.reviewer_signed_file_path)
             raise
开发者ID:1Smert1,项目名称:zamboni,代码行数:30,代码来源:models.py

示例6: test_delete_no_file

 def test_delete_no_file(self):
     """Test that the Extension instance can be deleted without the file
     being present."""
     extension = Extension.objects.create(version='0.1')
     filename = extension.file_path
     assert not private_storage.exists(filename)
     extension.delete()
开发者ID:shahbaz17,项目名称:zamboni,代码行数:7,代码来源:test_models.py

示例7: 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

示例8: test_move

 def test_move(self):
     src = self.newfile('src.txt', '<contents>')
     dst = self.path('somedir/dst.txt')
     move_stored_file(
         src, dst,
         src_storage=private_storage, dst_storage=private_storage)
     eq_(self.contents(dst), '<contents>')
     eq_(private_storage.exists(src), False)
开发者ID:shahbaz17,项目名称:zamboni,代码行数:8,代码来源:test_storage_utils.py

示例9: test_delete_with_file

 def test_delete_with_file(self):
     """Test that when a Extension instance is deleted, the ExtensionVersion
     referencing it are also deleted, as well as the attached files."""
     extension = Extension.objects.create()
     version = ExtensionVersion.objects.create(
         extension=extension, version='0.1')
     file_path = version.file_path
     with private_storage.open(file_path, 'w') as f:
         f.write('sample data\n')
     assert private_storage.exists(file_path)
     try:
         extension.delete()
         assert not Extension.objects.count()
         assert not ExtensionVersion.objects.count()
         assert not private_storage.exists(file_path)
     finally:
         if private_storage.exists(file_path):
             private_storage.delete(file_path)
开发者ID:demagu-sr,项目名称:zamboni,代码行数:18,代码来源:test_models.py

示例10: test_promo_img_too_small

    def test_promo_img_too_small(self):
        with local_storage.open(get_image_path('preview.jpg')) as f:
            errors, upload_hash = check_upload(f, 'promo_img', 'image/png')
            ok_(errors)
            ok_(upload_hash)

            tmp_img_path = os.path.join(settings.TMP_PATH, 'promo_img',
                                        upload_hash)
            ok_(private_storage.exists(tmp_img_path))
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:9,代码来源:test_utils_.py

示例11: test_icon_ok

    def test_icon_ok(self):
        with local_storage.open(get_image_path('mozilla-sq.png')) as f:
            errors, upload_hash = check_upload(f, 'icon', 'image/png')
            ok_(not errors)
            ok_(upload_hash)

            tmp_img_path = os.path.join(settings.TMP_PATH, 'icon',
                                        upload_hash)
            ok_(private_storage.exists(tmp_img_path))
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:9,代码来源:test_utils_.py

示例12: setup_files

    def setup_files(self):
        # Clean out any left over stuff.
        private_storage.delete(self.file.signed_file_path)
        private_storage.delete(self.file.signed_reviewer_file_path)

        # Make sure the source file is there.
        if not private_storage.exists(self.file.file_path):
            copy_to_storage(self.packaged_app_path('mozball.zip'),
                            self.file.file_path)
开发者ID:jamesthechamp,项目名称:zamboni,代码行数:9,代码来源:tests.py

示例13: move_files_to_their_new_locations

def move_files_to_their_new_locations(apps, schema_editor):
    ExtensionVersion = apps.get_model('extensions', 'ExtensionVersion')
    versions = ExtensionVersion.objects.all()
    for version in versions:
        # We lost the version number on old deleted versions, nothing we
        # can do about those. It's fine.
        if version.deleted:
            continue

        # Migrations have no access to custom properties and methods, so we
        # have to re-generate file paths.
        unsigned_prefix = os.path.join(
            settings.EXTENSIONS_PATH, str(version.extension.pk))
        signed_prefix = os.path.join(
            settings.SIGNED_EXTENSIONS_PATH, str(version.extension.pk))
        signed_reviewer_prefix = os.path.join(
            settings.EXTENSIONS_PATH, str(version.extension.pk), 'reviewers')
        filename = 'extension-%s.zip' % version.version

        # Original paths have the version number in them.
        original_unsigned_file_path = os.path.join(unsigned_prefix, filename)
        original_signed_file_path = os.path.join(signed_prefix, filename)
        original_reviewer_signed_file_path = os.path.join(
            signed_reviewer_prefix, filename)

        # New paths use the version pk instead, which will always be available.
        new_filename = 'extension-%s.zip' % version.pk
        new_unsigned_file_path = os.path.join(unsigned_prefix, new_filename)
        new_signed_file_path = os.path.join(signed_prefix, new_filename)
        new_reviewer_signed_file_path = os.path.join(
            signed_reviewer_prefix, new_filename)

        # Do the actual moving.
        if private_storage.exists(original_unsigned_file_path):
            move_stored_file(
                original_unsigned_file_path, new_unsigned_file_path)
        if private_storage.exists(original_reviewer_signed_file_path):
            move_stored_file(
                original_reviewer_signed_file_path,
                new_reviewer_signed_file_path)
        if public_storage.exists(original_signed_file_path):
            move_stored_file(
                original_signed_file_path, new_signed_file_path,
                src_storage=public_storage, dst_storage=public_storage)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:44,代码来源:0020_change_filename_scheme.py

示例14: test_upload_new

 def test_upload_new(self):
     eq_(Extension.objects.count(), 0)
     upload = self.upload('extension')
     extension = Extension.from_upload(upload)
     eq_(extension.version, '0.1')
     eq_(extension.name, u'My Lîttle Extension')
     eq_(extension.default_language, 'en-GB')
     eq_(extension.slug, u'my-lîttle-extension')
     eq_(extension.filename, 'extension-%s.zip' % extension.version)
     ok_(extension.filename in extension.file_path)
     ok_(extension.file_path.startswith(extension.path_prefix))
     ok_(private_storage.exists(extension.file_path))
     eq_(extension.manifest, self.expected_manifest)
     eq_(Extension.objects.count(), 1)
开发者ID:ayushagrawal288,项目名称:zamboni,代码行数:14,代码来源:test_models.py

示例15: test_upload_new

 def test_upload_new(self):
     eq_(Extension.objects.count(), 0)
     upload = self.upload('extension')
     extension = Extension.from_upload(upload, user=self.user)
     eq_(extension.version, '0.1')
     eq_(list(extension.authors.all()), [self.user])
     eq_(extension.name, u'My Lîttle Extension')
     eq_(extension.default_language, 'en-GB')
     eq_(extension.slug, u'my-lîttle-extension')
     eq_(extension.filename, 'extension-%s.zip' % extension.version)
     ok_(extension.filename in extension.file_path)
     ok_(private_storage.exists(extension.file_path))
     eq_(extension.manifest, self.expected_manifest)
     eq_(Extension.objects.count(), 1)
开发者ID:shahbaz17,项目名称:zamboni,代码行数:14,代码来源:test_models.py


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