本文整理汇总了Python中trac.wiki.WikiPage类的典型用法代码示例。如果您正苦于以下问题:Python WikiPage类的具体用法?Python WikiPage怎么用?Python WikiPage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WikiPage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_existing_page
def test_existing_page(self):
t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
self.env.db_transaction(
"INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
('TestPage', 1, to_utimestamp(t), 'joe', '::1', 'Bla bla',
'Testing', 0))
page = WikiPage(self.env, 'TestPage')
self.assertTrue(page.exists)
self.assertEqual('TestPage', page.name)
self.assertEqual(1, page.version)
self.assertIsNone(page.resource.version) # FIXME: Intentional?
self.assertEqual('Bla bla', page.text)
self.assertEqual(0, page.readonly)
self.assertEqual('joe', page.author)
self.assertEqual('Testing', page.comment)
self.assertEqual(t, page.time)
history = list(page.get_history())
self.assertEqual(1, len(history))
self.assertEqual((1, t, 'joe', 'Testing', '::1'), history[0])
page = WikiPage(self.env, 'TestPage', 1)
self.assertEqual(1, page.resource.version)
self.assertEqual(1, page.version)
resource = Resource('wiki', 'TestPage')
page = WikiPage(self.env, resource, 1)
self.assertEqual(1, page.version)
示例2: _do_uploadPicture
def _do_uploadPicture(self, req, userProfile, teamRosterData, req_arg_picture = 'tr_userProfile_picture' ):
upload = req.args.get(req_arg_picture, None)
if upload == None or not hasattr(upload, 'filename') or not upload.filename:
return userProfile.picture_href
if hasattr(upload.file, 'fileno'):
size = os.fstat(upload.file.fileno())[6]
else:
upload.file.seek(0, 2) # seek to end of file
size = upload.file.tell()
upload.file.seek(0)
if size == 0:
raise TracError(_("Can't upload empty file"))
filename = upload.filename
filename = filename.replace('\\', '/').replace(':', '/')
filename = os.path.basename(filename)
if not filename:
raise TracError(_('No file uploaded'))
page = WikiPage(self.env, self.teamRoster_wikiPage)
if not page.exists:
page.text="= Team Roster Pictures ="
page.save( 'trac', 'Page created by tracteamroster component', req.remote_addr)
attachment = Attachment(self.env, 'wiki', self.teamRoster_wikiPage)
attachment.author = get_reporter_id(req, 'author')
attachment.ipnr = req.remote_addr
attachment.insert('_'.join([userProfile.id, filename]), upload.file, size)
return req.href('/'.join(['raw-attachment', 'wiki',self.teamRoster_wikiPage,attachment.filename]))
示例3: process_request
def process_request(self, req):
req.perm.assert_permission ('WIKI_MODIFY')
page_name = req.args['target_page'][req.args['target_page'].find('wiki')+5:]
p = WikiPage(self.env, page_name )
author_name = req.authname
comment_text = req.args['comment']
comment_parent = req.args['comment_parent']
dt = datetime.now()
comment_date = dt.strftime("%Y-%m-%d %H:%M:%S")
comment_id = "%032x" % random.getrandbits(128)
redirect_url = "%s%s#%s" % (req.base_path, req.args['target_page'],comment_id)
changeset_comment = "%s..." % comment_text[:20]
insertion_index = string.find( p.text, "=%s" % comment_parent )
if ( insertion_index != -1 ):
heads = string.count(p.text,"{{{#!WikiComments",0,insertion_index)
tails = string.count(p.text,"}}}",0,insertion_index)
level = heads - tails
padding = ""
comment_out = '%s{{{#!WikiComments author="%s" date="%s" id="%s""\n%s%s\n%s=%s\n%s}}}\n' \
% (padding, author_name,comment_date,comment_id,padding,comment_text,padding,comment_id,padding)
p.text = p.text[:insertion_index]+comment_out+p.text[insertion_index:]
p.save( author_name, changeset_comment, req.remote_addr )
req.redirect(redirect_url)
示例4: test_rename_page
def test_rename_page(self):
data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
self.env.db_transaction(
"INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
('TestPage',) + data)
attachment = Attachment(self.env, 'wiki', 'TestPage')
attachment.insert('foo.txt', StringIO(), 0, 1)
page = WikiPage(self.env, 'TestPage')
page.rename('PageRenamed')
self.assertEqual('PageRenamed', page.name)
self.assertEqual('PageRenamed', page.resource.id)
self.assertEqual([data], self.env.db_query("""
SELECT version, time, author, ipnr, text, comment, readonly
FROM wiki WHERE name=%s
""", ('PageRenamed',)))
attachments = Attachment.select(self.env, 'wiki', 'PageRenamed')
self.assertEqual('foo.txt', attachments.next().filename)
self.assertRaises(StopIteration, attachments.next)
Attachment.delete_all(self.env, 'wiki', 'PageRenamed')
old_page = WikiPage(self.env, 'TestPage')
self.assertFalse(old_page.exists)
self.assertEqual([], self.env.db_query("""
SELECT version, time, author, ipnr, text, comment, readonly
FROM wiki WHERE name=%s
""", ('TestPage',)))
listener = TestWikiChangeListener(self.env)
self.assertEqual((page, 'TestPage'), listener.renamed[0])
示例5: test_rename_page
def test_rename_page(self):
cursor = self.db.cursor()
data = (1, 42, 'joe', '::1', 'Bla bla', 'Testing', 0)
cursor.execute("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
('TestPage',) + data)
attachment = Attachment(self.env, 'wiki', 'TestPage')
attachment.insert('foo.txt', StringIO(), 0, 1)
page = WikiPage(self.env, 'TestPage')
page.rename('PageRenamed')
self.assertEqual('PageRenamed', page.name)
cursor.execute("SELECT version,time,author,ipnr,text,comment,"
"readonly FROM wiki WHERE name=%s", ('PageRenamed',))
self.assertEqual(data, cursor.fetchone())
self.assertEqual(None, cursor.fetchone())
attachments = Attachment.select(self.env, 'wiki', 'PageRenamed')
self.assertEqual('foo.txt', attachments.next().filename)
self.assertRaises(StopIteration, attachments.next)
Attachment.delete_all(self.env, 'wiki', 'PageRenamed', self.db)
old_page = WikiPage(self.env, 'TestPage')
self.assertEqual(False, old_page.exists)
cursor.execute("SELECT version,time,author,ipnr,text,comment,"
"readonly FROM wiki WHERE name=%s", ('TestPage',))
self.assertEqual(None, cursor.fetchone())
listener = TestWikiChangeListener(self.env)
self.assertEqual((page, 'TestPage'), listener.renamed[0])
示例6: test_wiki_page_unicode_error
def test_wiki_page_unicode_error(self):
import pkg_resources
import define
text = open(pkg_resources.resource_filename(define.__name__, 'default-pages/DefineGuide%2FTicketTutorial')).read()
page = WikiPage(self.env, 'TicketTutorial')
page.text = text.decode('utf-8')
page.save('olle', 'Comment', 'define.logica.com')
so = self._get_so()
self.assertEquals('%s:wiki:TicketTutorial' % self.basename, so.doc_id)
示例7: _create_wiki_page
def _create_wiki_page(self, name=None):
name = name or self.INITIAL_NAME
wiki_page = WikiPage(self.env, name)
wiki_page.text = self.INITIAL_TEXT
wiki_page.save(
self.INITIAL_AUTHOR,
self.INITIAL_COMMENT,
self.INITIAL_REMOTE_ADDRESS)
return wiki_page
示例8: test_parseTestcase_parseWikiPage
def test_parseTestcase_parseWikiPage(build_trac_env):
env = build_trac_env
wikipage = WikiPage(env, "TcTestplanCreate")
wikipage.text = TESTCASE.decode("utf-8")
wikipage.save("pytest", "comment", "127.0.0.1")
tcp = TestcaseParser(env)
testcase = tcp.parseTestcase(pagename="TcTestplanCreate")
assert len(testcase.actions) == 5
示例9: test_can_index_renamed_event
def test_can_index_renamed_event(self):
#arrange
self.insert_wiki(self.DUMMY_PAGE_NAME)
page = WikiPage(self.env, self.DUMMY_PAGE_NAME)
page.rename("NewPageName")
#act
results = self.search_api.query("*:*")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
self.assertEqual("NewPageName", results.docs[0]["id"])
示例10: _term_desc
def _term_desc(self, target):
page = self._wiki_prefix + target
content = WikiPage(self.env, page).text
lines = content.splitlines()
if len(lines) <= 0:
return target
m = self._desc_regex.match(lines[0])
if m:
return m.group(1)
else:
return self._term_ns + ":" + target
示例11: test_can_index_changed_event
def test_can_index_changed_event(self):
#arrange
self.insert_wiki(self.DUMMY_PAGE_NAME, "Text to be changed")
page = WikiPage(self.env, self.DUMMY_PAGE_NAME)
page.text = "changed text with keyword"
page.save("anAuthor", "some comment", "::1")
#act
results = self.search_api.query("*:*")
#assert
self.print_result(results)
self.assertEqual(1, results.hits)
doc = results.docs[0]
self.assertEqual("changed text with keyword", doc["content"])
示例12: test_create_page
def test_create_page(self):
page = WikiPage(self.env)
page.name = "TestPage"
page.text = "Bla bla"
page.save("joe", "Testing", "::1", 42)
cursor = self.db.cursor()
cursor.execute(
"SELECT version,time,author,ipnr,text,comment," "readonly FROM wiki WHERE name=%s", ("TestPage",)
)
self.assertEqual((1, 42, "joe", "::1", "Bla bla", "Testing", 0), cursor.fetchone())
listener = TestWikiChangeListener(self.env)
self.assertEqual(page, listener.added[0])
示例13: test_existing_page
def test_existing_page(self):
t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
cursor = self.db.cursor()
cursor.execute("INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
('TestPage', 0, to_timestamp(t), 'joe', '::1', 'Bla bla',
'Testing', 0))
page = WikiPage(self.env, 'TestPage')
self.assertEqual('TestPage', page.name)
self.assertEqual(0, page.version)
self.assertEqual('Bla bla', page.text)
self.assertEqual(False, page.readonly)
history = list(page.get_history())
self.assertEqual(1, len(history))
self.assertEqual((0, t, 'joe', 'Testing', '::1'), history[0])
示例14: test_create_page
def test_create_page(self):
page = WikiPage(self.env)
page.name = 'TestPage'
page.text = 'Bla bla'
t = datetime(2001, 1, 1, 1, 1, 1, 0, utc)
page.save('joe', 'Testing', '::1', t)
cursor = self.db.cursor()
cursor.execute("SELECT version,time,author,ipnr,text,comment,"
"readonly FROM wiki WHERE name=%s", ('TestPage',))
self.assertEqual((1, to_timestamp(t), 'joe', '::1', 'Bla bla', 'Testing', 0),
cursor.fetchone())
listener = TestWikiChangeListener(self.env)
self.assertEqual(page, listener.added[0])
示例15: test_existing_page
def test_existing_page(self):
cursor = self.db.cursor()
cursor.execute(
"INSERT INTO wiki VALUES(%s,%s,%s,%s,%s,%s,%s,%s)",
("TestPage", 0, 42, "joe", "::1", "Bla bla", "Testing", 0),
)
page = WikiPage(self.env, "TestPage")
self.assertEqual("TestPage", page.name)
self.assertEqual(0, page.version)
self.assertEqual("Bla bla", page.text)
self.assertEqual(False, page.readonly)
history = list(page.get_history())
self.assertEqual(1, len(history))
self.assertEqual((0, 42, "joe", "Testing", "::1"), history[0])