Package trac :: Package ticket :: Package tests :: Module wikisyntax

Source Code for Module trac.ticket.tests.wikisyntax

  1  # -*- coding: utf-8 -*- 
  2   
  3  import unittest 
  4   
  5  from trac.ticket.model import Ticket 
  6  from trac.ticket.roadmap import Milestone 
  7  from trac.ticket.query import QueryModule 
  8  from trac.ticket.report import ReportModule 
  9  from trac.wiki.tests import formatter 
 10   
 11  TICKET_TEST_CASES=u""" 
 12  ============================== ticket: link resolver 
 13  ticket:1 
 14  ticket:12 
 15  ticket:abc 
 16  ------------------------------ 
 17  <p> 
 18  <a class="new ticket" href="/ticket/1" title="This is the summary (new)">ticket:1</a> 
 19  <a class="missing ticket">ticket:12</a> 
 20  <a class="missing ticket">ticket:abc</a> 
 21  </p> 
 22  ------------------------------ 
 23  ============================== ticket: link resolver + arguments 
 24  ticket:1?format=csv 
 25  ticket:1#comment:3 
 26  ------------------------------ 
 27  <p> 
 28  <a class="new ticket" href="/ticket/1?format=csv" title="This is the summary (new)">ticket:1?format=csv</a> 
 29  <a class="new ticket" href="/ticket/1#comment:3" title="This is the summary (new)">ticket:1#comment:3</a> 
 30  </p> 
 31  ------------------------------ 
 32  ============================== ticket: link resolver with ranges 
 33  ticket:12-14,33 
 34  ticket:12,33?order=created 
 35  ------------------------------ 
 36  <p> 
 37  <a href="/query?id=12-14%2C33" title="Tickets 12-14,33">ticket:12-14,33</a> 
 38  <a href="/query?id=12%2C33&amp;order=created" title="Tickets 12,33">ticket:12,33?order=created</a> 
 39  </p> 
 40  ------------------------------ 
 41  ============================== ticket link shorthand form 
 42  #1, #2 
 43  #12, #abc 
 44  ------------------------------ 
 45  <p> 
 46  <a class="new ticket" href="/ticket/1" title="This is the summary (new)">#1</a>, <a class="missing ticket">#2</a> 
 47  <a class="missing ticket">#12</a>, #abc 
 48  </p> 
 49  ------------------------------ 
 50  ============================== escaping the above 
 51  !#1 
 52  ------------------------------ 
 53  <p> 
 54  #1 
 55  </p> 
 56  ------------------------------ 
 57  #1 
 58  ============================== InterTrac for tickets 
 59  trac:ticket:2041 
 60  [trac:ticket:2041 Trac #2041] 
 61  #T2041 
 62  #trac2041 
 63  ------------------------------ 
 64  <p> 
 65  <a class="ext-link" href="http://trac.edgewall.org/intertrac/ticket%3A2041" title="ticket:2041 in Trac's Trac"><span class="icon">\xa0</span>trac:ticket:2041</a> 
 66  <a class="ext-link" href="http://trac.edgewall.org/intertrac/ticket%3A2041" title="ticket:2041 in Trac's Trac"><span class="icon">\xa0</span>Trac #2041</a> 
 67  <a class="ext-link" href="http://trac.edgewall.org/intertrac/ticket%3A2041" title="ticket:2041 in Trac's Trac"><span class="icon">\xa0</span>#T2041</a> 
 68  <a class="ext-link" href="http://trac.edgewall.org/intertrac/ticket%3A2041" title="ticket:2041 in Trac's Trac"><span class="icon">\xa0</span>#trac2041</a> 
 69  </p> 
 70  ------------------------------ 
 71  ============================== Ticket InterTrac shorthands 
 72  T:#2041 
 73  trac:#2041 
 74  ------------------------------ 
 75  <p> 
 76  <a class="ext-link" href="http://trac.edgewall.org/intertrac/%232041" title="#2041 in Trac's Trac"><span class="icon">\xa0</span>T:#2041</a> 
 77  <a class="ext-link" href="http://trac.edgewall.org/intertrac/%232041" title="#2041 in Trac's Trac"><span class="icon">\xa0</span>trac:#2041</a> 
 78  </p> 
 79  ------------------------------ 
 80  """ # "  
 81   
