import os import shutil import tempfile import unittest from trac.attachment import Attachment from trac.search.web_ui import SearchModule from trac.wiki.tests import formatter SEARCH_TEST_CASES=""" ============================== search: link resolver search:foo search:"foo bar" [search:bar Bar] [search:bar] [search:] ------------------------------

search:foo search:"foo bar" Bar bar search

------------------------------ ============================== search: link resolver with query arguments search:?q=foo&wiki=on search:"?q=foo bar&wiki=on" [search:?q=bar&ticket=on Bar in Tickets] ------------------------------

search:?q=foo&wiki=on search:"?q=foo bar&wiki=on" Bar in Tickets

------------------------------ """ ATTACHMENT_TEST_CASES=""" ============================== attachment: link resolver (deprecated) attachment:wiki:WikiStart:file.txt (deprecated) attachment:ticket:123:file.txt (deprecated) [attachment:wiki:WikiStart:file.txt file.txt] (deprecated) [attachment:ticket:123:file.txt] (deprecated) ------------------------------

attachment:wiki:WikiStart:file.txt (deprecated) attachment:ticket:123:file.txt (deprecated) file.txt (deprecated) ticket:123:file.txt (deprecated)

------------------------------ ============================== attachment: "foreign" links attachment:file.txt:wiki:WikiStart attachment:file.txt:ticket:123 [attachment:file.txt:wiki:WikiStart file.txt] [attachment:file.txt:ticket:123] attachment:foo.txt:wiki:SomePage/SubPage ------------------------------

attachment:file.txt:wiki:WikiStart attachment:file.txt:ticket:123 file.txt file.txt:ticket:123 attachment:foo.txt:wiki:SomePage/SubPage

------------------------------ ============================== attachment: "local" links attachment:file.txt [attachment:file.txt that file] ------------------------------

attachment:file.txt that file

------------------------------ ============================== attachment: "missing" links attachment:foo.txt [attachment:foo.txt other file] ------------------------------

attachment:foo.txt other file

------------------------------ ============================== attachment: "raw" links raw-attachment:file.txt [raw-attachment:file.txt that file] ------------------------------

raw-attachment:file.txt that file

------------------------------ ============================== attachment: raw format as explicit argument attachment:file.txt?format=raw [attachment:file.txt?format=raw that file] ------------------------------

attachment:file.txt?format=raw that file

------------------------------ """ # " def attachment_setup(tc): import trac.ticket.api import trac.wiki.api tc.env.path = os.path.join(tempfile.gettempdir(), 'trac-tempenv') os.mkdir(tc.env.path) attachment = Attachment(tc.env, 'wiki', 'WikiStart') attachment.insert('file.txt', tempfile.TemporaryFile(), 0) attachment = Attachment(tc.env, 'ticket', 123) attachment.insert('file.txt', tempfile.TemporaryFile(), 0) attachment = Attachment(tc.env, 'wiki', 'SomePage/SubPage') attachment.insert('foo.txt', tempfile.TemporaryFile(), 0) def attachment_teardown(tc): shutil.rmtree(tc.env.path) def suite(): suite = unittest.TestSuite() suite.addTest(formatter.suite(SEARCH_TEST_CASES, file=__file__)) suite.addTest(formatter.suite(ATTACHMENT_TEST_CASES, file=__file__, context=('wiki', 'WikiStart'), setup=attachment_setup, teardown=attachment_teardown)) return suite if __name__ == '__main__': unittest.main(defaultTest='suite')