-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[BD-38][TNL-7615] [BB-4846] feat: Add discussion_enabled for Unit #28864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
awaisdar001
merged 1 commit into
openedx:master
from
open-craft:farhaan/bb-4846-add-discussion-enabled-flag
Nov 8, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
cms/djangoapps/contentstore/views/tests/test_discussion_enabled.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| """ | ||
| Test module to test the discussion enabled flag. | ||
| """ | ||
|
|
||
|
|
||
| import json | ||
|
|
||
| from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory | ||
|
|
||
| from cms.djangoapps.contentstore.tests.utils import CourseTestCase | ||
| from cms.djangoapps.contentstore.utils import reverse_usage_url | ||
|
|
||
|
|
||
| class TestDiscussionEnabled(CourseTestCase): | ||
| """ | ||
| Test discussion enabled flags functionality in a Unit. | ||
| """ | ||
| def setUp(self): | ||
| super().setUp() | ||
| self.course = self.get_test_course() | ||
| self.course_usage_key = self.course.id.make_usage_key("course", self.course.id.run) | ||
| self.non_staff_authed_user_client, _ = self.create_non_staff_authed_user_client() | ||
|
|
||
| def get_test_course(self): | ||
| """ | ||
| Create and return a test course | ||
| """ | ||
| self.course = CourseFactory( | ||
| org="SHIELD", | ||
| number="SH101", | ||
| name="Introduction to Avengers", | ||
| run="2020_T2", | ||
| modulestore=self.store | ||
| ) | ||
| self.chapter = ItemFactory( | ||
| parent_location=self.course.location, | ||
| category="chapter", | ||
| display_name="What is SHIELD?", | ||
| modulestore=self.store | ||
| ) | ||
| self.sequential = ItemFactory( | ||
| parent_location=self.chapter.location, | ||
| category="sequential", | ||
| display_name="HQ", | ||
| modulestore=self.store | ||
| ) | ||
| self.vertical = ItemFactory( | ||
| parent_location=self.sequential.location, | ||
| category="vertical", | ||
| display_name="Triskelion", | ||
| modulestore=self.store | ||
| ) | ||
| self.vertical_1 = ItemFactory( | ||
| parent_location=self.sequential.location, | ||
| category="vertical", | ||
| display_name="Helicarrier", | ||
| modulestore=self.store | ||
| ) | ||
| self.course.save() | ||
| return self.course | ||
|
|
||
| def _get_discussion_enabled_status(self, usage_key, client=None): | ||
| """ | ||
| Issue a GET request to fetch value of discussion_enabled flag of xblock represented by param:usage_key | ||
| """ | ||
| client = client if client is not None else self.client | ||
| url = reverse_usage_url("xblock_handler", usage_key) | ||
| resp = client.get(url, HTTP_ACCEPT="application/json") | ||
| return resp | ||
|
|
||
| def get_discussion_enabled_status(self, xblock, client=None): | ||
| """ | ||
| Issue a GET request to fetch value of discussion_enabled flag of param:xblock's | ||
| """ | ||
| resp = self._get_discussion_enabled_status(xblock.location, client=client) | ||
| content = json.loads(resp.content.decode("utf-8")) | ||
| return content.get("discussion_enabled", None) | ||
|
|
||
| def set_discussion_enabled_status(self, xblock, value, client=None): | ||
| """ | ||
| Issue a POST request to update value of discussion_enabled flag of param:xblock's | ||
| """ | ||
| client = client if client is not None else self.client | ||
| xblock_location = xblock.location | ||
| url = reverse_usage_url("xblock_handler", xblock_location) | ||
| resp = client.post( | ||
| url, | ||
| HTTP_ACCEPT="application/json", | ||
| data=json.dumps({"metadata": {"discussion_enabled": value}}), | ||
| content_type="application/json", | ||
| ) | ||
| return resp | ||
|
|
||
| def test_discussion_enabled_false_initially(self): | ||
| """ | ||
| Tests discussion_enabled flag is False initially for vertical | ||
| """ | ||
| self.assertFalse(self.get_discussion_enabled_status(self.vertical)) | ||
| self.assertFalse(self.get_discussion_enabled_status(self.vertical_1)) | ||
|
|
||
| def test_discussion_enabled_toggle(self): | ||
| """ | ||
| Tests discussion_enabled can be toggled. | ||
| """ | ||
| self.set_discussion_enabled_status(self.vertical, True) | ||
| self.assertTrue(self.get_discussion_enabled_status(self.vertical)) | ||
| self.assertFalse(self.get_discussion_enabled_status(self.vertical_1)) | ||
|
|
||
| def test_non_course_author_cannot_get_or_set_discussion_enabled_flag(self): | ||
| """ | ||
| Test non course author cannot get/set discussion_enabled flag | ||
| """ | ||
| resp = self._get_discussion_enabled_status(self.course_usage_key, self.non_staff_authed_user_client) | ||
| self.assertEqual(resp.status_code, 403) | ||
| # Set call to the API with non authorised user should raise a 403 | ||
| resp = self.set_discussion_enabled_status(self.vertical, True, self.non_staff_authed_user_client) | ||
| self.assertEqual(resp.status_code, 403) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.