Check access for discussion modules in forums
TNL-650 Conflicts: lms/djangoapps/django_comment_client/base/views.py lms/djangoapps/django_comment_client/tests/test_utils.py lms/djangoapps/django_comment_client/tests/utils.py lms/djangoapps/django_comment_client/utils.py
This commit is contained in:
@@ -5,12 +5,15 @@ Helper functions and classes for discussion tests.
|
||||
from uuid import uuid4
|
||||
import json
|
||||
|
||||
from ...fixtures import LMS_BASE_URL
|
||||
from ...fixtures.course import CourseFixture
|
||||
from ...fixtures.discussion import (
|
||||
SingleThreadViewFixture,
|
||||
Thread,
|
||||
Response,
|
||||
)
|
||||
from ...fixtures import LMS_BASE_URL
|
||||
from ...pages.lms.discussion import DiscussionTabSingleThreadPage
|
||||
from ...tests.helpers import UniqueCourseTest
|
||||
|
||||
|
||||
class BaseDiscussionMixin(object):
|
||||
@@ -83,3 +86,22 @@ class CohortTestMixin(object):
|
||||
data = {"users": username}
|
||||
response = course_fixture.session.post(url, data=data, headers=course_fixture.headers)
|
||||
self.assertTrue(response.ok, "Failed to add user to cohort")
|
||||
|
||||
|
||||
class BaseDiscussionTestCase(UniqueCourseTest):
|
||||
def setUp(self):
|
||||
super(BaseDiscussionTestCase, self).setUp()
|
||||
|
||||
self.discussion_id = "test_discussion_{}".format(uuid4().hex)
|
||||
self.course_fixture = CourseFixture(**self.course_info)
|
||||
self.course_fixture.add_advanced_settings(
|
||||
{'discussion_topics': {'value': {'Test Discussion Topic': {'id': self.discussion_id}}}}
|
||||
)
|
||||
self.course_fixture.install()
|
||||
|
||||
def create_single_thread_page(self, thread_id):
|
||||
"""
|
||||
Sets up a `DiscussionTabSingleThreadPage` for a given
|
||||
`thread_id`.
|
||||
"""
|
||||
return DiscussionTabSingleThreadPage(self.browser, self.course_id, self.discussion_id, thread_id)
|
||||
|
||||
@@ -3,7 +3,7 @@ Tests related to the cohorting feature.
|
||||
"""
|
||||
from uuid import uuid4
|
||||
|
||||
from .helpers import BaseDiscussionMixin
|
||||
from .helpers import BaseDiscussionMixin, BaseDiscussionTestCase
|
||||
from .helpers import CohortTestMixin
|
||||
from ..helpers import UniqueCourseTest
|
||||
from ...pages.lms.auto_auth import AutoAuthPage
|
||||
@@ -57,20 +57,17 @@ class CohortedDiscussionTestMixin(BaseDiscussionMixin, CohortTestMixin):
|
||||
self.assertEquals(self.thread_page.get_group_visibility_label(), "This post is visible to everyone.")
|
||||
|
||||
|
||||
class DiscussionTabSingleThreadTest(UniqueCourseTest):
|
||||
class DiscussionTabSingleThreadTest(BaseDiscussionTestCase):
|
||||
"""
|
||||
Tests for the discussion page displaying a single thread.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(DiscussionTabSingleThreadTest, self).setUp()
|
||||
self.discussion_id = "test_discussion_{}".format(uuid4().hex)
|
||||
# Create a course to register for
|
||||
self.course_fixture = CourseFixture(**self.course_info).install()
|
||||
self.setup_cohorts()
|
||||
AutoAuthPage(self.browser, course_id=self.course_id).visit()
|
||||
|
||||
def setup_thread_page(self, thread_id):
|
||||
self.thread_page = DiscussionTabSingleThreadPage(self.browser, self.course_id, thread_id) # pylint: disable=attribute-defined-outside-init
|
||||
self.thread_page = DiscussionTabSingleThreadPage(self.browser, self.course_id, self.discussion_id, thread_id) # pylint: disable=attribute-defined-outside-init
|
||||
self.thread_page.visit()
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
|
||||
@@ -7,6 +7,7 @@ from pytz import UTC
|
||||
from uuid import uuid4
|
||||
from nose.plugins.attrib import attr
|
||||
|
||||
from .helpers import BaseDiscussionTestCase
|
||||
from ..helpers import UniqueCourseTest
|
||||
from ...pages.lms.auto_auth import AutoAuthPage
|
||||
from ...pages.lms.courseware import CoursewarePage
|
||||
@@ -139,22 +140,17 @@ class DiscussionHomePageTest(UniqueCourseTest):
|
||||
|
||||
|
||||
@attr('shard_1')
|
||||
class DiscussionTabSingleThreadTest(UniqueCourseTest, DiscussionResponsePaginationTestMixin):
|
||||
class DiscussionTabSingleThreadTest(BaseDiscussionTestCase, DiscussionResponsePaginationTestMixin):
|
||||
"""
|
||||
Tests for the discussion page displaying a single thread
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
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()
|
||||
|
||||
def setup_thread_page(self, thread_id):
|
||||
self.thread_page = DiscussionTabSingleThreadPage(self.browser, self.course_id, thread_id) # pylint: disable=attribute-defined-outside-init
|
||||
self.thread_page = self.create_single_thread_page(thread_id) # pylint: disable=attribute-defined-outside-init
|
||||
self.thread_page.visit()
|
||||
|
||||
def test_marked_answer_comments(self):
|
||||
@@ -180,7 +176,7 @@ class DiscussionTabSingleThreadTest(UniqueCourseTest, DiscussionResponsePaginati
|
||||
|
||||
|
||||
@attr('shard_1')
|
||||
class DiscussionOpenClosedThreadTest(UniqueCourseTest):
|
||||
class DiscussionOpenClosedThreadTest(BaseDiscussionTestCase):
|
||||
"""
|
||||
Tests for checking the display of attributes on open and closed threads
|
||||
"""
|
||||
@@ -188,8 +184,6 @@ class DiscussionOpenClosedThreadTest(UniqueCourseTest):
|
||||
def setUp(self):
|
||||
super(DiscussionOpenClosedThreadTest, self).setUp()
|
||||
|
||||
# Create a course to register for
|
||||
CourseFixture(**self.course_info).install()
|
||||
self.thread_id = "test_thread_{}".format(uuid4().hex)
|
||||
|
||||
def setup_user(self, roles=[]):
|
||||
@@ -197,6 +191,7 @@ class DiscussionOpenClosedThreadTest(UniqueCourseTest):
|
||||
self.user_id = AutoAuthPage(self.browser, course_id=self.course_id, roles=roles_str).visit().get_user_id()
|
||||
|
||||
def setup_view(self, **thread_kwargs):
|
||||
thread_kwargs.update({'commentable_id': self.discussion_id})
|
||||
view = SingleThreadViewFixture(
|
||||
Thread(id=self.thread_id, **thread_kwargs)
|
||||
)
|
||||
@@ -209,7 +204,7 @@ class DiscussionOpenClosedThreadTest(UniqueCourseTest):
|
||||
self.setup_view(closed=True)
|
||||
else:
|
||||
self.setup_view()
|
||||
page = DiscussionTabSingleThreadPage(self.browser, self.course_id, self.thread_id)
|
||||
page = self.create_single_thread_page(self.thread_id)
|
||||
page.visit()
|
||||
page.close_open_thread()
|
||||
return page
|
||||
@@ -230,23 +225,16 @@ class DiscussionOpenClosedThreadTest(UniqueCourseTest):
|
||||
|
||||
|
||||
@attr('shard_1')
|
||||
class DiscussionCommentDeletionTest(UniqueCourseTest):
|
||||
class DiscussionCommentDeletionTest(BaseDiscussionTestCase):
|
||||
"""
|
||||
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=[]):
|
||||
roles_str = ','.join(roles)
|
||||
self.user_id = AutoAuthPage(self.browser, course_id=self.course_id, roles=roles_str).visit().get_user_id()
|
||||
|
||||
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(
|
||||
Response(id="response1"),
|
||||
[Comment(id="comment_other_author", user_id="other"), Comment(id="comment_self_author", user_id=self.user_id)])
|
||||
@@ -255,7 +243,7 @@ class DiscussionCommentDeletionTest(UniqueCourseTest):
|
||||
def test_comment_deletion_as_student(self):
|
||||
self.setup_user()
|
||||
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()
|
||||
self.assertTrue(page.is_comment_deletable("comment_self_author"))
|
||||
self.assertTrue(page.is_comment_visible("comment_other_author"))
|
||||
@@ -265,7 +253,7 @@ class DiscussionCommentDeletionTest(UniqueCourseTest):
|
||||
def test_comment_deletion_as_moderator(self):
|
||||
self.setup_user(roles=['Moderator'])
|
||||
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()
|
||||
self.assertTrue(page.is_comment_deletable("comment_self_author"))
|
||||
self.assertTrue(page.is_comment_deletable("comment_other_author"))
|
||||
@@ -274,23 +262,16 @@ class DiscussionCommentDeletionTest(UniqueCourseTest):
|
||||
|
||||
|
||||
@attr('shard_1')
|
||||
class DiscussionResponseEditTest(UniqueCourseTest):
|
||||
class DiscussionResponseEditTest(BaseDiscussionTestCase):
|
||||
"""
|
||||
Tests for editing responses displayed beneath thread in the single thread view.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(DiscussionResponseEditTest, self).setUp()
|
||||
|
||||
# Create a course to register for
|
||||
CourseFixture(**self.course_info).install()
|
||||
|
||||
def setup_user(self, roles=[]):
|
||||
roles_str = ','.join(roles)
|
||||
self.user_id = AutoAuthPage(self.browser, course_id=self.course_id, roles=roles_str).visit().get_user_id()
|
||||
|
||||
def setup_view(self):
|
||||
view = SingleThreadViewFixture(Thread(id="response_edit_test_thread"))
|
||||
view = SingleThreadViewFixture(Thread(id="response_edit_test_thread", commentable_id=self.discussion_id))
|
||||
view.addResponse(
|
||||
Response(id="response_other_author", user_id="other", thread_id="response_edit_test_thread"),
|
||||
)
|
||||
@@ -317,7 +298,7 @@ class DiscussionResponseEditTest(UniqueCourseTest):
|
||||
"""
|
||||
self.setup_user()
|
||||
self.setup_view()
|
||||
page = DiscussionTabSingleThreadPage(self.browser, self.course_id, "response_edit_test_thread")
|
||||
page = self.create_single_thread_page("response_edit_test_thread")
|
||||
page.visit()
|
||||
self.assertTrue(page.is_response_visible("response_other_author"))
|
||||
self.assertFalse(page.is_response_editable("response_other_author"))
|
||||
@@ -334,7 +315,7 @@ class DiscussionResponseEditTest(UniqueCourseTest):
|
||||
"""
|
||||
self.setup_user(roles=["Moderator"])
|
||||
self.setup_view()
|
||||
page = DiscussionTabSingleThreadPage(self.browser, self.course_id, "response_edit_test_thread")
|
||||
page = self.create_single_thread_page("response_edit_test_thread")
|
||||
page.visit()
|
||||
self.edit_response(page, "response_self_author")
|
||||
self.edit_response(page, "response_other_author")
|
||||
@@ -362,7 +343,7 @@ class DiscussionResponseEditTest(UniqueCourseTest):
|
||||
"""
|
||||
self.setup_user(roles=["Moderator"])
|
||||
self.setup_view()
|
||||
page = DiscussionTabSingleThreadPage(self.browser, self.course_id, "response_edit_test_thread")
|
||||
page = self.create_single_thread_page("response_edit_test_thread")
|
||||
page.visit()
|
||||
self.edit_response(page, "response_self_author")
|
||||
self.edit_response(page, "response_other_author")
|
||||
@@ -375,23 +356,16 @@ class DiscussionResponseEditTest(UniqueCourseTest):
|
||||
|
||||
|
||||
@attr('shard_1')
|
||||
class DiscussionCommentEditTest(UniqueCourseTest):
|
||||
class DiscussionCommentEditTest(BaseDiscussionTestCase):
|
||||
"""
|
||||
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=[]):
|
||||
roles_str = ','.join(roles)
|
||||
self.user_id = AutoAuthPage(self.browser, course_id=self.course_id, roles=roles_str).visit().get_user_id()
|
||||
|
||||
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(
|
||||
Response(id="response1"),
|
||||
[Comment(id="comment_other_author", user_id="other"), Comment(id="comment_self_author", user_id=self.user_id)])
|
||||
@@ -406,7 +380,7 @@ class DiscussionCommentEditTest(UniqueCourseTest):
|
||||
def test_edit_comment_as_student(self):
|
||||
self.setup_user()
|
||||
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()
|
||||
self.assertTrue(page.is_comment_editable("comment_self_author"))
|
||||
self.assertTrue(page.is_comment_visible("comment_other_author"))
|
||||
@@ -416,7 +390,7 @@ class DiscussionCommentEditTest(UniqueCourseTest):
|
||||
def test_edit_comment_as_moderator(self):
|
||||
self.setup_user(roles=["Moderator"])
|
||||
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()
|
||||
self.assertTrue(page.is_comment_editable("comment_self_author"))
|
||||
self.assertTrue(page.is_comment_editable("comment_other_author"))
|
||||
@@ -426,7 +400,7 @@ class DiscussionCommentEditTest(UniqueCourseTest):
|
||||
def test_cancel_comment_edit(self):
|
||||
self.setup_user()
|
||||
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()
|
||||
self.assertTrue(page.is_comment_editable("comment_self_author"))
|
||||
original_body = page.get_comment_body("comment_self_author")
|
||||
@@ -438,7 +412,7 @@ class DiscussionCommentEditTest(UniqueCourseTest):
|
||||
"""Only one editor should be visible at a time within a single response"""
|
||||
self.setup_user(roles=["Moderator"])
|
||||
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()
|
||||
self.assertTrue(page.is_comment_editable("comment_self_author"))
|
||||
self.assertTrue(page.is_comment_editable("comment_other_author"))
|
||||
|
||||
Reference in New Issue
Block a user