This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish test suite for package linking via email
- Loading branch information
1 parent
05ff710
commit 9cd01ae
Showing
2 changed files
with
69 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,16 @@ | |
|
||
import json | ||
import sys | ||
|
||
import urllib | ||
|
||
from pytest import raises | ||
|
||
from gratipay.exceptions import CannotRemovePrimaryEmail, EmailTaken, EmailNotVerified | ||
from gratipay.exceptions import TooManyEmailAddresses, Throttled, EmailAlreadyVerified | ||
from gratipay.exceptions import EmailNotOnFile, ProblemChangingEmail | ||
from gratipay.testing import P, Harness | ||
from gratipay.testing.email import QueuedEmailHarness, SentEmailHarness | ||
from gratipay.models.package import Package | ||
from gratipay.models.participant import email as _email | ||
from gratipay.utils import encode_for_querystring | ||
from gratipay.cli import queue_branch_email as _queue_branch_email | ||
|
@@ -167,10 +168,18 @@ def test_verify_email_expired_nonce(self): | |
def test_finish_email_verification(self): | ||
self.hit_email_spt('add-email', '[email protected]') | ||
nonce = self.alice.get_email('[email protected]').nonce | ||
self.finish_email_verification('[email protected]', nonce) | ||
expected = '[email protected]' | ||
actual = P('alice').email_address | ||
assert expected == actual | ||
assert self.finish_email_verification('[email protected]', nonce).code == 200 | ||
assert P('alice').email_address == '[email protected]' | ||
|
||
def test_empty_email_results_in_missing(self): | ||
for empty in ('', ' '): | ||
result = self.alice.finish_email_verification(empty, 'foobar') | ||
assert result == _email.VERIFICATION_MISSING | ||
|
||
def test_empty_nonce_results_in_missing(self): | ||
for empty in ('', ' '): | ||
result = self.alice.finish_email_verification('foobar', empty) | ||
assert result == _email.VERIFICATION_MISSING | ||
|
||
def test_email_verification_is_backwards_compatible(self): | ||
"""Test email verification still works with unencoded email in verification link. | ||
|
@@ -679,36 +688,59 @@ def test_sends_notice_for_unverified_address_and_multiple_packages(self): | |
assert ' connecting [email protected] and 2 npm packages ' in text | ||
|
||
|
||
class FinishEmailVerification(VerificationBase): | ||
class PackageLinking(VerificationBase): | ||
|
||
address = '[email protected]' | ||
|
||
def start(self, address, *package_names): | ||
packages = [self.make_package(name=name, emails=[address]) for name in package_names] | ||
self.alice.start_email_verification(address, *packages) | ||
return self.alice.get_email(address).nonce | ||
|
||
def test_handles_new_address(self): | ||
address = '[email protected]' | ||
def check(self, *package_names): | ||
nonce = self.start(self.address, *package_names) | ||
retval = self.alice.finish_email_verification(self.address, nonce) | ||
assert retval == _email.VERIFICATION_SUCCEEDED | ||
assert self.alice.email_address == P('alice').email_address == self.address | ||
for name in package_names: | ||
package = Package.from_names('npm', name) | ||
assert package.team.package == package | ||
|
||
|
||
def test_preverify_preverifies(self): | ||
assert self.alice.email_address is None | ||
self.alice.finish_email_verification(address, self.start(address)) | ||
assert self.alice.email_address == P('alice').email_address == address | ||
self.preverify() | ||
assert self.alice.email_address == self.address | ||
|
||
def test_handles_verified_address_and_no_packages(self): | ||
raise NotImplementedError # should error | ||
|
||
def test_handles_verified_address_and_one_package(self): | ||
def test_unverified_address_and_no_packages_succeeds(self): | ||
self.check() | ||
|
||
def test_unverified_address_and_one_package_succeeds(self): | ||
self.check('foo') | ||
|
||
def test_unverified_address_and_multiple_packages_succeeds(self): | ||
self.check('foo', 'bar') | ||
|
||
def test_verified_address_and_no_packages_is_a_no_go(self): | ||
self.preverify() | ||
address = '[email protected]' | ||
assert self.alice.email_address == address | ||
self.alice.finish_email_verification(address, self.start(address, 'foo')) | ||
assert self.alice.email_address == P('alice').email_address == address | ||
raise NotImplementedError # assert we connect the package | ||
raises(EmailAlreadyVerified, self.check) | ||
|
||
def test_handles_verified_address_and_multiple_packages(self): | ||
def test_verified_address_and_one_package_succeeds(self): | ||
self.preverify() | ||
raise NotImplementedError | ||
self.check('foo') | ||
|
||
def test_handles_unverified_address_and_one_package(self): | ||
raise NotImplementedError | ||
def test_verified_address_and_multiple_packages_succeeds(self): | ||
self.preverify() | ||
self.check('foo', 'bar') | ||
|
||
def test_handles_unverified_address_and_multiple_packages(self): | ||
raise NotImplementedError | ||
|
||
def test_while_we_are_at_it_that_packages_have_unique_teams_that_survive_comparison(self): | ||
self.test_verified_address_and_multiple_packages_succeeds() | ||
|
||
foo = Package.from_names('npm', 'foo') | ||
bar = Package.from_names('npm', 'bar') | ||
|
||
assert foo.team == foo.team | ||
assert bar.team == bar.team | ||
assert foo.team != bar.team |