Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
ac43a015
Commit
ac43a015
authored
Feb 13, 2017
by
Waheed Ahmed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Course team admin dropdown fallback to username if full_name not set.
ECOM-6976
parent
e4ad2a6d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
16 deletions
+44
-16
course_discovery/apps/publisher/api/serializers.py
+5
-1
course_discovery/apps/publisher/api/tests/test_serializers.py
+14
-3
course_discovery/apps/publisher/api/tests/test_views.py
+6
-6
course_discovery/apps/publisher/forms.py
+1
-1
course_discovery/apps/publisher/tests/test_forms.py
+18
-5
No files found.
course_discovery/apps/publisher/api/serializers.py
View file @
ac43a015
...
...
@@ -32,10 +32,14 @@ class CourseUserRoleSerializer(serializers.ModelSerializer):
class
GroupUserSerializer
(
serializers
.
ModelSerializer
):
"""Serializer for the `User` model used in OrganizationGroupUserView. """
full_name
=
serializers
.
SerializerMethodField
(
'get_user_full_name'
)
class
Meta
:
model
=
User
fields
=
(
'id'
,
'full_name'
,
)
fields
=
(
'id'
,
'full_name'
,)
def
get_user_full_name
(
self
,
obj
):
return
obj
.
get_full_name
()
or
obj
.
username
class
UpdateCourseKeySerializer
(
serializers
.
ModelSerializer
):
...
...
course_discovery/apps/publisher/api/tests/test_serializers.py
View file @
ac43a015
...
...
@@ -38,13 +38,24 @@ class CourseUserRoleSerializerTests(TestCase):
class
GroupUserSerializerTests
(
TestCase
):
def
test_date
(
self
):
def
test_data_with_full_name
(
self
):
""" Verify that UserSerializer serialize the user object. """
user
=
UserFactory
(
full_name
=
'Test User'
)
serializer
=
GroupUserSerializer
(
user
)
expected
=
{
'id'
:
user
.
id
,
'full_name'
:
user
.
full_name
}
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
def
test_data_without_full_name
(
self
):
""" Verify that UserSerializer serialize the user object. """
user
=
UserFactory
(
full_name
=
"test user"
)
user
=
UserFactory
(
full_name
=
''
,
first_name
=
''
,
last_name
=
''
)
serializer
=
GroupUserSerializer
(
user
)
self
.
assertDictEqual
(
serializer
.
data
,
{
'id'
:
user
.
id
,
'full_name'
:
user
.
full_name
})
expected
=
{
'id'
:
user
.
id
,
'full_name'
:
user
.
username
}
self
.
assertDictEqual
(
serializer
.
data
,
expected
)
class
UpdateCourseKeySerializerTests
(
TestCase
):
...
...
course_discovery/apps/publisher/api/tests/test_views.py
View file @
ac43a015
...
...
@@ -163,17 +163,17 @@ class OrganizationGroupUserViewTests(TestCase):
organization_extension
=
factories
.
OrganizationExtensionFactory
()
self
.
org_user1
=
UserFactory
.
create
(
full_name
=
"org user1"
)
self
.
org_user2
=
UserFactory
.
create
(
full_name
=
"org user2"
)
organization_extension
.
group
.
user_set
.
add
(
self
.
org_user1
)
organization_extension
.
group
.
user_set
.
add
(
self
.
org_user2
)
self
.
org_user2
=
UserFactory
.
create
(
first_name
=
''
,
last_name
=
''
,
full_name
=
''
)
organization_extension
.
group
.
user_set
.
add
(
*
[
self
.
org_user1
,
self
.
org_user2
])
self
.
organization
=
organization_extension
.
organization
def
test_get_organization_user_group
(
self
):
""" Verify that view returns list of users associated with the group
related to given organization id.
"""
response
=
self
.
client
.
get
(
path
=
self
.
_get_organization_group_user_url
(
self
.
organization
.
id
),
content_type
=
JSON_CONTENT_TYPE
)
response
=
self
.
client
.
get
(
path
=
self
.
_get_organization_group_user_url
(
self
.
organization
.
id
),
content_type
=
JSON_CONTENT_TYPE
)
self
.
assertEqual
(
response
.
status_code
,
200
)
expected_results
=
[
...
...
@@ -183,7 +183,7 @@ class OrganizationGroupUserViewTests(TestCase):
},
{
"id"
:
self
.
org_user2
.
id
,
"full_name"
:
self
.
org_user2
.
full_
name
"full_name"
:
self
.
org_user2
.
user
name
}
]
...
...
course_discovery/apps/publisher/forms.py
View file @
ac43a015
...
...
@@ -20,7 +20,7 @@ from course_discovery.apps.publisher.models import (
class
UserModelChoiceField
(
forms
.
ModelChoiceField
):
def
label_from_instance
(
self
,
obj
):
return
obj
.
get_full_name
()
return
obj
.
get_full_name
()
or
obj
.
username
class
PersonModelMultipleChoice
(
forms
.
ModelMultipleChoiceField
):
...
...
course_discovery/apps/publisher/tests/test_forms.py
View file @
ac43a015
...
...
@@ -12,18 +12,31 @@ class UserModelChoiceFieldTests(TestCase):
Tests for the publisher model "UserModelChoiceField".
"""
def
setUp
(
self
):
super
(
UserModelChoiceFieldTests
,
self
)
.
setUp
()
self
.
course_form
=
CustomCourseForm
()
def
test_course_form
(
self
):
"""
Verify that UserModelChoiceField returns `full_name` as choice label.
"""
course_form
=
CustomCourseForm
()
user
=
UserFactory
(
username
=
'test_user'
,
full_name
=
'Test Full Name'
)
course_form
.
fields
[
'team_admin'
]
.
queryset
=
User
.
objects
.
all
()
course_form
.
fields
[
'team_admin'
]
.
empty_label
=
None
self
.
_assert_choice_label
(
user
.
full_name
)
def
test_team_admin_without_full_name
(
self
):
"""
Verify that UserModelChoiceField returns `username` if `full_name` empty.
"""
user
=
UserFactory
(
username
=
'test_user'
,
full_name
=
''
,
first_name
=
''
,
last_name
=
''
)
self
.
_assert_choice_label
(
user
.
username
)
def
_assert_choice_label
(
self
,
expected_name
):
self
.
course_form
.
fields
[
'team_admin'
]
.
queryset
=
User
.
objects
.
all
()
self
.
course_form
.
fields
[
'team_admin'
]
.
empty_label
=
None
# we need to loop through choices because it is a ModelChoiceIterator
for
__
,
choice_label
in
course_form
.
fields
[
'team_admin'
]
.
choices
:
self
.
assertEqual
(
choice_label
,
user
.
full
_name
)
for
__
,
choice_label
in
self
.
course_form
.
fields
[
'team_admin'
]
.
choices
:
self
.
assertEqual
(
choice_label
,
expected
_name
)
class
PersonModelMultipleChoiceTests
(
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment