Debian Codegraph @

tests/test-bugzilla.t

raw
1 mock bugzilla driver for testing template output:
2
3 $ cat <<EOF > bzmock.py
4 > from mercurial import extensions
5 > from mercurial import pycompat
6 > from mercurial import registrar
7 > from mercurial.utils import stringutil
8 >
9 > configtable = {}
10 > configitem = registrar.configitem(configtable)
11 >
12 > configitem(b'bugzilla', b'mocklog',
13 > default=None,
14 > )
15 > def extsetup(ui):
16 > bugzilla = extensions.find(b'bugzilla')
17 > class bzmock(bugzilla.bzaccess):
18 > def __init__(self, ui):
19 > super(bzmock, self).__init__(ui)
20 > self._logfile = ui.config(b'bugzilla', b'mocklog')
21 > def updatebug(self, bugid, newstate, text, committer):
22 > with open(pycompat.fsdecode(self._logfile), 'ab') as f:
23 > f.write(b'update bugid=%s, newstate=%s, committer=%s\n'
24 > % (stringutil.pprint(bugid),
25 > stringutil.pprint(newstate),
26 > stringutil.pprint(committer)))
27 > f.write(b'----\n' + text + b'\n----\n')
28 > def notify(self, bugs, committer):
29 > with open(pycompat.fsdecode(self._logfile), 'ab') as f:
30 > f.write(b'notify bugs=%s, committer=%s\n'
31 > % (stringutil.pprint(bugs),
32 > stringutil.pprint(committer)))
33 > bugzilla.bugzilla._versions[b'mock'] = bzmock
34 > EOF
35
36 set up mock repository:
37
38 $ hg init mockremote
39 $ cat <<EOF > mockremote/.hg/hgrc
40 > [extensions]
41 > bugzilla =
42 > bzmock = $TESTTMP/bzmock.py
43 >
44 > [bugzilla]
45 > version = mock
46 > mocklog = $TESTTMP/bzmock.log
47 >
48 > [hooks]
49 > incoming.bugzilla = python:hgext.bugzilla.hook
50 >
51 > [web]
52 > baseurl=http://example.org/hg
53 >
54 > %include $TESTTMP/bzstyle.hgrc
55 > EOF
56
57 $ hg clone -q mockremote mocklocal
58
59 push with default template:
60
61 $ echo '[bugzilla]' > bzstyle.hgrc
62 $ echo foo > mocklocal/foo
63 $ hg ci -R mocklocal -Aqm 'Fixes bug 123'
64 $ hg -R mocklocal push -q
65 $ cat bzmock.log && rm bzmock.log
66 update bugid=123, newstate={}, committer='test'
67 ----
68 changeset 7875a8342c6f in repo $TESTTMP/mockremote refers to bug 123.
69 details:
70 Fixes bug 123
71 ----
72 notify bugs={123: {}}, committer='test'
73
74 push with style:
75
76 $ cat <<EOF > bzstyle.map
77 > changeset = "{node|short} refers to bug {bug}."
78 > EOF
79 $ echo "style = $TESTTMP/bzstyle.map" >> bzstyle.hgrc
80 $ echo foo >> mocklocal/foo
81 $ hg ci -R mocklocal -qm 'Fixes bug 456'
82 $ hg -R mocklocal push -q
83 $ cat bzmock.log && rm bzmock.log
84 update bugid=456, newstate={}, committer='test'
85 ----
86 2808b172464b refers to bug 456.
87 ----
88 notify bugs={456: {}}, committer='test'
89
90 push with template (overrides style):
91
92 $ cat <<EOF >> bzstyle.hgrc
93 > template = Changeset {node|short} in {root|basename}.
94 > {hgweb}/rev/{node|short}\n
95 > {desc}
96 > EOF
97 $ echo foo >> mocklocal/foo
98 $ hg ci -R mocklocal -qm 'Fixes bug 789'
99 $ hg -R mocklocal push -q
100 $ cat bzmock.log && rm bzmock.log
101 update bugid=789, newstate={}, committer='test'
102 ----
103 Changeset a770f3e409f2 in mockremote.
104 http://example.org/hg/rev/a770f3e409f2
105
106 Fixes bug 789
107 ----
108 notify bugs={789: {}}, committer='test'