def test_run(self, lookup): shortlink = mock.Mock(url='/p/project/tool/artifact') shortlink.ref.artifact.deleted = False lookup.return_value = shortlink p = mde.PatternReplacingProcessor(mde.TracRef1(), mde.TracRef2()) res = p.run(['#100', 'ticket:100']) self.assertEqual(res, [ '[#100](/p/project/tool/artifact)', '[ticket:100](/p/project/tool/artifact)'])
def test_legit_refs(self, lookup): shortlink = mock.Mock(url='/p/project/tool/artifact/') shortlink.ref.artifact.deleted = False lookup.return_value = shortlink pattern = mde.TracRef2() pattern.get_comment_slug = lambda *args: 'abc' self.assertEqual(pattern.sub('ticket:100'), '[ticket:100](/p/project/tool/artifact/)') self.assertEqual(pattern.sub('[ticket:100]'), '[[ticket:100](/p/project/tool/artifact/)]') self.assertEqual(pattern.sub('comment:13:ticket:100'), '[comment:13:ticket:100](/p/project/tool/artifact/#abc)') pattern.get_comment_slug = lambda *args: None self.assertEqual(pattern.sub('comment:13:ticket:100'), '[comment:13:ticket:100](/p/project/tool/artifact/)')
def test_word_boundaries(self): self.assertEqual(mde.TracRef2().sub('myticket:100'), 'myticket:100') self.assertEqual(mde.TracRef2().sub('ticket:100th'), 'ticket:100th')
def test_no_such_artifact(self, lookup): lookup.return_value = None self.assertEqual(mde.TracRef2().sub('ticket:100'), 'ticket:100')