本文整理汇总了Python中MoinMoin.action.AttachFile.add_attachment方法的典型用法代码示例。如果您正苦于以下问题:Python AttachFile.add_attachment方法的具体用法?Python AttachFile.add_attachment怎么用?Python AttachFile.add_attachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoinMoin.action.AttachFile
的用法示例。
在下文中一共展示了AttachFile.add_attachment方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cache_key_attachment
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import add_attachment [as 别名]
def test_cache_key_attachment(self):
request = self.request
pagename = self.pagename
attachname = 'foo.txt'
become_trusted(request)
create_page(request, pagename, u"Foo!")
AttachFile.add_attachment(request, pagename, attachname, "Test content1", True)
result1 = cache.key(request, itemname=pagename, attachname=attachname, secret='bar')
result2 = cache.key(request, itemname=pagename, attachname=attachname, secret='baz')
assert result1 # not empty
assert result1 != result2 # different for different secret
# test below does not work, because mtime is often same, inode can be same due to how add_attachment
# works, file size is same, attachment name is same, wikiname/pagename is same.
# In practice, this should rather rarely cause problems:
#AttachFile.add_attachment(request, pagename, attachname, "Test content2", True)
#result3 = cache.key(request, itemname=pagename, attachname=attachname, secret='baz')
#assert result3 != result2 # different for different content
AttachFile.add_attachment(request, pagename, attachname, "Test content33333", True)
result4 = cache.key(request, itemname=pagename, attachname=attachname, secret='baz')
assert len(result4) == len(result2) # same length of key for different input lengths
nuke_page(request, pagename)
示例2: test_attachment
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import add_attachment [as 别名]
def test_attachment(self):
page_name = u'TestAttachment'
self.pages[page_name] = 'some text' # Moin search must search this page
filename = "AutoCreatedSillyAttachmentForSearching.png"
data = "Test content"
filecontent = StringIO.StringIO(data)
result = self.search(filename)
found_attachments = set([(hit.page_name, hit.attachment) for hit in result.hits])
assert not found_attachments
try:
create_page(self.request, page_name, self.pages[page_name])
AttachFile.add_attachment(self.request, page_name, filename, filecontent, True)
append_page(self.request, page_name, '[[attachment:%s]]' % filename)
self._index_update()
result = self.search(filename)
found_attachments = set([(hit.page_name, hit.attachment) for hit in result.hits])
assert (page_name, '') in found_attachments
assert 1 <= len(found_attachments) <= 2
# Note: moin search returns (page_name, '') as only result
# xapian search returns 2 results: (page_name, '') and (page_name, filename)
# TODO: make behaviour the same, if possible
finally:
nuke_page(self.request, page_name)
del self.pages[page_name]
self._index_update()
result = self.search(filename)
found_attachments = set([(hit.page_name, hit.attachment) for hit in result.hits])
assert not found_attachments
示例3: addAttachment
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import add_attachment [as 别名]
def addAttachment(self, name, content):
"""add image to attachment"""
if os.path.splitext(name)[1].lower() not in \
['.' + x for x in self.image_extenstions]:
name += '.jpg' # if the url didn't contain a image extention
AttachFile.add_attachment(self.request,
self.pagename,
name,
content,
True)
return wikiutil.taintfilename(name)
示例4: test_add_attachment
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import add_attachment [as 别名]
def test_add_attachment(self):
"""Test if add_attachment() works"""
become_trusted(self.request)
filename = "AutoCreatedSillyAttachment"
create_page(self.request, self.pagename, u"Foo!")
AttachFile.add_attachment(self.request, self.pagename, filename, "Test content", True)
exists = AttachFile.exists(self.request, self.pagename, filename)
nuke_page(self.request, self.pagename)
assert exists
示例5: setup_class
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import add_attachment [as 别名]
def setup_class(self):
request = self.request
pagename = self.pagename
become_trusted(request)
self.page = create_page(request, pagename, u"Foo")
AttachFile.getAttachDir(request, pagename)
test_files = [
('test.ogg', 'vorbis'),
('test.svg', 'SVG'),
('test.mpg', 'MPG'),
('test.pdf', 'PDF'),
('test.mp3', 'MP3'),
]
for filename, filecontent in test_files:
AttachFile.add_attachment(request, pagename, filename, filecontent, overwrite=0)
示例6: test_add_attachment_for_file_object
# 需要导入模块: from MoinMoin.action import AttachFile [as 别名]
# 或者: from MoinMoin.action.AttachFile import add_attachment [as 别名]
def test_add_attachment_for_file_object(self):
"""Test if add_attachment() works with file like object"""
become_trusted(self.request)
filename = "AutoCreatedSillyAttachment.png"
create_page(self.request, self.pagename, u"FooBar!")
data = "Test content"
filecontent = StringIO.StringIO(data)
AttachFile.add_attachment(self.request, self.pagename, filename, filecontent, True)
exists = AttachFile.exists(self.request, self.pagename, filename)
path = AttachFile.getAttachDir(self.request, self.pagename)
imagef = os.path.join(path, filename)
file_size = os.path.getsize(imagef)
nuke_page(self.request, self.pagename)
assert exists and file_size == len(data)