~launchpad-pqm/launchpad/devel

6331.3.1 by Graham Binns
Merged BugTrackerPerson set base.
1
= The BugTrackerPerson interface =
2
3
The IBugTrackerPerson interfaces allows Launchpad to link Persons to
4
bugtrackers. BugTrackerPersons are created using the
6331.3.12 by Graham Binns
Moved BugTrackerPersonSet logic into BugTracker.
5
linkPersonToSelf() method of IBugTracker.
6331.3.1 by Graham Binns
Merged BugTrackerPerson set base.
6
7
    >>> from zope.component import getUtility
8523.3.1 by Gavin Panella
Bugs tree reorg after automated migration.
8
    >>> from lp.bugs.interfaces.bugtracker import (
6331.3.3 by Graham Binns
Added ZCML for BugTrackerPerson
9
    ...     BugTrackerType)
7675.110.3 by Curtis Hovey
Ran the migration script to move registry code to lp.registry.
10
    >>> from lp.registry.interfaces.person import (
6331.3.3 by Graham Binns
Added ZCML for BugTrackerPerson
11
    ...     IPersonSet)
8523.3.1 by Gavin Panella
Bugs tree reorg after automated migration.
12
    >>> from lp.bugs.tests.externalbugtracker import (
6331.3.1 by Graham Binns
Merged BugTrackerPerson set base.
13
    ...     new_bugtracker)
14
6331.3.8 by Graham Binns
Added a test to check for error handling of BugTrackerPerson.
15
    >>> sample_person = getUtility(IPersonSet).getByName('name12')
6331.3.1 by Graham Binns
Merged BugTrackerPerson set base.
16
17
    >>> bugtracker = new_bugtracker(BugTrackerType.BUGZILLA)
18
6325.2.36 by Graham Binns
Review changes for barry.
19
We'll rename the bugtracker to make the tests more readable.
20
21
    >>> from canonical.database.sqlbase import commit
14604.1.1 by Curtis Hovey
Separate test-authoring classes from test-running classes.
22
    >>> from lp.testing.layers import LaunchpadZopelessLayer
6325.2.36 by Graham Binns
Review changes for barry.
23
    >>> LaunchpadZopelessLayer.switchDbUser('launchpad')
24
25
    >>> bugtracker.name = 'bugzilla-checkwatches'
26
    >>> commit()
27
14605.1.1 by Curtis Hovey
Moved canonical.config to lp.services.
28
    >>> from lp.services.config import config
6325.2.36 by Graham Binns
Review changes for barry.
29
    >>> LaunchpadZopelessLayer.switchDbUser(config.checkwatches.dbuser)
30
6331.3.12 by Graham Binns
Moved BugTrackerPersonSet logic into BugTracker.
31
    >>> bugtracker_person = bugtracker.linkPersonToSelf(
32
    ...         'some-name-i-made-up', sample_person)
6331.3.1 by Graham Binns
Merged BugTrackerPerson set base.
33
34
    >>> print bugtracker_person.name
6331.3.6 by Graham Binns
Added linkPersonToBugTracker() implementation.
35
    some-name-i-made-up
36
37
    >>> print bugtracker_person.person.name
38
    name12
39
40
    >>> print bugtracker_person.bugtracker.name
6325.2.36 by Graham Binns
Review changes for barry.
41
    bugzilla-checkwatches
6331.3.7 by Graham Binns
Added implementation for getByNameAndBugTracker().
42
6331.3.8 by Graham Binns
Added a test to check for error handling of BugTrackerPerson.
43
A name can only be registered with a bugtracker once. Trying to link a
44
new person to a bugtracker using an existing name will cause an error.
45
46
    >>> foo_bar = getUtility(IPersonSet).getByName('name16')
6331.3.12 by Graham Binns
Moved BugTrackerPersonSet logic into BugTracker.
47
    >>> bugtracker_person = bugtracker.linkPersonToSelf(
48
    ...         'some-name-i-made-up', foo_bar)
6331.3.8 by Graham Binns
Added a test to check for error handling of BugTrackerPerson.
49
    Traceback (most recent call last):
50
      ...
6331.3.11 by Graham Binns
Fixes for salgado.
51
    BugTrackerPersonAlreadyExists: Name 'some-name-i-made-up' is already in
