{"id":112,"date":"2011-09-08T23:07:51","date_gmt":"2011-09-09T03:07:51","guid":{"rendered":"http:\/\/www.jetmore.org\/john\/blog\/?p=112"},"modified":"2012-05-11T15:15:48","modified_gmt":"2012-05-11T19:15:48","slug":"custom-testlink-macro-for-trac","status":"publish","type":"post","link":"https:\/\/www.jetmore.org\/john\/blog\/2011\/09\/custom-testlink-macro-for-trac\/","title":{"rendered":"Custom TestLink Macro for Trac"},"content":{"rendered":"<p>I&#8217;ve been spending a lot of time lately trying to get the workflow between Trac and TestLink to make sense.  I&#8217;m far from having the perfect solution, but a great first step was creating a Trac wiki macro that will link to specific test cases in TestLink.  There&#8217;s lots of areas in which this could be improved in the future&#8230;<\/p>\n<p>Create this as conf\/TestLinkMacro.py in your project (replacing test.example.com with your TestLink host):<\/p>\n<pre class=\"brush: python; title: conf\/TestLinkMacro.py; notranslate\" title=\"conf\/TestLinkMacro.py\">\r\nimport re\r\n\r\nfrom trac.wiki.macros import WikiMacroBase\r\n\r\nclass TestLinkMacro(WikiMacroBase):\r\n    &quot;&quot;&quot;Macro to generate automatic links to test cases in TestLink.\r\n    &quot;&quot;&quot;\r\n\r\n    def expand_macro(self, formatter, name, args):\r\n        &quot;&quot;&quot;Expand a TestLink test case ID into a link\r\n        &quot;&quot;&quot;\r\n        TestLinkServer = 'test.example.com'\r\n        matches = re.match(r'(.*)-(d+)$', args)\r\n        \r\n        return '&lt;a href=&quot;https:\/\/' + TestLinkServer + '\/linkto.php?tprojectPrefix=' + matches.group(1) + '&amp;item=testcase&amp;id=' + matches.group(0) + '&quot;&gt;[[TestLink(' + matches.group(0) + ')]]&lt;\/a&gt;'\r\n<\/pre>\n<p>After putting this in place, and possibly restarting Trac, you can create a direct link to test case m3-123 in a wiki by typing [[TestLink(m3-123)]].  Note that I could have changed the actual string displayed in the wiki to anything I wanted, but I chose to leave it looking identical to the actual macro (but linked) so that it would reinforce to people the correct format for the test case links.<\/p>\n<p>This macro is useful in several ways, but the most obvious is allowing us to enter regression test case IDs into commit messages (which then get associated with a ticket in Trac and are displayed with the wiki engine, making the test case link clickable).<br \/>\nWith commit messages being associated with tickets automatically and being displayed by the wiki engine, this gives us a nice syntax to enter regression case links into commit messages and be very followable later<\/p>\n<p><strong>Edit 2011-09-13:<\/strong><\/p>\n<p>See also <a href=\"https:\/\/www.jetmore.org\/john\/blog\/2011\/09\/linking-to-testlink-testcases-from-trac-addendum\/\">this update to my use of macros for linking to test cases<\/a> and <a href=\"https:\/\/www.jetmore.org\/john\/blog\/2011\/09\/using-wiki-markup-in-trac-custom-ticket-fields\/\">this comment on custom ticket field wiki parsing<\/a>, both of which have a direct relation to this post<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been spending a lot of time lately trying to get the workflow between Trac and TestLink to make sense. I&#8217;m far from having the perfect solution, but a great first step was creating a Trac wiki macro that will &hellip; <a href=\"https:\/\/www.jetmore.org\/john\/blog\/2011\/09\/custom-testlink-macro-for-trac\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[8,14],"_links":{"self":[{"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/posts\/112"}],"collection":[{"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/comments?post=112"}],"version-history":[{"count":3,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/posts\/112\/revisions"}],"predecessor-version":[{"id":689,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/posts\/112\/revisions\/689"}],"wp:attachment":[{"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/categories?post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jetmore.org\/john\/blog\/wp-json\/wp\/v2\/tags?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}