diff --git a/lms/djangoapps/discussion_api/tests/test_forms.py b/lms/djangoapps/discussion_api/tests/test_forms.py index ab09f0b969..cd841e9fcc 100644 --- a/lms/djangoapps/discussion_api/tests/test_forms.py +++ b/lms/djangoapps/discussion_api/tests/test_forms.py @@ -100,14 +100,20 @@ class ThreadListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase): self.form_data.setlist("topic_id", ["", "not empty"]) self.assert_error("topic_id", "This field cannot be empty.") - def test_following_true(self): - self.form_data["following"] = "True" + @ddt.data("True", "true", 1, True) + def test_following_true(self, value): + self.form_data["following"] = value self.assert_field_value("following", True) - def test_following_false(self): - self.form_data["following"] = "False" + @ddt.data("False", "false", 0, False) + def test_following_false(self, value): + self.form_data["following"] = value self.assert_error("following", "The value of the 'following' parameter must be true.") + def test_invalid_following(self): + self.form_data["following"] = "invalid-boolean" + self.assert_error("following", "Invalid Boolean Value.") + @ddt.data(*itertools.combinations(["topic_id", "text_search", "following"], 2)) def test_mutually_exclusive(self, params): self.form_data.update({param: "True" for param in params}) @@ -134,7 +140,22 @@ class ThreadListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase): "Select a valid choice. not_a_valid_choice is not one of the available choices." ) + @ddt.data( + ("view", "unread"), + ("view", "unanswered"), + ("order_by", "last_activity_at"), + ("order_by", "comment_count"), + ("order_by", "vote_count"), + ("order_direction", "asc"), + ("order_direction", "desc"), + ) + @ddt.unpack + def test_valid_choice_fields(self, field, value): + self.form_data[field] = value + self.assert_field_value(field, value) + +@ddt.ddt class CommentListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase): """Tests for CommentListGetForm""" FORM_CLASS = CommentListGetForm @@ -167,3 +188,17 @@ class CommentListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase): def test_missing_endorsed(self): self.form_data.pop("endorsed") self.assert_field_value("endorsed", None) + + @ddt.data("True", "true", True, 1) + def test_endorsed_true(self, value): + self.form_data["endorsed"] = value + self.assert_field_value("endorsed", True) + + @ddt.data("False", "false", False, 0) + def test_endorsed_false(self, value): + self.form_data["endorsed"] = value + self.assert_field_value("endorsed", False) + + def test_invalid_endorsed(self): + self.form_data["endorsed"] = "invalid-boolean" + self.assert_error("endorsed", "Invalid Boolean Value.") diff --git a/lms/djangoapps/discussion_api/tests/test_views.py b/lms/djangoapps/discussion_api/tests/test_views.py index 44dcde6def..2727566877 100644 --- a/lms/djangoapps/discussion_api/tests/test_views.py +++ b/lms/djangoapps/discussion_api/tests/test_views.py @@ -1014,6 +1014,39 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): parsed_content = json.loads(response.content) self.assertEqual(parsed_content["results"][0]["id"], comment_id) + def test_question_invalid_endorsed(self): + response = self.client.get(self.url, { + "thread_id": self.thread_id, + "endorsed": "invalid-boolean" + }) + self.assert_response_correct( + response, + 400, + {"field_errors": { + "endorsed": {"developer_message": "Invalid Boolean Value."} + }} + ) + + def test_question_missing_endorsed(self): + self.register_get_user_response(self.user) + thread = self.make_minimal_cs_thread({ + "thread_type": "question", + "endorsed_responses": [make_minimal_cs_comment({"id": "endorsed_comment"})], + "non_endorsed_responses": [make_minimal_cs_comment({"id": "non_endorsed_comment"})], + "non_endorsed_resp_total": 1, + }) + self.register_get_thread_response(thread) + response = self.client.get(self.url, { + "thread_id": thread["id"] + }) + self.assert_response_correct( + response, + 400, + {"field_errors": { + "endorsed": {"developer_message": "This field is required for question threads."} + }} + ) + @httpretty.activate @disable_signal(api, 'comment_deleted')