6325.2.36 by Graham Binns
Review changes for barry.
52
    use for bugtracker 'bugzilla-checkwatches'.
6331.3.8 by Graham Binns
Added a test to check for error handling of BugTrackerPerson.
53
6331.3.7 by Graham Binns
Added implementation for getByNameAndBugTracker().
54
The BugTrackerPerson record for a given name on a given bugtracker can
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
55
be retrieved by calling BugTracker.getLinkedPersonByName().
6331.3.7 by Graham Binns
Added implementation for getByNameAndBugTracker().
56
6331.3.12 by Graham Binns
Moved BugTrackerPersonSet logic into BugTracker.
57
    >>> bugtracker_person = bugtracker.getLinkedPersonByName(
58
    ...     'some-name-i-made-up')
6331.3.7 by Graham Binns
Added implementation for getByNameAndBugTracker().
59
6331.3.12 by Graham Binns
Moved BugTrackerPersonSet logic into BugTracker.
60
    >>> print bugtracker_person.name
6331.3.7 by Graham Binns
Added implementation for getByNameAndBugTracker().
61
    some-name-i-made-up
62
6331.3.12 by Graham Binns
Moved BugTrackerPersonSet logic into BugTracker.
63
    >>> print bugtracker_person.person.name
6331.3.7 by Graham Binns
Added implementation for getByNameAndBugTracker().
64
    name12
6331.3.8 by Graham Binns
Added a test to check for error handling of BugTrackerPerson.
65
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
66
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
67
== ensurePersonForSelf() ==
6325.2.37 by Graham Binns
Merged bugtracker person branch.
68
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
69
IBugTracker has a method, ensurePersonForSelf(), which is
6325.2.37 by Graham Binns
Merged bugtracker person branch.
70
responsible for returning the correct BugTrackerPerson for a given
71
remote username on on a given bugtracker.
72
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
73
Passing a new remote user's details to ensurePersonForSelf() will
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
74
return a new Person record.
75
7675.110.3 by Curtis Hovey
Ran the migration script to move registry code to lp.registry.
76
    >>> from lp.registry.interfaces.person import (
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
77
    ...     PersonCreationRationale)
78
79
    >>> print getUtility(IPersonSet).getByEmail('new.person@example.com')
80
    None
81
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
82
    >>> new_person = bugtracker.ensurePersonForSelf(
6325.2.37 by Graham Binns
Merged bugtracker person branch.
83
    ...     display_name='New Person', email='new.person@example.com',
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
84
    ...     rationale=PersonCreationRationale.BUGIMPORT,
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
85
    ...     creation_comment='whilst testing ensurePersonForSelf().')
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
86
87
    >>> print new_person.displayname
88
    New Person
89
90
There won't be a BugTrackerPerson record linking 'New Person' to the
91
bugtracker since we have an email address for 'New Person'. That means
92
that we can always retrieve them reliably when we encounter them in a
93
remote bugtracker.
94
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
95
    >>> bugtracker_person = bugtracker.getLinkedPersonByName('New Person')
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
96
    >>> print bugtracker_person
97
    None
98
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
99
Calling ensurePersonForSelf() with the same details will return the
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
100
same person.
101
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
102
    >>> other_person = bugtracker.ensurePersonForSelf(
103
    ...     display_name='New Person',
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
104
    ...     email='new.person@example.com',
105
    ...     rationale=PersonCreationRationale.BUGIMPORT,
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
106
    ...     creation_comment='whilst testing ensurePersonForSelf().')
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
107
6325.2.36 by Graham Binns
Review changes for barry.
108
    >>> print other_person.name
109
    new-person
110
111
    >>> print new_person.name
112
    new-person
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
113
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
114
ensurePersonForSelf() can also handle remote users whose email
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
115
addresses aren't provided.
116
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
117
    >>> noemail_person = bugtracker.ensurePersonForSelf(
118
    ...     display_name='no-email-person',
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
119
    ...     email=None, rationale=PersonCreationRationale.BUGIMPORT,
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
120
    ...     creation_comment='whilst testing ensurePersonForSelf().')
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
121
122
    >>> print noemail_person.name
