File: test_admins.py

package info (click to toggle)
python-duo-client 5.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 768 kB
  • sloc: python: 7,105; sh: 6; makefile: 4
file content (258 lines) | stat: -rw-r--r-- 10,149 bytes parent folder | download
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
import json
from .. import util
import duo_client.admin
from .base import TestAdmin


class TestAdmins(TestAdmin):
    # Uses underlying paging
    def test_get_admins(self):
        response = self.client_list.get_admins()
        response = response[0]
        self.assertEqual(response['method'], 'GET')
        (uri, args) = response['uri'].split('?')
        self.assertEqual(uri, '/admin/v1/admins')
        self.assertEqual(
            util.params_to_dict(args),
            {
                'account_id': [self.client.account_id],
                'limit': ['100'],
                'offset': ['0'],
            })

    def test_get_admins_with_limit(self):
        response = self.client_list.get_admins(limit='20')
        response = response[0]
        self.assertEqual(response['method'], 'GET')
        (uri, args) = response['uri'].split('?')
        self.assertEqual(uri, '/admin/v1/admins')
        self.assertEqual(
            util.params_to_dict(args),
            {
                'account_id': [self.client.account_id],
                'limit': ['20'],
                'offset': ['0'],
            })

    def test_get_admins_with_limit_offset(self):
        response = self.client_list.get_admins(limit='20', offset='2')
        response = response[0]
        self.assertEqual(response['method'], 'GET')
        (uri, args) = response['uri'].split('?')
        self.assertEqual(uri, '/admin/v1/admins')
        self.assertEqual(
            util.params_to_dict(args),
            {
                'account_id': [self.client.account_id],
                'limit': ['20'],
                'offset': ['2'],
            })

    def test_get_admins_with_offset(self):
        response = self.client_list.get_admins(offset=9001)
        response = response[0]
        self.assertEqual(response['method'], 'GET')
        (uri, args) = response['uri'].split('?')
        self.assertEqual(uri, '/admin/v1/admins')
        self.assertEqual(
            util.params_to_dict(args),
            {
                'account_id': [self.client.account_id],
                'limit': ['100'],
                'offset': ['0'],
            })

    def test_get_admins_iterator(self):
        response = self.client_list.get_admins_iterator()
        response = next(response)
        self.assertEqual(response['method'], 'GET')
        (uri, args) = response['uri'].split('?')
        self.assertEqual(uri, '/admin/v1/admins')
        self.assertEqual(
            util.params_to_dict(args),
            {
                'account_id': [self.client.account_id],
                'limit': ['100'],
                'offset': ['0'],
            })

    def test_get_external_password_mgmt_statuses(self):

        response = self.client_list.get_external_password_mgmt_statuses()
        response = response[0]
        self.assertEqual(response['method'], 'GET')
        (uri, args) = response['uri'].split('?')
        self.assertEqual(uri, '/admin/v1/admins/password_mgmt')
        self.assertEqual(
            util.params_to_dict(args),
            {
                'account_id': [self.client.account_id],
                'limit': ['100'],
                'offset': ['0'],
            })

    def test_get_external_password_mgmt_statuses_with_limit(self):
        response = self.client_list.get_external_password_mgmt_statuses(
            limit='20')
        response = response[0]
        self.assertEqual(response['method'], 'GET')
        (uri, args) = response['uri'].split('?')
        self.assertEqual(uri, '/admin/v1/admins/password_mgmt')
        self.assertEqual(
            util.params_to_dict(args),
            {
                'account_id': [self.client.account_id],
                'limit': ['20'],
                'offset': ['0'],
            })

    def test_get_external_password_mgmt_statusesg_with_limit_offset(self):
        response = self.client_list.get_external_password_mgmt_statuses(
            limit='20', offset='2')
        response = response[0]
        self.assertEqual(response['method'], 'GET')
        (uri, args) = response['uri'].split('?')
        self.assertEqual(uri, '/admin/v1/admins/password_mgmt')
        self.assertEqual(
            util.params_to_dict(args),
            {
                'account_id': [self.client.account_id],
                'limit': ['20'],
                'offset': ['2'],
            })

    def test_get_external_password_mgmt_statuses_with_offset(self):
        response = self.client_list.get_external_password_mgmt_statuses(
            offset=9001)
        response = response[0]
        self.assertEqual(response['method'], 'GET')
        (uri, args) = response['uri'].split('?')
        self.assertEqual(uri, '/admin/v1/admins/password_mgmt')
        self.assertEqual(
            util.params_to_dict(args),
            {
                'account_id': [self.client.account_id],
                'limit': ['100'],
                'offset': ['0'],
            })

    def test_get_external_password_mgmt_status_for_admin(self):
        response = self.client_list.get_external_password_mgmt_status_for_admin(
            'DFAKEADMINID')
        response = response[0]
        self.assertEqual(response['method'], 'GET')
        (uri, args) = response['uri'].split('?')
        self.assertEqual(uri, '/admin/v1/admins/DFAKEADMINID/password_mgmt')
        self.assertEqual(
            util.params_to_dict(args),
            {
                'account_id': [self.client.account_id],
            })

    def test_update_admin_password_mgmt_status(self):
        response = self.client_list.update_admin_password_mgmt_status(
            'DFAKEADMINID', has_external_password_mgmt='False')
        response = response[0]
        self.assertEqual(response['method'], 'POST')
        self.assertEqual(response['uri'], '/admin/v1/admins/DFAKEADMINID/password_mgmt')
        self.assertEqual(
            json.loads(response['body']),
            {
                'account_id': self.client.account_id,
                'has_external_password_mgmt': 'False'
            })

    def test_update_admin_password_mgmt_status_set_password(self):
        response = self.client_list.update_admin_password_mgmt_status(
            'DFAKEADMINID', has_external_password_mgmt='True', password='dolphins')
        response = response[0]
        self.assertEqual(response['method'], 'POST')
        self.assertEqual(response['uri'], '/admin/v1/admins/DFAKEADMINID/password_mgmt')
        self.assertEqual(
            json.loads(response['body']),
            {
                'account_id': self.client.account_id,
                'has_external_password_mgmt': 'True',
                'password': 'dolphins'
            })

    def test_create_admin(self):
        response = self.client.add_admin('test-name', 'test-email', 'test-phone', 'test-pswd')
        self.assertEqual(response['method'], 'POST')
        self.assertEqual(response['uri'], '/admin/v1/admins')
        self.assertEqual(
            json.loads(response['body']),
            {
                'account_id': self.client.account_id,
                'name': 'test-name',
                'email': 'test-email',
                'phone': 'test-phone',
            })

    def test_create_admin_with_role(self):
        response = self.client.add_admin('test-name', 'test-email', 'test-phone', 'test-pswd', 'test-role')
        self.assertEqual(response['method'], 'POST')
        self.assertEqual(response['uri'], '/admin/v1/admins')
        self.assertEqual(
            json.loads(response['body']),
            {
                'account_id': self.client.account_id,
                'name': 'test-name',
                'email': 'test-email',
                'phone': 'test-phone',
                'role': 'test-role',
            })

    def test_create_admin_with_subaccount_role(self):
        response = self.client.add_admin('test-name', 'test-email', 'test-phone', 'test-pswd', 'test-role', 'test-subaccount-role')
        self.assertEqual(response['method'], 'POST')
        self.assertEqual(response['uri'], '/admin/v1/admins')
        self.assertEqual(
            json.loads(response['body']),
            {
                'account_id': self.client.account_id,
                'name': 'test-name',
                'email': 'test-email',
                'phone': 'test-phone',
                'role': 'test-role',
                'subaccount_role': 'test-subaccount-role',
            })

    def test_update_admin_pass_all_params(self):
        response = self.client.update_admin('test-id', 'test-name1', 'test-phone', None, False, 'test-status', 'test-role', 'test-subaccount-role')
        self.assertEqual(response['method'], 'POST')
        self.assertEqual(response['uri'], '/admin/v1/admins/test-id')
        self.assertEqual(
            json.loads(response['body']),
            {
                'account_id': self.client.account_id,
                'name': 'test-name1',
                'password_change_required': False,
                'phone': 'test-phone',
                'role': 'test-role',
                'status': 'test-status',
                'subaccount_role': 'test-subaccount-role',
            })
        
    def test_update_admin_pass_two_optional_params(self):
        response = self.client.update_admin(admin_id='test-id', name='test-name2', status='test-status')
        self.assertEqual(response['method'], 'POST')
        self.assertEqual(response['uri'], '/admin/v1/admins/test-id')
        self.assertEqual(
            json.loads(response['body']),
            {
                'account_id': self.client.account_id,
                'name': 'test-name2',
                'status': 'test-status',
            })
    
    def test_update_admin_pass_one_optional_param(self):
        response = self.client.update_admin(admin_id='test-id', name='test-name3')
        self.assertEqual(response['method'], 'POST')
        self.assertEqual(response['uri'], '/admin/v1/admins/test-id')
        self.assertEqual(
            json.loads(response['body']),
            {
                'account_id': self.client.account_id,
                'name': 'test-name3',
            })