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
4c3e16cf
Commit
4c3e16cf
authored
Jul 11, 2017
by
attiyaishaque
Committed by
Attiya Ishaque
Jul 12, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EDUCATOR-831 Correct course title format in publisher course update.
parent
b049e652
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
1 deletions
+48
-1
course_discovery/apps/publisher/forms.py
+9
-0
course_discovery/apps/publisher/tests/test_forms.py
+39
-1
No files found.
course_discovery/apps/publisher/forms.py
View file @
4c3e16cf
"""
Course publisher forms.
"""
import
html
from
dal
import
autocomplete
from
django
import
forms
from
django.core.exceptions
import
ValidationError
...
...
@@ -193,6 +195,13 @@ class CustomCourseForm(CourseForm):
if
user
and
not
is_internal_user
(
user
):
self
.
fields
[
'video_link'
]
.
widget
=
forms
.
HiddenInput
()
def
clean_title
(
self
):
"""
Convert all named and numeric character references in the string
to the corresponding unicode characters
"""
return
html
.
unescape
(
self
.
cleaned_data
.
get
(
"title"
))
def
clean
(
self
):
cleaned_data
=
self
.
cleaned_data
organization
=
cleaned_data
.
get
(
"organization"
)
...
...
course_discovery/apps/publisher/tests/test_forms.py
View file @
4c3e16cf
...
...
@@ -9,7 +9,7 @@ from course_discovery.apps.core.tests.factories import UserFactory
from
course_discovery.apps.course_metadata.models
import
Person
from
course_discovery.apps.course_metadata.tests.factories
import
OrganizationFactory
,
PersonFactory
from
course_discovery.apps.publisher.forms
import
CustomCourseForm
,
CustomCourseRunForm
,
PublisherUserCreationForm
from
course_discovery.apps.publisher.tests.factories
import
CourseFactory
from
course_discovery.apps.publisher.tests.factories
import
CourseFactory
,
OrganizationExtensionFactory
class
UserModelChoiceFieldTests
(
TestCase
):
...
...
@@ -168,6 +168,23 @@ class PublisherCustomCourseFormTests(TestCase):
self
.
organization
=
OrganizationFactory
()
self
.
course
.
organizations
.
add
(
self
.
organization
)
def
setup_course
(
self
,
**
course_kwargs
):
"""
Creates the course and add organization and admin to this course.
Returns:
course: a course object
course_admin: a user object
"""
course
=
CourseFactory
(
**
course_kwargs
)
course_admin
=
UserFactory
(
username
=
'course_admin'
)
organization_extension
=
OrganizationExtensionFactory
()
organization
=
organization_extension
.
organization
course_admin
.
groups
.
add
(
organization_extension
.
group
)
course
.
organizations
.
add
(
organization
)
return
course
,
course_admin
def
test_duplicate_title
(
self
):
"""
Verify that clean raises 'ValidationError' if the course title is a duplicate of another course title
...
...
@@ -193,3 +210,24 @@ class PublisherCustomCourseFormTests(TestCase):
course_form
.
cleaned_data
[
'number'
]
=
"123a"
self
.
assertEqual
(
course_form
.
clean
(),
course_form
.
cleaned_data
)
def
test_course_title_formatting
(
self
):
"""
Verify that course_title is properly escaped and saved in database while
updating the course
"""
course
,
course_admin
=
self
.
setup_course
(
title
=
'test_course'
)
organization
=
course
.
organizations
.
all
()[
0
]
.
id
course_from_data
=
{
'title'
:
'áçã'
,
'number'
:
course
.
number
,
'organization'
:
organization
,
'team_admin'
:
course_admin
.
id
}
course_form
=
CustomCourseForm
(
**
{
'data'
:
course_from_data
,
'instance'
:
course
,
'user'
:
course_admin
,
'organization'
:
organization
}
)
self
.
assertTrue
(
course_form
.
is_valid
())
course_updated_data
=
course_form
.
save
()
self
.
assertTrue
(
course_updated_data
.
title
,
'áçã'
)
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