6325.2.36 by Graham Binns
Review changes for barry.
123
    no-email-person-bugzilla-checkwatches
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
124
125
A BugTrackerPerson record will have been created to map
126
'no-email-person' on our example bugtracker to
6325.2.36 by Graham Binns
Review changes for barry.
127
'no-email-person-bugzilla-checkwatches-1' in Launchpad.
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
128
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
129
    >>> bugtracker_person = bugtracker.getLinkedPersonByName(
130
    ...     'no-email-person')
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
131
132
    >>> bugtracker_person.person == noemail_person
133
    True
134
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
135
ensurePersonForSelf() handles situations in which bugtrackers have
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
136
been renamed, too, and avoids name collisions when doing so.
137
6325.2.33 by Graham Binns
Moved tests successfully. A thousand hurrahs.
138
We'll create a person, 'noemail,' on our example bugtracker.
139
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
140
    >>> new_person = bugtracker.ensurePersonForSelf(
141
    ...     display_name='noemail',
6325.2.33 by Graham Binns
Moved tests successfully. A thousand hurrahs.
142
    ...     email=None, rationale=PersonCreationRationale.BUGIMPORT,
143
    ...     creation_comment='whilst testing.')
144
145
    >>> print new_person.name
6325.2.36 by Graham Binns
Review changes for barry.
146
    noemail-bugzilla-checkwatches
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
147
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
148
    >>> bugtracker_person = bugtracker.getLinkedPersonByName('noemail')
6325.2.33 by Graham Binns
Moved tests successfully. A thousand hurrahs.
149
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
150
    >>> print bugtracker_person.bugtracker.name
6325.2.36 by Graham Binns
Review changes for barry.
151
    bugzilla-checkwatches
152
153
    >>> print bugtracker_person.person.name
154
    noemail-bugzilla-checkwatches
155
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
156
    >>> commit()
157
158
If we rename the BugTracker and then create another with the same name,
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
159
calling ensurePersonForSelf() for 'noemail' on that BugTracker
6325.2.33 by Graham Binns
Moved tests successfully. A thousand hurrahs.
160
should produce a new Person rather than re-using the existing one.
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
161
6325.2.36 by Graham Binns
Review changes for barry.
162
    >>> other_bug_tracker = new_bugtracker(BugTrackerType.BUGZILLA)
163
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
164
    >>> LaunchpadZopelessLayer.switchDbUser('launchpad')
165
6325.2.32 by Graham Binns
Updated some tests, narrative is still wrong.
166
    >>> bugtracker.name = 'bugzilla-checkwatches-renamed'
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
167
    >>> commit()
168
6325.2.36 by Graham Binns
Review changes for barry.
169
    >>> other_bug_tracker.name = 'bugzilla-checkwatches'
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
170
    >>> commit()
6325.2.33 by Graham Binns
Moved tests successfully. A thousand hurrahs.
171
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
172
    >>> LaunchpadZopelessLayer.switchDbUser(config.checkwatches.dbuser)
173
174
A new Person has been created for 'noemail' on other_bug_tracker, even
175
though that bug tracker's name is the same as one from which we've
176
imported previously.
177
8523.3.1 by Gavin Panella
Bugs tree reorg after automated migration.
178
    >>> from lp.bugs.interfaces.bugtracker import IBugTrackerSet
6325.2.36 by Graham Binns
Review changes for barry.
179
    >>> bugtracker = getUtility(IBugTrackerSet).get(bugtracker.id)
180
    >>> other_bugtracker = getUtility(IBugTrackerSet).get(
181
    ...     other_bug_tracker.id)
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
182
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
183
    >>> original_bugtracker_person = bugtracker.getLinkedPersonByName(
184
    ...     'noemail')
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
185
6325.2.38 by Graham Binns
Moved ensurePerson... into BugTracker.
186
    >>> new_person = other_bugtracker.ensurePersonForSelf(
187
    ...     'noemail', None, PersonCreationRationale.BUGIMPORT,
188
    ...     'while testing, again')
6325.2.36 by Graham Binns
Review changes for barry.
189
190
    >>> print original_bugtracker_person.person.name
191
    noemail-bugzilla-checkwatches
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
192
193
    >>> print new_person.name
6325.2.36 by Graham Binns
Review changes for barry.
194
    noemail-bugzilla-checkwatches-1
6325.2.31 by Graham Binns
Moved BugWatchUpdater._getPersonForBugTracker() into IBugTrackerPersonSet as ensurePersonForBugTracker(). Tests are moved, but broken.
195