~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
Merging people
==============

Since we may create Launchpad profiles automatically sometimes, we allow
people to merge two profiles into a single one, if they find there's more
than one profile representing themselves.

Here we will merge the profile named 'foo' into the one named 'no-priv'.

    # First we'll create the 'foo' profile because it doesn't exist yet.
    >>> login('foo.bar@canonical.com')
    >>> foo = factory.makePerson(name='foo', email='foo@baz.com')
    >>> logout()

First we have to go to the +requestmerge page.

    >>> browser.addHeader('Authorization', 'Basic no-priv@canonical.com:test')
    >>> browser.open('http://launchpad.dev/people/+requestmerge')
    >>> print browser.title
    Merge Launchpad accounts

In preparation for the actual merge (below), we add an extra email
address to the 'foo' account, to show how things work when the dupe
account has more than one email address.

    >>> from lp.services.identity.model.emailaddress import EmailAddressSet
    >>> from lp.registry.model.person import PersonSet
    >>> from lp.services.identity.interfaces.emailaddress import (
    ...     EmailAddressStatus)
    >>> foo = PersonSet().getByName('foo')
    >>> email = EmailAddressSet().new(
    ...     'bar.foo@canonical.com', person=foo,
    ...     status=EmailAddressStatus.VALIDATED)

Then we find the duplicate account and request the merge.
This redirects to the page which displays all email addresses owned by the
duplicate account. Here the user choses the ones which he want to claim.

    >>> browser.getControl(
    ...     'Duplicated Account').value = 'foo'
    >>> browser.getControl('Continue').click()
    >>> explanation = find_tag_by_id(browser.contents, 'explanation')
    >>> print extract_text(explanation)
    The account...has more than one registered e-mail address...


Make sure we haven't got leftovers from a previous test

    >>> from lp.services.mail import stub
    >>> len(stub.test_emails)
    0

Claim all the email addresses

    >>> email_select_control = browser.getControl(name='selected')
    >>> for ctrl in email_select_control.controls:
    ...     ctrl.selected = True
    >>> browser.getControl('Merge Accounts').click()
    >>> confirmation = find_tag_by_id(browser.contents, 'confirmation')
    >>> print extract_text(confirmation)
    Confirmation email messages were sent to:...
    >>> 'foo@baz.com' in browser.contents
    True
    >>> 'bar.foo@canonical.com' in browser.contents
    True

Get the token we'll have to use to finish the registration process.

    >>> len(stub.test_emails) == 2
    True
    >>> emails = []
    >>> emails.append(stub.test_emails.pop())
    >>> emails.append(stub.test_emails.pop())
    >>> emails.sort()
    >>> from_addr1, to_addrs1, raw_msg1 = emails.pop()
    >>> from_addr2, to_addrs2, raw_msg2 = emails.pop()

    >>> from lp.services.verification.tests.logintoken import (
    ...     get_token_url_from_email)
    >>> token_url = get_token_url_from_email(raw_msg1)

Now the user goes to the page we sent a link via email to validate the first
claimed email address.

    >>> browser.open(token_url)
    >>> 'trying to merge the Launchpad account' in browser.contents
    True

User confirms the merge request submitting the form, but the merge wasn't
finished because the duplicate account still have a registered email addresses.

    >>> browser.getControl('Confirm').click()
    >>> 'has other registered e-mail addresses too' in browser.contents
    True

    >>> token_url = get_token_url_from_email(raw_msg2)

Now the user proves that he's the owner of the second email address of the
dupe account. And now the merge is completed successfully.

    >>> browser.open(token_url)
    >>> 'trying to merge the Launchpad account' in browser.contents
    True
    >>> browser.getControl('Confirm').click()
    >>> 'The accounts have been merged successfully' in browser.contents
    True


If the account we were trying to merge had a single email address, the
process would be a little simpler.

To demonstrate that, now we'll merge marilize@hbd.com into
no-priv@canonical.com.

    >>> len(stub.test_emails)
    0

    >>> browser.open('http://launchpad.dev/people/+requestmerge')
    >>> browser.getControl('Duplicated Account').value = 'marilize@hbd.com'
    >>> browser.getControl('Continue').click()
    >>> browser.url
    'http://launchpad.dev/people/+mergerequest-sent?dupe=55'
    >>> len(stub.test_emails)
    1
    >>> 'An email message was sent to' in browser.contents
    True
    >>> '<strong>marilize@hbd.com</strong' in browser.contents
    True

Revisiting that page gives the same results:

    >>> browser.open('http://launchpad.dev/people/+mergerequest-sent?dupe=55')
    >>> 'An email message was sent to' in browser.contents
    True
    >>> '<strong>marilize@hbd.com</strong' in browser.contents
    True

Get the token we'll have to use to finish the registration process.

    >>> from_addr, to_addrs, raw_msg = stub.test_emails.pop()
    >>> assert not stub.test_emails
    >>> token_url = get_token_url_from_email(raw_msg)

If the duplicate account has multiple email addresses and has chosen
to hide them the process is slightly different.  We cannot display the
hidden addresses so instead we just inform the user to check all of
them (and hope they know which ones) and we send merge request
messages to them all.

    >>> login('foo.bar@canonical.com')
    >>> dupe = factory.makePerson(name="duplicate-person", email="dupe1@example.com",
    ...                           hide_email_addresses=True)
    >>> email = factory.makeEmail(address="dupe2@example.com", person=dupe)

Ensure there are no leftover emails.

    >>> len(stub.test_emails)
    0

Open the merge page and merge our duplicate account with hidden email
addresses.

    >>> logout()
    >>> browser.open('http://launchpad.dev/people/+requestmerge')
    >>> browser.getControl(
    ...     'Duplicated Account').value = 'duplicate-person'
    >>> browser.getControl('Continue').click()

    >>> explanation = find_tag_by_id(browser.contents, 'explanation')
    >>> print extract_text(explanation)
    The account...has 2 registered e-mail addresses...


Since the addresses are hidden we cannot display them therefore there
are no controls to select.

    >>> email_select_control = browser.getControl(name='selected')
    Traceback (most recent call last):
    ...
    LookupError: name 'selected'

    >>> browser.getControl('Merge Accounts').click()

    >>> len(stub.test_emails)
    2

    >>> confirmation = find_tag_by_id(browser.contents, 'confirmation')
    >>> print extract_text(confirmation)
    Confirmation email messages were sent to the 2 registered e-mail addresses...

    >>> maincontent = extract_text(find_main_content(browser.contents))

    >>> 'dupe1@example.com' in maincontent
    False
    >>> 'dupe2@example.com' in maincontent
    False