~abompard/mailman/subpolicy

« back to all changes in this revision

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

  • Committer: Barry Warsaw
  • Date: 2015-04-07 02:06:28 UTC
  • mfrom: (7313.2.6 lp1423756)
  • mto: This revision was merged to the branch mainline in revision 7323.
  • Revision ID: barry@list.org-20150407020628-fkwphij7to9lc8gy
 * Domains now have a list of owners, which are ``IUser`` objects, instead of
   the single ``contact_address`` they used to have.  ``IUser`` objects now
   also have a ``is_server_owner`` flag (defaulting to False) to indicate
   whether they have superuser privileges.  Give by Abhliash Raj, with fixes
   and refinements by Barry Warsaw.  (LP: #1423756)

 * Domains can now optionally be created with owners; domain owners can be
   added after the fact; domain owners can be deleted.  Also, users now have
   an ``is_server_owner`` flag as part of their representation, which defaults
   to False, and can be PUT and PATCH'd.  Given by Abhilash Raj, with fixes
   and refinements by Barry Warsaw.  (LP: #1423756)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""REST domain tests."""
19
19
 
20
20
__all__ = [
 
21
    'TestDomainOwners',
21
22
    'TestDomains',
22
23
    ]
23
24
 
41
42
        with transaction():
42
43
            self._mlist = create_list('test@example.com')
43
44
 
 
45
    def test_create_domains(self):
 
46
        # Create a domain with owners.
 
47
        data = dict(
 
48
            mail_host='example.org',
 
49
            description='Example domain',
 
50
            base_url='http://example.org',
 
51
            owner=['someone@example.com', 'secondowner@example.com'],
 
52
            )
 
53
        content, response = call_api(
 
54
            'http://localhost:9001/3.0/domains', data, method="POST")
 
55
        self.assertEqual(response.status, 201)
 
56
 
44
57
    def test_bogus_endpoint_extension(self):
45
58
        # /domains/<domain>/lists/<anything> is not a valid endpoint.
46
59
        with self.assertRaises(HTTPError) as cm:
87
100
            call_api('http://localhost:9001/3.0/domains/example.com',
88
101
                     method='DELETE')
89
102
        self.assertEqual(cm.exception.code, 404)
 
103
 
 
104
 
 
105
 
 
106
class TestDomainOwners(unittest.TestCase):
 
107
    layer = RESTLayer
 
108
 
 
109
    def test_get_missing_domain_owners(self):
 
110
        # Try to get the owners of a missing domain.
 
111
        with self.assertRaises(HTTPError) as cm:
 
112
            call_api('http://localhost:9001/3.0/domains/example.net/owners')
 
113
        self.assertEqual(cm.exception.code, 404)
 
114
 
 
115
    def test_post_to_missing_domain_owners(self):
 
116
        # Try to add owners to a missing domain.
 
117
        with self.assertRaises(HTTPError) as cm:
 
118
            call_api('http://localhost:9001/3.0/domains/example.net/owners', (
 
119
                ('owner', 'dave@example.com'), ('owner', 'elle@example.com'),
 
120
                ))
 
121
        self.assertEqual(cm.exception.code, 404)
 
122
 
 
123
    def test_delete_missing_domain_owners(self):
 
124
        # Try to delete the owners of a missing domain.
 
125
        with self.assertRaises(HTTPError) as cm:
 
126
            call_api('http://localhost:9001/3.0/domains/example.net/owners',
 
127
                     method='DELETE')
 
128
        self.assertEqual(cm.exception.code, 404)
 
129
 
 
130
    def test_bad_post(self):
 
131
        # Send POST data with an invalid attribute.
 
132
        with self.assertRaises(HTTPError) as cm:
 
133
            call_api('http://localhost:9001/3.0/domains/example.com/owners', (
 
134
                ('guy', 'dave@example.com'), ('gal', 'elle@example.com'),
 
135
                ))
 
136
        self.assertEqual(cm.exception.code, 400)
 
137
 
 
138
    def test_bad_delete(self):
 
139
        # Send DELETE with any data.
 
140
        with self.assertRaises(HTTPError) as cm:
 
141
            call_api('http://localhost:9001/3.0/domains/example.com/owners', {
 
142
                'owner': 'dave@example.com',
 
143
                }, method='DELETE')
 
144
        self.assertEqual(cm.exception.code, 400)