Move is_commentable_cohorted to django_comment_client
This commit is contained in:
@@ -121,42 +121,6 @@ def get_cohort_id(user, course_key, use_cached=False):
|
||||
return None if cohort is None else cohort.id
|
||||
|
||||
|
||||
def is_commentable_cohorted(course_key, commentable_id):
|
||||
"""
|
||||
Args:
|
||||
course_key: CourseKey
|
||||
commentable_id: string
|
||||
|
||||
Returns:
|
||||
Bool: is this commentable cohorted?
|
||||
|
||||
Raises:
|
||||
Http404 if the course doesn't exist.
|
||||
"""
|
||||
course = courses.get_course_by_id(course_key)
|
||||
course_cohort_settings = get_course_cohort_settings(course_key)
|
||||
|
||||
if not course_cohort_settings.is_cohorted:
|
||||
# this is the easy case :)
|
||||
ans = False
|
||||
elif (
|
||||
commentable_id in course.top_level_discussion_topic_ids or
|
||||
course_cohort_settings.always_cohort_inline_discussions is False
|
||||
):
|
||||
# top level discussions have to be manually configured as cohorted
|
||||
# (default is not).
|
||||
# Same thing for inline discussions if the default is explicitly set to False in settings
|
||||
ans = commentable_id in course_cohort_settings.cohorted_discussions
|
||||
else:
|
||||
# inline discussions are cohorted by default
|
||||
ans = True
|
||||
|
||||
log.debug(u"is_commentable_cohorted({0}, {1}) = {2}".format(
|
||||
course_key, commentable_id, ans
|
||||
))
|
||||
return ans
|
||||
|
||||
|
||||
def get_cohorted_commentables(course_key):
|
||||
"""
|
||||
Given a course_key return a set of strings representing cohorted commentables.
|
||||
|
||||
@@ -470,95 +470,6 @@ class TestCohorts(ModuleStoreTestCase):
|
||||
{cohort1.id: cohort1.name, cohort2.id: cohort2.name}
|
||||
)
|
||||
|
||||
def test_is_commentable_cohorted(self):
|
||||
course = modulestore().get_course(self.toy_course_key)
|
||||
self.assertFalse(cohorts.is_course_cohorted(course.id))
|
||||
|
||||
def to_id(name):
|
||||
return topic_name_to_id(course, name)
|
||||
|
||||
# no topics
|
||||
self.assertFalse(
|
||||
cohorts.is_commentable_cohorted(course.id, to_id("General")),
|
||||
"Course doesn't even have a 'General' topic"
|
||||
)
|
||||
|
||||
# not cohorted
|
||||
config_course_cohorts(course, is_cohorted=False, discussion_topics=["General", "Feedback"])
|
||||
|
||||
self.assertFalse(
|
||||
cohorts.is_commentable_cohorted(course.id, to_id("General")),
|
||||
"Course isn't cohorted"
|
||||
)
|
||||
|
||||
# cohorted, but top level topics aren't
|
||||
config_course_cohorts(course, is_cohorted=True, discussion_topics=["General", "Feedback"])
|
||||
|
||||
self.assertTrue(cohorts.is_course_cohorted(course.id))
|
||||
self.assertFalse(
|
||||
cohorts.is_commentable_cohorted(course.id, to_id("General")),
|
||||
"Course is cohorted, but 'General' isn't."
|
||||
)
|
||||
|
||||
# cohorted, including "Feedback" top-level topics aren't
|
||||
config_course_cohorts(
|
||||
course,
|
||||
is_cohorted=True,
|
||||
discussion_topics=["General", "Feedback"],
|
||||
cohorted_discussions=["Feedback"]
|
||||
)
|
||||
|
||||
self.assertTrue(cohorts.is_course_cohorted(course.id))
|
||||
self.assertFalse(
|
||||
cohorts.is_commentable_cohorted(course.id, to_id("General")),
|
||||
"Course is cohorted, but 'General' isn't."
|
||||
)
|
||||
self.assertTrue(
|
||||
cohorts.is_commentable_cohorted(course.id, to_id("Feedback")),
|
||||
"Feedback was listed as cohorted. Should be."
|
||||
)
|
||||
|
||||
def test_is_commentable_cohorted_inline_discussion(self):
|
||||
course = modulestore().get_course(self.toy_course_key)
|
||||
self.assertFalse(cohorts.is_course_cohorted(course.id))
|
||||
|
||||
def to_id(name): # pylint: disable=missing-docstring
|
||||
return topic_name_to_id(course, name)
|
||||
|
||||
config_course_cohorts(
|
||||
course,
|
||||
is_cohorted=True,
|
||||
discussion_topics=["General", "Feedback"],
|
||||
cohorted_discussions=["Feedback", "random_inline"]
|
||||
)
|
||||
self.assertTrue(
|
||||
cohorts.is_commentable_cohorted(course.id, to_id("random")),
|
||||
"By default, Non-top-level discussion is always cohorted in cohorted courses."
|
||||
)
|
||||
|
||||
# if always_cohort_inline_discussions is set to False, non-top-level discussion are always
|
||||
# non cohorted unless they are explicitly set in cohorted_discussions
|
||||
config_course_cohorts(
|
||||
course,
|
||||
is_cohorted=True,
|
||||
discussion_topics=["General", "Feedback"],
|
||||
cohorted_discussions=["Feedback", "random_inline"],
|
||||
always_cohort_inline_discussions=False
|
||||
)
|
||||
self.assertFalse(
|
||||
cohorts.is_commentable_cohorted(course.id, to_id("random")),
|
||||
"Non-top-level discussion is not cohorted if always_cohort_inline_discussions is False."
|
||||
)
|
||||
self.assertTrue(
|
||||
cohorts.is_commentable_cohorted(course.id, to_id("random_inline")),
|
||||
"If always_cohort_inline_discussions set to False, Non-top-level discussion is "
|
||||
"cohorted if explicitly set in cohorted_discussions."
|
||||
)
|
||||
self.assertTrue(
|
||||
cohorts.is_commentable_cohorted(course.id, to_id("Feedback")),
|
||||
"If always_cohort_inline_discussions set to False, top-level discussion are not affected."
|
||||
)
|
||||
|
||||
def test_get_cohorted_commentables(self):
|
||||
"""
|
||||
Make sure cohorts.get_cohorted_commentables() correctly returns a list of strings representing cohorted
|
||||
|
||||
Reference in New Issue
Block a user