49
49
def test_membership_of_missing_address(self):
50
50
# Try to get the memberships of a missing address.
51
with self.assertRaises(HTTPError) as cm:
53
52
call_api('http://localhost:9001/3.0/addresses/'
54
53
'nobody@example.com/memberships')
55
except HTTPError as exc:
56
self.assertEqual(exc.code, 404)
58
raise AssertionError('Expected HTTPError 404')
54
self.assertEqual(cm.exception.code, 404)
60
56
def test_verify_a_missing_address(self):
61
57
# POSTing to the 'verify' sub-resource returns a 404.
58
with self.assertRaises(HTTPError) as cm:
63
59
call_api('http://localhost:9001/3.0/addresses/'
64
60
'nobody@example.com/verify', {})
65
except HTTPError as exc:
66
self.assertEqual(exc.code, 404)
68
raise AssertionError('Expected HTTPError 404')
61
self.assertEqual(cm.exception.code, 404)
70
63
def test_unverify_a_missing_address(self):
71
64
# POSTing to the 'unverify' sub-resource returns a 404.
65
with self.assertRaises(HTTPError) as cm:
73
66
call_api('http://localhost:9001/3.0/addresses/'
74
67
'nobody@example.com/unverify', {})
75
except HTTPError as exc:
76
self.assertEqual(exc.code, 404)
78
raise AssertionError('Expected HTTPError 404')
68
self.assertEqual(cm.exception.code, 404)
80
70
def test_verify_already_verified(self):
81
71
# It's okay to verify an already verified; it just doesn't change the
105
95
with transaction():
106
96
anne = getUtility(IUserManager).create_address('anne@example.com')
107
97
self.assertEqual(anne.verified_on, None)
98
with self.assertRaises(HTTPError) as cm:
109
99
call_api('http://localhost:9001/3.0/addresses/'
110
100
'anne@example.com/verify/foo', {})
111
except HTTPError as exc:
112
self.assertEqual(exc.code, 400)
114
raise AssertionError('Expected HTTPError 400')
101
self.assertEqual(cm.exception.code, 400)
116
103
def test_unverify_bad_request(self):
117
104
# Too many segments after /verify.
118
105
with transaction():
119
106
anne = getUtility(IUserManager).create_address('anne@example.com')
120
107
self.assertEqual(anne.verified_on, None)
108
with self.assertRaises(HTTPError) as cm:
122
109
call_api('http://localhost:9001/3.0/addresses/'
123
110
'anne@example.com/unverify/foo', {})
124
except HTTPError as exc:
125
self.assertEqual(exc.code, 400)
127
raise AssertionError('Expected HTTPError 400')
111
self.assertEqual(cm.exception.code, 400)