Merge pull request #21209 from edx/msingh/discussion_topic_validation2

PROD-145: Added validation to discussion topic input in studio, testing 2
This commit is contained in:
Manjinder Singh
2019-08-15 19:53:17 -04:00
committed by GitHub
4 changed files with 62 additions and 22 deletions

View File

@@ -120,7 +120,19 @@ def topic_name_to_id(course, name):
"""
Given a discussion topic name, return an id for that name (includes
course and url_name).
The set of valid characters for topic id is a smaller subset of valid
characters for topic name. Topic id can only have
these characters: a-z, A-Z, 0-9, underscore, hyphen, and period
Whereas, topic name character choice is much larger.
This function goes through all the characters in name and removes all invalid
characters and returns the resulting topic id.
"""
for index, indexed_character in enumerate(name):
if not (indexed_character.isalnum()
or indexed_character == "-"
or indexed_character == "_"
or indexed_character == "."):
name = name[:index] + "_" + name[index + 1:]
return "{course}_{run}_{name}".format(
course=course.location.course,
run=course.url_name,

View File

@@ -1928,7 +1928,7 @@ class CourseDiscussionSettingsAPIViewTest(APITestCase, UrlResetMixin, ModuleStor
start=datetime.now()
)
discussion_topics = {
"Topic B": {"id": "Topic B"},
"Topic B": {"id": "Topic_B"},
}
config_course_cohorts(self.course, is_cohorted=True)
config_course_discussions(
@@ -2073,7 +2073,7 @@ class CourseDiscussionSettingsAPIViewTest(APITestCase, UrlResetMixin, ModuleStor
def test_update_course_wide_discussion_settings(self):
"""Test whether the 'divided_course_wide_discussions' setting is updated."""
discussion_topics = {
'Topic B': {'id': 'Topic B'}
'Topic B': {'id': 'Topic_B'}
}
config_course_cohorts(self.course, is_cohorted=True)
config_course_discussions(self.course, discussion_topics=discussion_topics)