82 -def ticket_setup(tc):
83 ticket = Ticket(tc.env) 84 ticket.values.update({'reporter': 'santa', 85 'summary': 'This is the summary', 86 'status': 'new'}) 87 ticket.insert()
88
89 -def ticket_teardown(tc):
90 tc.env.reset_db()
91 92 93 94 REPORT_TEST_CASES=u""" 95 ============================== report link shorthand form 96 {1}, {2} 97 {12}, {abc} 98 ------------------------------ 99 <p> 100 <a class="report" href="/report/1">{1}</a>, <a class="report" href="/report/2">{2}</a> 101 <a class="report" href="/report/12">{12}</a>, {abc} 102 </p> 103 ------------------------------ 104 ============================== escaping the above 105 !{1} 106 ------------------------------ 107 <p> 108 {1} 109 </p> 110 ------------------------------ 111 {1} 112 ============================== ticket shorthands, not numerical HTML entities 113 &#1; &#23; 114 ------------------------------ 115 <p> 116 &amp;#1; &amp;#23; 117 </p> 118 ------------------------------ 119 &amp;#1; &amp;#23; 120 ============================== InterTrac for reports 121 trac:report:1 122 [trac:report:1 Trac r1] 123 {T1} 124 {trac1} 125 {trac 1} 126 ------------------------------ 127 <p> 128 <a class="ext-link" href="http://trac.edgewall.org/intertrac/report%3A1" title="report:1 in Trac's Trac"><span class="icon">\xa0</span>trac:report:1</a> 129 <a class="ext-link" href="http://trac.edgewall.org/intertrac/report%3A1" title="report:1 in Trac's Trac"><span class="icon">\xa0</span>Trac r1</a> 130 <a class="ext-link" href="http://trac.edgewall.org/intertrac/report%3A1" title="report:1 in Trac's Trac"><span class="icon">\xa0</span>{T1}</a> 131 <a class="ext-link" href="http://trac.edgewall.org/intertrac/report%3A1" title="report:1 in Trac's Trac"><span class="icon">\xa0</span>{trac1}</a> 132 <a class="ext-link" href="http://trac.edgewall.org/intertrac/report%3A1" title="report:1 in Trac's Trac"><span class="icon">\xa0</span>{trac 1}</a> 133 </p> 134 ------------------------------ 135 """ # ' 136
137 -def report_setup(tc):
138 db = tc.env.get_db_cnx()
139 # TBD 140 141 142 MILESTONE_TEST_CASES=""" 143 ============================== milestone: link resolver 144 milestone:foo 145 [milestone:boo Milestone Boo] 146 [milestone:roo Milestone Roo] 147 ------------------------------ 148 <p> 149 <a class="missing milestone" href="/milestone/foo" rel="nofollow">milestone:foo</a> 150 <a class="milestone" href="/milestone/boo">Milestone Boo</a> 151 <a class="closed milestone" href="/milestone/roo">Milestone Roo</a> 152 </p> 153 ------------------------------ 154 ============================== milestone: link resolver + arguments 155 milestone:?action=new 156 [milestone:boo#KnownIssues Known Issues for 1.0] 157 ------------------------------ 158 <p> 159 <a class="missing milestone" href="/milestone/?action=new" rel="nofollow">milestone:?action=new</a> 160 <a class="milestone" href="/milestone/boo#KnownIssues">Known Issues for 1.0</a> 161 </p> 162 ------------------------------ 163 """ #" 164
165 -def milestone_setup(tc):
166 from datetime import datetime 167 from trac.util.datefmt import utc 168 boo = Milestone(tc.env) 169 boo.name = 'boo' 170 boo.completed = boo.due = None 171 boo.insert() 172 roo = Milestone(tc.env) 173 roo.name = 'roo' 174 roo.completed = datetime.now(utc) 175 roo.due = None 176 roo.insert()
177
178 -def milestone_teardown(tc):
179 tc.env.reset_db()
180 181 182 183 QUERY_TEST_CASES=""" 184 ============================== query: link resolver 185 query:?order=priority 186 187 query:?order=priority&owner=me 188 189 query:status=new|reopened 190 191 query:milestone!= 192 193 query:milestone=1.0|2.0&owner=me 194 195 query:group=owner 196 197 query:verbose=1 198 ------------------------------ 199 <p> 200 <a class="query" href="/query?order=priority">query:?order=priority</a> 201 </p> 202 <p> 203 <a class="query" href="/query?order=priority&amp;owner=me">query:?order=priority&amp;owner=me</a> 204 </p> 205 <p> 206 <a class="query" href="/query?status=new&amp;status=reopened&amp;order=priority">query:status=new|reopened</a> 207 </p> 208 <p> 209 <a class="query" href="/query?milestone=%21&amp;order=priority">query:milestone!=</a> 210 </p> 211 <p> 212 <a class="query" href="/query?milestone=1.0&amp;milestone=2.0&amp;owner=me&amp;order=priority">query:milestone=1.0|2.0&amp;owner=me</a> 213 </p> 214 <p> 215 <a class="query" href="/query?group=owner&amp;order=priority">query:group=owner</a> 216 </p> 217 <p> 218 <a class="query" href="/query?order=priority&amp;row=description">query:verbose=1</a> 219 </p> 220 ------------------------------ 221 """ 222 223 COMMENT_TEST_CASES=""" 224 ============================== comment: link resolver (deprecated) 225 comment:ticket:123:2 (deprecated) 226 [comment:ticket:123:2 see above] (deprecated) 227 [comment:ticket:123:description see descr] (deprecated) 228 ------------------------------ 229 <p> 230 <a href="/ticket/123#comment:2" title="Comment 2 for Ticket #123">comment:ticket:123:2</a> (deprecated) 231 <a href="/ticket/123#comment:2" title="Comment 2 for Ticket #123">see above</a> (deprecated) 232 <a href="/ticket/123#comment:description" title="Comment description for Ticket #123">see descr</a> (deprecated) 233 </p> 234 ------------------------------ 235 ============================== comment: link resolver 236 comment:2:ticket:123 237 [comment:2:ticket:123 see above] 238 [comment:description:ticket:123 see descr] 239 ------------------------------ 240 <p> 241 <a href="/ticket/123#comment:2" title="Comment 2 for Ticket #123">comment:2:ticket:123</a> 242 <a href="/ticket/123#comment:2" title="Comment 2 for Ticket #123">see above</a> 243 <a href="/ticket/123#comment:description" title="Comment description for Ticket #123">see descr</a> 244 </p> 245 ------------------------------ 246 """ # " 247 248 # NOTE: the following test cases: 249 # 250 # comment:2 251 # [comment:2 see above] 252 # 253 # would trigger an error in the workaround code ../api.py, line 235 254 # As it's a problem with a temp workaround, I think there's no need 255 # to fix it for now. 256
257 -def suite():
258 suite = unittest.TestSuite() 259 suite.addTest(formatter.suite(TICKET_TEST_CASES, ticket_setup, __file__, 260 ticket_teardown)) 261 suite.addTest(formatter.suite(REPORT_TEST_CASES, report_setup, __file__)) 262 suite.addTest(formatter.suite(MILESTONE_TEST_CASES, milestone_setup, 263 __file__, milestone_teardown)) 264 suite.addTest(formatter.suite(QUERY_TEST_CASES, file=__file__)) 265 suite.addTest(formatter.suite(COMMENT_TEST_CASES, file=__file__)) 266 return suite
267 268 if __name__ == '__main__': 269 unittest.main(defaultTest='suite') 270