本文整理汇总了Python中mkt.site.storage_utils.public_storage.exists函数的典型用法代码示例。如果您正苦于以下问题:Python exists函数的具体用法?Python exists怎么用?Python exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exists函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: image_status
def image_status(request, addon_id, addon, icon_size=64):
# Default icon needs no checking.
if not addon.icon_type or addon.icon_type.split("/")[0] == "icon":
icons = True
else:
icons = public_storage.exists(os.path.join(addon.get_icon_dir(), "%s-%s.png" % (addon.id, icon_size)))
previews = all(public_storage.exists(p.thumbnail_path) for p in addon.get_previews())
return {"overall": icons and previews, "icons": icons, "previews": previews}
示例2: check_delete
def check_delete(self, file_, filename):
"""Test that when the File object is deleted, it is removed from the
filesystem."""
try:
with public_storage.open(filename, 'w') as f:
f.write('sample data\n')
assert public_storage.exists(filename)
file_.delete()
assert not public_storage.exists(filename)
finally:
if public_storage.exists(filename):
public_storage.delete(filename)
示例3: image_status
def image_status(request, addon_id, addon, icon_size=64):
# Default icon needs no checking.
if not addon.icon_type or addon.icon_type.split('/')[0] == 'icon':
icons = True
else:
icons = public_storage.exists(
os.path.join(addon.get_icon_dir(), '%s-%s.png' % (
addon.id, icon_size)))
previews = all(public_storage.exists(p.thumbnail_path)
for p in addon.get_previews())
return {'overall': icons and previews,
'icons': icons,
'previews': previews}
示例4: test_delete_with_file
def test_delete_with_file(self):
"""Test that when a LangPack instance is deleted, the corresponding
file on the filesystem is also deleted."""
langpack = LangPack.objects.create(version='0.1')
file_path = langpack.file_path
with public_storage.open(file_path, 'w') as f:
f.write('sample data\n')
assert public_storage.exists(file_path)
try:
langpack.delete()
assert not public_storage.exists(file_path)
finally:
if public_storage.exists(file_path):
public_storage.delete(file_path)
示例5: 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)
示例6: 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)
示例7: test_unhide_disabled_files
def test_unhide_disabled_files(self):
f = File.objects.get()
f.status = mkt.STATUS_PUBLIC
with private_storage.open(f.guarded_file_path, 'wb') as fp:
fp.write('some data\n')
f.unhide_disabled_file()
assert public_storage.exists(f.file_path)
assert public_storage.open(f.file_path).size
示例8: test_delete_no_file
def test_delete_no_file(self):
"""Test that the file object can be deleted without the file being
present."""
f = File.objects.get()
filename = f.file_path
assert not public_storage.exists(filename), ('File exists at: %s' %
filename)
f.delete()
示例9: test_delete_no_file
def test_delete_no_file(self):
"""Test that the LangPack instance can be deleted without the file
being present."""
langpack = LangPack.objects.create(version='0.1')
filename = langpack.file_path
x = public_storage.exists(filename)
assert not x, 'File exists at: %s' % filename
langpack.delete()
示例10: remove_public_signed_file
def remove_public_signed_file(self):
"""Remove the public signed file if it exists.
Return the size of the unsigned file, to be used by the caller to
update the size property on the current instance."""
if public_storage.exists(self.signed_file_path):
public_storage.delete(self.signed_file_path)
return private_storage.size(self.file_path)
示例11: test_export_is_created
def test_export_is_created(self):
expected_files = [self.app_path, "license.txt", "readme.txt"]
tarball = self.create_export("tarball-name")
actual_files = tarball.getnames()
for expected_file in expected_files:
assert expected_file in actual_files, expected_file
# Make sure we didn't touch old tarballs by accident.
assert public_storage.exists(self.existing_tarball)
示例12: test_no_resize_when_exact
def test_no_resize_when_exact(self, fake_req, resize):
url = 'http://site/media/my.jpg'
(fake_req.expects('get')
.returns_fake()
.expects('iter_content')
.returns(self.open_img())
.expects('raise_for_status'))
size = 64
self.fetch(url=url, ext_size=size, size=size)
prod = ProductIcon.objects.get()
eq_(prod.size, size)
assert public_storage.exists(prod.storage_path()), 'Image not created'
示例13: test_resize_transparency
def test_resize_transparency():
src = get_image_path('transparent.png')
dest = tempfile.mkstemp(dir=settings.TMP_PATH)[1]
expected = src.replace('.png', '-expected.png')
if storage_is_remote():
copy_to_storage(src, src, src_storage=local_storage)
try:
resize_image(src, dest, (32, 32), remove_src=False)
with public_storage.open(dest) as dfh:
with open(expected) as efh:
assert dfh.read() == efh.read()
finally:
if public_storage.exists(dest):
public_storage.delete(dest)
示例14: _uploader
def _uploader(resize_size, final_size):
img = get_image_path('mozilla.png')
original_size = (339, 128)
for rsize, fsize in zip(resize_size, final_size):
dest_name = os.path.join(settings.ADDON_ICONS_PATH, '1234')
src = tempfile.NamedTemporaryFile(mode='r+w+b', suffix='.png',
delete=False)
# resize_icon removes the original, copy it to a tempfile and use that.
copy_stored_file(img, src.name, src_storage=local_storage,
dest_storage=private_storage)
# Sanity check.
with private_storage.open(src.name) as fp:
src_image = Image.open(fp)
src_image.load()
eq_(src_image.size, original_size)
val = tasks.resize_icon(src.name, dest_name, resize_size)
eq_(val, {'icon_hash': 'bb362450'})
dest_image_filename = '%s-%s.png' % (dest_name, rsize)
with public_storage.open(dest_image_filename) as fp:
dest_image = Image.open(fp)
dest_image.load()
# Assert that the width is always identical.
eq_(dest_image.size[0], fsize[0])
# Assert that the height can be a wee bit fuzzy.
assert -1 <= dest_image.size[1] - fsize[1] <= 1, (
'Got width %d, expected %d' % (
fsize[1], dest_image.size[1]))
if public_storage.exists(dest_image_filename):
public_storage.delete(dest_image_filename)
assert not public_storage.exists(dest_image_filename)
assert not private_storage.exists(src.name)
示例15: test_fetch_ok
def test_fetch_ok(self, fake_req):
url = 'http://site/media/my.jpg'
ext_size = 512
size = 64
(fake_req.expects('get')
.with_args(url, timeout=arg.any())
.returns_fake()
.expects('iter_content')
.returns(self.open_img())
.expects('raise_for_status'))
self.fetch(url, ext_size, size)
prod = ProductIcon.objects.get()
eq_(prod.ext_size, ext_size)
eq_(prod.size, size)
assert public_storage.exists(prod.storage_path()), 'Image not created'