本文整理汇总了Python中files.helpers.FileViewer.select方法的典型用法代码示例。如果您正苦于以下问题:Python FileViewer.select方法的具体用法?Python FileViewer.select怎么用?Python FileViewer.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类files.helpers.FileViewer
的用法示例。
在下文中一共展示了FileViewer.select方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_as_editor
# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import select [as 别名]
#.........这里部分代码省略.........
def test_view_access_another_developer_view_source(self):
self.client.logout()
assert self.client.login(username=self.regular.email,
password='password')
self.addon.update(view_source=True)
self.file_viewer.extract()
self.check_urls(200)
def test_poll_extracted(self):
self.file_viewer.extract()
res = self.client.get(self.poll_url())
eq_(res.status_code, 200)
eq_(json.loads(res.content)['status'], True)
def test_poll_not_extracted(self):
res = self.client.get(self.poll_url())
eq_(res.status_code, 200)
eq_(json.loads(res.content)['status'], False)
def test_poll_extracted_anon(self):
self.client.logout()
res = self.client.get(self.poll_url())
eq_(res.status_code, 403)
def test_content_headers(self):
self.file_viewer.extract()
res = self.client.get(self.file_url('install.js'))
assert 'etag' in res._headers
assert 'last-modified' in res._headers
def test_content_headers_etag(self):
self.file_viewer.extract()
self.file_viewer.select('install.js')
obj = getattr(self.file_viewer, 'left', self.file_viewer)
etag = obj.selected.get('md5')
res = self.client.get(self.file_url('install.js'),
HTTP_IF_NONE_MATCH=etag)
eq_(res.status_code, 304)
def test_content_headers_if_modified(self):
self.file_viewer.extract()
self.file_viewer.select('install.js')
obj = getattr(self.file_viewer, 'left', self.file_viewer)
date = http_date(obj.selected.get('modified'))
res = self.client.get(self.file_url('install.js'),
HTTP_IF_MODIFIED_SINCE=date)
eq_(res.status_code, 304)
def test_file_header(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(not_binary))
url = res.context['file_link']['url']
eq_(url, reverse('editors.review', args=[self.addon.slug]))
def test_file_header_anon(self):
self.client.logout()
self.file_viewer.extract()
self.addon.update(view_source=True)
res = self.client.get(self.file_url(not_binary))
url = res.context['file_link']['url']
eq_(url, reverse('addons.detail', args=[self.addon.pk]))
def test_content_no_file(self):
self.file_viewer.extract()
res = self.client.get(self.file_url())
示例2: TestFileHelper
# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import select [as 别名]
#.........这里部分代码省略.........
[u'unicodesomelong삮.txt', u'unicodesomelong...txt'],
['somelongfilename.somelongextension',
'somelongfilenam...somelonge..'],):
eq_(truncate(x), y)
def test_get_files_not_extracted(self):
assert not self.viewer.get_files()
def test_get_files_size(self):
self.viewer.extract()
files = self.viewer.get_files()
eq_(len(files), 14)
def test_get_files_directory(self):
self.viewer.extract()
files = self.viewer.get_files()
eq_(files['install.js']['directory'], False)
eq_(files['install.js']['binary'], False)
eq_(files['__MACOSX']['directory'], True)
eq_(files['__MACOSX']['binary'], False)
def test_url_file(self):
self.viewer.extract()
files = self.viewer.get_files()
url = reverse('files.list', args=[self.viewer.file.id,
'file', 'install.js'])
assert files['install.js']['url'].endswith(url)
def test_get_files_depth(self):
self.viewer.extract()
files = self.viewer.get_files()
eq_(files['dictionaries/license.txt']['depth'], 1)
def test_bom(self):
dest = os.path.join(settings.TMP_PATH, 'test_bom')
open(dest, 'w').write('foo'.encode('utf-16'))
self.viewer.select('foo')
self.viewer.selected = {'full': dest, 'size': 1}
eq_(self.viewer.read_file(), u'foo')
os.remove(dest)
def test_syntax(self):
for filename, syntax in [('foo.rdf', 'xml'),
('foo.xul', 'xml'),
('foo.json', 'js'),
('foo.jsm', 'js'),
('foo.bar', 'plain')]:
eq_(self.viewer.get_syntax(filename), syntax)
def test_file_order(self):
self.viewer.extract()
dest = self.viewer.dest
open(os.path.join(dest, 'chrome.manifest'), 'w')
subdir = os.path.join(dest, 'chrome')
os.mkdir(subdir)
open(os.path.join(subdir, 'foo'), 'w')
cache.clear()
files = self.viewer.get_files().keys()
rt = files.index(u'chrome')
eq_(files[rt:rt + 3], [u'chrome', u'chrome/foo', u'dictionaries'])
@patch.object(settings, 'FILE_VIEWER_SIZE_LIMIT', 5)
def test_file_size(self):
self.viewer.extract()
self.viewer.get_files()
self.viewer.select('install.js')
res = self.viewer.read_file()
eq_(res, '')
assert self.viewer.selected['msg'].startswith('File size is')
@patch.object(settings, 'FILE_VIEWER_SIZE_LIMIT', 5)
def test_file_size_unicode(self):
with self.activate(locale='he'):
self.viewer.extract()
self.viewer.get_files()
self.viewer.select('install.js')
res = self.viewer.read_file()
eq_(res, '')
assert self.viewer.selected['msg'].startswith('File size is')
@patch.object(settings, 'FILE_UNZIP_SIZE_LIMIT', 5)
def test_contents_size(self):
self.assertRaises(forms.ValidationError, self.viewer.extract)
def test_default(self):
eq_(self.viewer.get_default(None), 'install.rdf')
def test_delete_mid_read(self):
self.viewer.extract()
self.viewer.select('install.js')
os.remove(os.path.join(self.viewer.dest, 'install.js'))
res = self.viewer.read_file()
eq_(res, '')
assert self.viewer.selected['msg'].startswith('That file no')
@patch('files.helpers.get_md5')
def test_delete_mid_tree(self, get_md5):
get_md5.side_effect = IOError('ow')
self.viewer.extract()
eq_({}, self.viewer.get_files())
示例3: login_as_editor
# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import select [as 别名]
#.........这里部分代码省略.........
def test_view_access_another_developer_view_source(self):
self.client.logout()
assert self.client.login(username=self.regular.email,
password='password')
self.addon.update(view_source=True)
self.file_viewer.extract()
self.check_urls(200)
def test_poll_extracted(self):
self.file_viewer.extract()
res = self.client.get(self.poll_url())
eq_(res.status_code, 200)
eq_(json.loads(res.content)['status'], True)
def test_poll_not_extracted(self):
res = self.client.get(self.poll_url())
eq_(res.status_code, 200)
eq_(json.loads(res.content)['status'], False)
def test_poll_extracted_anon(self):
self.client.logout()
res = self.client.get(self.poll_url())
eq_(res.status_code, 403)
def test_content_headers(self):
self.file_viewer.extract()
res = self.client.get(self.file_url('install.js'))
assert 'etag' in res._headers
assert 'last-modified' in res._headers
def test_content_headers_etag(self):
self.file_viewer.extract()
self.file_viewer.select('install.js')
obj = getattr(self.file_viewer, 'left', self.file_viewer)
etag = obj.selected.get('md5')
res = self.client.get(self.file_url('install.js'),
HTTP_IF_NONE_MATCH=etag)
eq_(res.status_code, 304)
def test_content_headers_if_modified(self):
self.file_viewer.extract()
self.file_viewer.select('install.js')
obj = getattr(self.file_viewer, 'left', self.file_viewer)
date = http_date(obj.selected.get('modified'))
res = self.client.get(self.file_url('install.js'),
HTTP_IF_MODIFIED_SINCE=date)
eq_(res.status_code, 304)
def test_file_header(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(not_binary))
url = res.context['file_link']['url']
eq_(url, reverse('editors.review', args=[self.addon.slug]))
def test_file_header_anon(self):
self.client.logout()
self.file_viewer.extract()
self.addon.update(view_source=True)
res = self.client.get(self.file_url(not_binary))
url = res.context['file_link']['url']
eq_(url, reverse('addons.detail', args=[self.addon.pk]))
def test_content_no_file(self):
self.file_viewer.extract()
res = self.client.get(self.file_url())
示例4: FilesBase
# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import select [as 别名]
#.........这里部分代码省略.........
def test_view_access_another_developer_view_source(self):
self.client.logout()
assert self.client.login(username=self.regular.email,
password='password')
self.app.update(view_source=True, status=amo.STATUS_PUBLIC)
self.file_viewer.extract()
self.check_urls(200)
def test_poll_extracted(self):
self.file_viewer.extract()
res = self.client.get(self.poll_url())
eq_(res.status_code, 200)
eq_(json.loads(res.content)['status'], True)
def test_poll_not_extracted(self):
res = self.client.get(self.poll_url())
eq_(res.status_code, 200)
eq_(json.loads(res.content)['status'], False)
def test_poll_extracted_anon(self):
self.client.logout()
res = self.client.get(self.poll_url())
eq_(res.status_code, 403)
def test_content_headers(self):
self.file_viewer.extract()
res = self.client.get(self.file_url('manifest.webapp'))
assert 'etag' in res._headers
assert 'last-modified' in res._headers
def test_content_headers_etag(self):
self.file_viewer.extract()
self.file_viewer.select('manifest.webapp')
obj = getattr(self.file_viewer, 'left', self.file_viewer)
etag = obj.selected.get('md5')
res = self.client.get(self.file_url('manifest.webapp'),
HTTP_IF_NONE_MATCH=etag)
eq_(res.status_code, 304)
def test_content_headers_if_modified(self):
self.file_viewer.extract()
self.file_viewer.select('manifest.webapp')
obj = getattr(self.file_viewer, 'left', self.file_viewer)
date = http_date(obj.selected.get('modified'))
res = self.client.get(self.file_url('manifest.webapp'),
HTTP_IF_MODIFIED_SINCE=date)
eq_(res.status_code, 304)
def test_file_header(self):
self.file_viewer.extract()
res = self.client.get(self.file_url(not_binary))
eq_(res.status_code, 200)
url = res.context['file_link']['url']
eq_(url, reverse('reviewers.apps.review', args=[self.app.app_slug]))
def test_file_header_anon(self):
self.client.logout()
self.file_viewer.extract()
self.app.update(view_source=True, status=amo.STATUS_PUBLIC)
res = self.client.get(self.file_url(not_binary))
eq_(res.status_code, 200)
url = res.context['file_link']['url']
eq_(url, reverse('detail', args=[self.app.pk]))
def test_content_no_file(self):
示例5: TestFileHelper
# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import select [as 别名]
#.........这里部分代码省略.........
m, encoding = mimetypes.guess_type(filename)
assert not binary(m, filename), "%s should not be binary" % txt
for txt in ["MZ"]:
open(filename, "w").write(txt)
m, encoding = mimetypes.guess_type(filename)
assert binary(m, filename), "%s should be binary" % txt
os.remove(filename)
def test_truncate(self):
truncate = self.viewer.truncate
for x, y in (
["foo.rdf", "foo.rdf"],
["somelongfilename.rdf", "somelongfilenam...rdf"],
[u"unicode삮.txt", u"unicode\uc0ae.txt"],
[u"unicodesomelong삮.txt", u"unicodesomelong...txt"],
["somelongfilename.somelongextension", "somelongfilenam...somelonge.."],
):
eq_(truncate(x), y)
def test_get_files_not_extracted(self):
assert not self.viewer.get_files()
def test_get_files_size(self):
self.viewer.extract()
files = self.viewer.get_files()
eq_(len(files), 14)
def test_get_files_directory(self):
self.viewer.extract()
files = self.viewer.get_files()
eq_(files["install.js"]["directory"], False)
eq_(files["install.js"]["binary"], False)
eq_(files["__MACOSX"]["directory"], True)
eq_(files["__MACOSX"]["binary"], False)
def test_url_file(self):
self.viewer.extract()
files = self.viewer.get_files()
url = reverse("files.list", args=[self.viewer.file.id, "file", "install.js"])
assert files["install.js"]["url"].endswith(url)
def test_get_files_depth(self):
self.viewer.extract()
files = self.viewer.get_files()
eq_(files["dictionaries/license.txt"]["depth"], 1)
def test_bom(self):
dest = os.path.join(settings.TMP_PATH, "test_bom")
open(dest, "w").write("foo".encode("utf-16"))
self.viewer.select("foo")
self.viewer.selected = {"full": dest, "size": 1}
eq_(self.viewer.read_file(), u"foo")
os.remove(dest)
def test_syntax(self):
for filename, syntax in [("foo.rdf", "xml"), ("foo.xul", "xml"), ("foo.bar", "plain")]:
eq_(self.viewer.get_syntax(filename), syntax)
def test_file_order(self):
self.viewer.extract()
dest = self.viewer.dest
open(os.path.join(dest, "chrome.manifest"), "w")
subdir = os.path.join(dest, "chrome")
os.mkdir(subdir)
open(os.path.join(subdir, "foo"), "w")
cache.clear()
files = self.viewer.get_files().keys()
rt = files.index(u"chrome")
eq_(files[rt : rt + 3], [u"chrome", u"chrome/foo", u"chrome.manifest"])
@patch.object(settings, "FILE_VIEWER_SIZE_LIMIT", 5)
def test_file_size(self):
self.viewer.extract()
self.viewer.get_files()
self.viewer.select("install.js")
res = self.viewer.read_file()
eq_(res, "")
assert self.viewer.selected["msg"].startswith("File size is")
@patch.object(settings, "FILE_UNZIP_SIZE_LIMIT", 5)
def test_contents_size(self):
self.assertRaises(forms.ValidationError, self.viewer.extract)
def test_default(self):
eq_(self.viewer.get_default(None), "install.rdf")
def test_delete_mid_read(self):
self.viewer.extract()
self.viewer.select("install.js")
os.remove(os.path.join(self.viewer.dest, "install.js"))
res = self.viewer.read_file()
eq_(res, "")
assert self.viewer.selected["msg"].startswith("That file no")
@patch("files.helpers.get_md5")
def test_delete_mid_tree(self, get_md5):
get_md5.side_effect = IOError("ow")
self.viewer.extract()
eq_({}, self.viewer.get_files())