141 |
141 |
assert resp.json['next'] is None
|
142 |
142 |
|
143 |
143 |
|
|
144 |
def test_api_users_fetch_roles(settings, app, api_user, user_rando):
|
|
145 |
from django.contrib.auth import get_user_model
|
|
146 |
from authentic2.models import Attribute, AttributeValue
|
|
147 |
app.authorization = ('Basic', (api_user.username, api_user.username))
|
|
148 |
|
|
149 |
resp = app.get('/api/users/%s/' % user_rando.uuid)
|
|
150 |
|
|
151 |
assert len(resp.json['roles']) == 2
|
|
152 |
|
|
153 |
|
|
154 |
def test_api_users_readonly_fields(settings, app, api_user, role_random, role_misc):
|
|
155 |
from django.contrib.auth import get_user_model
|
|
156 |
from authentic2.models import Attribute, AttributeValue
|
|
157 |
app.authorization = ('Basic', (api_user.username, api_user.username))
|
|
158 |
|
|
159 |
payload = {
|
|
160 |
'username': 'john.doe',
|
|
161 |
'first_name': 'John',
|
|
162 |
'last_name': 'Doe',
|
|
163 |
'email': 'john.doe@example.net',
|
|
164 |
'password': 'password',
|
|
165 |
'roles': ['rando', 'misc'],
|
|
166 |
}
|
|
167 |
|
|
168 |
if api_user.is_superuser:
|
|
169 |
status = 201
|
|
170 |
elif api_user.roles.exists():
|
|
171 |
status = 201
|
|
172 |
payload['ou'] = api_user.ou.slug
|
|
173 |
else:
|
|
174 |
status = 403
|
|
175 |
|
|
176 |
resp = app.post_json('/api/users/', params=payload, status=status)
|
|
177 |
if api_user.is_superuser or api_user.roles.exists():
|
|
178 |
assert resp.json['first_name'] == payload['first_name']
|
|
179 |
assert resp.json['last_name'] == payload['last_name']
|
|
180 |
assert resp.json['email'] == payload['email']
|
|
181 |
assert resp.json['username'] == payload['username']
|
|
182 |
assert resp.json['uuid']
|
|
183 |
assert resp.json['id']
|
|
184 |
|
|
185 |
# Test empty roles attribute
|
|
186 |
assert resp.json['roles'] == []
|
|
187 |
|
|
188 |
|
144 |
189 |
def test_api_users_create(settings, app, api_user):
|
145 |
190 |
from django.contrib.auth import get_user_model
|
146 |
191 |
from authentic2.models import Attribute, AttributeValue
|
... | ... | |
188 |
233 |
if api_user.is_superuser or api_user.roles.exists():
|
189 |
234 |
assert set(['ou', 'id', 'uuid', 'is_staff', 'is_superuser', 'first_name', 'last_name',
|
190 |
235 |
'date_joined', 'last_login', 'username', 'password', 'email', 'is_active',
|
191 |
|
'title', 'modified', 'email_verified']) == set(resp.json.keys())
|
|
236 |
'title', 'modified', 'email_verified', 'roles']) == set(resp.json.keys())
|
192 |
237 |
assert resp.json['first_name'] == payload['first_name']
|
193 |
238 |
assert resp.json['last_name'] == payload['last_name']
|
194 |
239 |
assert resp.json['email'] == payload['email']
|
195 |
|
-
|