Commit 98b2e753 by Jonathan Piacenti

Fix bok_choy tests for discussion.

parent 6af4af51
...@@ -6,6 +6,7 @@ import datetime ...@@ -6,6 +6,7 @@ import datetime
from pytz import UTC from pytz import UTC
from uuid import uuid4 from uuid import uuid4
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from common.test.acceptance.tests.discussion.helpers import BaseDiscussionTestCase
from ..helpers import UniqueCourseTest from ..helpers import UniqueCourseTest
from ...pages.lms.auto_auth import AutoAuthPage from ...pages.lms.auto_auth import AutoAuthPage
...@@ -112,22 +113,17 @@ class DiscussionResponsePaginationTestMixin(BaseDiscussionMixin): ...@@ -112,22 +113,17 @@ class DiscussionResponsePaginationTestMixin(BaseDiscussionMixin):
@attr('shard_1') @attr('shard_1')
class DiscussionTabSingleThreadTest(UniqueCourseTest, DiscussionResponsePaginationTestMixin): class DiscussionTabSingleThreadTest(BaseDiscussionTestCase, DiscussionResponsePaginationTestMixin):
""" """
Tests for the discussion page displaying a single thread Tests for the discussion page displaying a single thread
""" """
def setUp(self): def setUp(self):
super(DiscussionTabSingleThreadTest, self).setUp() super(DiscussionTabSingleThreadTest, self).setUp()
self.discussion_id = "test_discussion_{}".format(uuid4().hex)
# Create a course to register for
CourseFixture(**self.course_info).install()
AutoAuthPage(self.browser, course_id=self.course_id).visit() AutoAuthPage(self.browser, course_id=self.course_id).visit()
def setup_thread_page(self, thread_id): def setup_thread_page(self, thread_id):
self.thread_page = DiscussionTabSingleThreadPage(self.browser, self.course_id, thread_id) # pylint:disable=W0201 self.thread_page = self.create_single_thread_page(thread_id) # pylint: disable=attribute-defined-outside-init
self.thread_page.visit() self.thread_page.visit()
def test_marked_answer_comments(self): def test_marked_answer_comments(self):
...@@ -153,23 +149,17 @@ class DiscussionTabSingleThreadTest(UniqueCourseTest, DiscussionResponsePaginati ...@@ -153,23 +149,17 @@ class DiscussionTabSingleThreadTest(UniqueCourseTest, DiscussionResponsePaginati
@attr('shard_1') @attr('shard_1')
class DiscussionCommentDeletionTest(UniqueCourseTest): class DiscussionCommentDeletionTest(BaseDiscussionTestCase):
""" """
Tests for deleting comments displayed beneath responses in the single thread view. Tests for deleting comments displayed beneath responses in the single thread view.
""" """
def setUp(self):
super(DiscussionCommentDeletionTest, self).setUp()
# Create a course to register for
CourseFixture(**self.course_info).install()
def setup_user(self, roles=[]): def setup_user(self, roles=[]):
roles_str = ','.join(roles) roles_str = ','.join(roles)
self.user_id = AutoAuthPage(self.browser, course_id=self.course_id, roles=roles_str).visit().get_user_id() self.user_id = AutoAuthPage(self.browser, course_id=self.course_id, roles=roles_str).visit().get_user_id()
def setup_view(self): def setup_view(self):
view = SingleThreadViewFixture(Thread(id="comment_deletion_test_thread")) view = SingleThreadViewFixture(Thread(id="comment_deletion_test_thread", commentable_id=self.discussion_id))
view.addResponse( view.addResponse(
Response(id="response1"), Response(id="response1"),
[Comment(id="comment_other_author", user_id="other"), Comment(id="comment_self_author", user_id=self.user_id)]) [Comment(id="comment_other_author", user_id="other"), Comment(id="comment_self_author", user_id=self.user_id)])
...@@ -178,7 +168,7 @@ class DiscussionCommentDeletionTest(UniqueCourseTest): ...@@ -178,7 +168,7 @@ class DiscussionCommentDeletionTest(UniqueCourseTest):
def test_comment_deletion_as_student(self): def test_comment_deletion_as_student(self):
self.setup_user() self.setup_user()
self.setup_view() self.setup_view()
page = DiscussionTabSingleThreadPage(self.browser, self.course_id, "comment_deletion_test_thread") page = self.create_single_thread_page("comment_deletion_test_thread")
page.visit() page.visit()
self.assertTrue(page.is_comment_deletable("comment_self_author")) self.assertTrue(page.is_comment_deletable("comment_self_author"))
self.assertTrue(page.is_comment_visible("comment_other_author")) self.assertTrue(page.is_comment_visible("comment_other_author"))
...@@ -188,7 +178,7 @@ class DiscussionCommentDeletionTest(UniqueCourseTest): ...@@ -188,7 +178,7 @@ class DiscussionCommentDeletionTest(UniqueCourseTest):
def test_comment_deletion_as_moderator(self): def test_comment_deletion_as_moderator(self):
self.setup_user(roles=['Moderator']) self.setup_user(roles=['Moderator'])
self.setup_view() self.setup_view()
page = DiscussionTabSingleThreadPage(self.browser, self.course_id, "comment_deletion_test_thread") page = self.create_single_thread_page("comment_deletion_test_thread")
page.visit() page.visit()
self.assertTrue(page.is_comment_deletable("comment_self_author")) self.assertTrue(page.is_comment_deletable("comment_self_author"))
self.assertTrue(page.is_comment_deletable("comment_other_author")) self.assertTrue(page.is_comment_deletable("comment_other_author"))
...@@ -197,23 +187,17 @@ class DiscussionCommentDeletionTest(UniqueCourseTest): ...@@ -197,23 +187,17 @@ class DiscussionCommentDeletionTest(UniqueCourseTest):
@attr('shard_1') @attr('shard_1')
class DiscussionCommentEditTest(UniqueCourseTest): class DiscussionCommentEditTest(BaseDiscussionTestCase):
""" """
Tests for editing comments displayed beneath responses in the single thread view. Tests for editing comments displayed beneath responses in the single thread view.
""" """
def setUp(self):
super(DiscussionCommentEditTest, self).setUp()
# Create a course to register for
CourseFixture(**self.course_info).install()
def setup_user(self, roles=[]): def setup_user(self, roles=[]):
roles_str = ','.join(roles) roles_str = ','.join(roles)
self.user_id = AutoAuthPage(self.browser, course_id=self.course_id, roles=roles_str).visit().get_user_id() self.user_id = AutoAuthPage(self.browser, course_id=self.course_id, roles=roles_str).visit().get_user_id()
def setup_view(self): def setup_view(self):
view = SingleThreadViewFixture(Thread(id="comment_edit_test_thread")) view = SingleThreadViewFixture(Thread(id="comment_edit_test_thread", commentable_id=self.discussion_id))
view.addResponse( view.addResponse(
Response(id="response1"), Response(id="response1"),
[Comment(id="comment_other_author", user_id="other"), Comment(id="comment_self_author", user_id=self.user_id)]) [Comment(id="comment_other_author", user_id="other"), Comment(id="comment_self_author", user_id=self.user_id)])
...@@ -228,7 +212,7 @@ class DiscussionCommentEditTest(UniqueCourseTest): ...@@ -228,7 +212,7 @@ class DiscussionCommentEditTest(UniqueCourseTest):
def test_edit_comment_as_student(self): def test_edit_comment_as_student(self):
self.setup_user() self.setup_user()
self.setup_view() self.setup_view()
page = DiscussionTabSingleThreadPage(self.browser, self.course_id, "comment_edit_test_thread") page = self.create_single_thread_page("comment_edit_test_thread")
page.visit() page.visit()
self.assertTrue(page.is_comment_editable("comment_self_author")) self.assertTrue(page.is_comment_editable("comment_self_author"))
self.assertTrue(page.is_comment_visible("comment_other_author")) self.assertTrue(page.is_comment_visible("comment_other_author"))
...@@ -238,7 +222,7 @@ class DiscussionCommentEditTest(UniqueCourseTest): ...@@ -238,7 +222,7 @@ class DiscussionCommentEditTest(UniqueCourseTest):
def test_edit_comment_as_moderator(self): def test_edit_comment_as_moderator(self):
self.setup_user(roles=["Moderator"]) self.setup_user(roles=["Moderator"])
self.setup_view() self.setup_view()
page = DiscussionTabSingleThreadPage(self.browser, self.course_id, "comment_edit_test_thread") page = self.create_single_thread_page("comment_edit_test_thread")
page.visit() page.visit()
self.assertTrue(page.is_comment_editable("comment_self_author")) self.assertTrue(page.is_comment_editable("comment_self_author"))
self.assertTrue(page.is_comment_editable("comment_other_author")) self.assertTrue(page.is_comment_editable("comment_other_author"))
...@@ -248,7 +232,7 @@ class DiscussionCommentEditTest(UniqueCourseTest): ...@@ -248,7 +232,7 @@ class DiscussionCommentEditTest(UniqueCourseTest):
def test_cancel_comment_edit(self): def test_cancel_comment_edit(self):
self.setup_user() self.setup_user()
self.setup_view() self.setup_view()
page = DiscussionTabSingleThreadPage(self.browser, self.course_id, "comment_edit_test_thread") page = self.create_single_thread_page("comment_edit_test_thread")
page.visit() page.visit()
self.assertTrue(page.is_comment_editable("comment_self_author")) self.assertTrue(page.is_comment_editable("comment_self_author"))
original_body = page.get_comment_body("comment_self_author") original_body = page.get_comment_body("comment_self_author")
...@@ -260,7 +244,7 @@ class DiscussionCommentEditTest(UniqueCourseTest): ...@@ -260,7 +244,7 @@ class DiscussionCommentEditTest(UniqueCourseTest):
"""Only one editor should be visible at a time within a single response""" """Only one editor should be visible at a time within a single response"""
self.setup_user(roles=["Moderator"]) self.setup_user(roles=["Moderator"])
self.setup_view() self.setup_view()
page = DiscussionTabSingleThreadPage(self.browser, self.course_id, "comment_edit_test_thread") page = self.create_single_thread_page("comment_edit_test_thread")
page.visit() page.visit()
self.assertTrue(page.is_comment_editable("comment_self_author")) self.assertTrue(page.is_comment_editable("comment_self_author"))
self.assertTrue(page.is_comment_editable("comment_other_author")) self.assertTrue(page.is_comment_editable("comment_other_author"))
......
...@@ -23,9 +23,8 @@ from edx_notifications.lib.publisher import ( ...@@ -23,9 +23,8 @@ from edx_notifications.lib.publisher import (
get_notification_type get_notification_type
) )
from edx_notifications.data import NotificationMessage from edx_notifications.data import NotificationMessage
from openedx.core.djangoapps.course_groups.cohorts import get_cohort_id, is_commentable_cohorted, get_cohort_by_id from openedx.core.djangoapps.course_groups.cohorts import get_cohort_by_id
from openedx.core.djangoapps.course_groups.tasks import publish_course_group_notification_task from openedx.core.djangoapps.course_groups.tasks import publish_course_group_notification_task
from openedx.core.djangoapps.course_groups.models import CourseUserGroup
import django_comment_client.settings as cc_settings import django_comment_client.settings as cc_settings
from django_comment_client.utils import ( from django_comment_client.utils import (
add_courseware_context, add_courseware_context,
......
...@@ -327,8 +327,8 @@ class SingleThreadQueryCountTestCase(ModuleStoreTestCase): ...@@ -327,8 +327,8 @@ class SingleThreadQueryCountTestCase(ModuleStoreTestCase):
@ddt.data( @ddt.data(
# old mongo with cache # old mongo with cache
(ModuleStoreEnum.Type.mongo, 1, 6, 4, 12, 7), (ModuleStoreEnum.Type.mongo, 1, 8, 6, 12, 7),
(ModuleStoreEnum.Type.mongo, 50, 6, 4, 12, 7), (ModuleStoreEnum.Type.mongo, 50, 8, 6, 12, 7),
# split mongo: 3 queries, regardless of thread response size. # split mongo: 3 queries, regardless of thread response size.
(ModuleStoreEnum.Type.split, 1, 3, 3, 12, 7), (ModuleStoreEnum.Type.split, 1, 3, 3, 12, 7),
(ModuleStoreEnum.Type.split, 50, 3, 3, 12, 7), (ModuleStoreEnum.Type.split, 50, 3, 3, 12, 7),
......
...@@ -364,7 +364,6 @@ def single_thread(request, course_key, discussion_id, thread_id): ...@@ -364,7 +364,6 @@ def single_thread(request, course_key, discussion_id, thread_id):
) )
except cc.utils.CommentClientRequestError as e: except cc.utils.CommentClientRequestError as e:
if e.status_code == 404: if e.status_code == 404:
print "Can't find it!"
raise Http404 raise Http404
raise raise
...@@ -398,7 +397,6 @@ def single_thread(request, course_key, discussion_id, thread_id): ...@@ -398,7 +397,6 @@ def single_thread(request, course_key, discussion_id, thread_id):
add_courseware_context(threads, course, request.user) add_courseware_context(threads, course, request.user)
for thread in threads: for thread in threads:
add_thread_group_name(thread, course_key)
# patch for backward compatibility with comments service # patch for backward compatibility with comments service
if "pinned" not in thread: if "pinned" not in thread:
thread["pinned"] = False thread["pinned"] = False
......
...@@ -70,7 +70,9 @@ def get_accessible_discussion_modules(course, user, include_all=False): # pylin ...@@ -70,7 +70,9 @@ def get_accessible_discussion_modules(course, user, include_all=False): # pylin
Return a list of all valid discussion modules in this course that Return a list of all valid discussion modules in this course that
are accessible to the given user. are accessible to the given user.
""" """
all_modules = modulestore().get_items(course.id, qualifiers={'category': 'discussion'}) discussion_modules = modulestore().get_items(course.id, qualifiers={'category': 'discussion'})
discussion_xblocks = modulestore().get_items(course.id, qualifiers={'category': 'discussion-forum'})
all_modules = discussion_modules + discussion_xblocks
def has_required_keys(module): def has_required_keys(module):
for key in ('discussion_id', 'discussion_category', 'discussion_target'): for key in ('discussion_id', 'discussion_category', 'discussion_target'):
......
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