Commit e7c0d0da by vkaracic Committed by Jonathan Piacenti

API call to display 'is_staff' attribute

This is a prerequisite for YONK-69:
https://openedx.atlassian.net/browse/YONK-69
parent b872ab80
......@@ -39,7 +39,7 @@ class UserSerializer(DynamicFieldsModelSerializer):
class Meta:
""" Serializer/field specification """
model = APIUser
fields = ("id", "email", "username", "first_name", "last_name", "created", "is_active", "organizations", "avatar_url", "city", "title", "country", "full_name")
fields = ("id", "email", "username", "first_name", "last_name", "created", "is_active", "organizations", "avatar_url", "city", "title", "country", "full_name", "is_staff")
read_only_fields = ("id", "email", "username")
class SimpleUserSerializer(DynamicFieldsModelSerializer):
......
......@@ -197,6 +197,37 @@ class UsersApiTests(ModuleStoreTestCase):
user_id = response.data['id']
return user_id
def test_user_is_staff(self):
"""
Test if a user is a staff member
"""
test_uri = self.users_base_uri
for i in xrange(1, 7):
data = {
'email': 'test{}@example.com'.format(i),
'username': 'test_user{}'.format(i),
'password': 'PassWord1',
'first_name': 'John',
'last_name': 'Doe',
'city': 'Boston',
}
data['is_staff'] = True if i % 2 == 0 else False
response = self.do_post(test_uri, data)
self.assertEqual(response.status_code, 201)
# Test for Robot user with ID 1
response = self.do_get('{}?ids={}'.format(test_uri, '1,2,3,4,5,6,7'))
self.assertEqual(response.status_code, 200)
# ID 1 is a Robot Test (results[0]) so the users list starts with ID 2 (results[1])
self.assertEqual(response.data['results'][1]['is_staff'], False)
self.assertEqual(response.data['results'][3]['is_staff'], False)
self.assertEqual(response.data['results'][5]['is_staff'], False)
self.assertTrue(response.data['results'][2]['is_staff'])
self.assertTrue(response.data['results'][4]['is_staff'])
self.assertTrue(response.data['results'][6]['is_staff'])
def test_user_list_get(self):
test_uri = self.users_base_uri
users = []
......
......@@ -87,6 +87,7 @@ def _serialize_user(response_data, user):
response_data['id'] = user.id
response_data['is_active'] = user.is_active
response_data['created'] = user.date_joined
response_data['is_staff'] = user.is_staff
return response_data
......@@ -329,6 +330,7 @@ class UsersList(SecureListAPIView):
profile.gender = gender
profile.title = title
profile.avatar_url = avatar_url
profile.is_staff = is_staff
try:
profile.year_of_birth = int(year_of_birth)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment