~barry/mailman/templatecache

« back to all changes in this revision

Viewing changes to src/mailman/rest/tests/test_addresses.py

  • Committer: Barry Warsaw
  • Date: 2012-10-31 16:37:22 UTC
  • mfrom: (7178.1.1 work2)
  • Revision ID: barry@list.org-20121031163722-3lszhsiv9ai0akfp
 * Python 2.7 is not required.  Python 2.6 is no longer officially supported.
   The code base is now also `python2.7 -3` clean, although there are still
   some warnings in 3rd party dependencies.  LP: #1073506

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 
49
49
    def test_membership_of_missing_address(self):
50
50
        # Try to get the memberships of a missing address.
51
 
        try:
52
 
            # For Python 2.6.
 
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)
57
 
        else:
58
 
            raise AssertionError('Expected HTTPError 404')
 
54
        self.assertEqual(cm.exception.code, 404)
59
55
 
60
56
    def test_verify_a_missing_address(self):
61
57
        # POSTing to the 'verify' sub-resource returns a 404.
62
 
        try:
 
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)
67
 
        else:
68
 
            raise AssertionError('Expected HTTPError 404')
 
61
        self.assertEqual(cm.exception.code, 404)
69
62
 
70
63
    def test_unverify_a_missing_address(self):
71
64
        # POSTing to the 'unverify' sub-resource returns a 404.
72
 
        try:
 
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)
77
 
        else:
78
 
            raise AssertionError('Expected HTTPError 404')
 
68
        self.assertEqual(cm.exception.code, 404)
79
69
 
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)
108
 
        try:
 
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)
113
 
        else:
114
 
            raise AssertionError('Expected HTTPError 400')
 
101
        self.assertEqual(cm.exception.code, 400)
115
102
 
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)
121
 
        try:
 
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)
126
 
        else:
127
 
            raise AssertionError('Expected HTTPError 400')
 
111
        self.assertEqual(cm.exception.code, 400)