Commit 08471834 by wajeeha-khalid

MA-1046 added valid form field test

parent edd4781d
...@@ -100,14 +100,20 @@ class ThreadListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase): ...@@ -100,14 +100,20 @@ class ThreadListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase):
self.form_data.setlist("topic_id", ["", "not empty"]) self.form_data.setlist("topic_id", ["", "not empty"])
self.assert_error("topic_id", "This field cannot be empty.") self.assert_error("topic_id", "This field cannot be empty.")
def test_following_true(self): @ddt.data("True", "true", 1, True)
self.form_data["following"] = "True" def test_following_true(self, value):
self.form_data["following"] = value
self.assert_field_value("following", True) self.assert_field_value("following", True)
def test_following_false(self): @ddt.data("False", "false", 0, False)
self.form_data["following"] = "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.") 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)) @ddt.data(*itertools.combinations(["topic_id", "text_search", "following"], 2))
def test_mutually_exclusive(self, params): def test_mutually_exclusive(self, params):
self.form_data.update({param: "True" for param in params}) self.form_data.update({param: "True" for param in params})
...@@ -134,7 +140,22 @@ class ThreadListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase): ...@@ -134,7 +140,22 @@ class ThreadListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase):
"Select a valid choice. not_a_valid_choice is not one of the available choices." "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): class CommentListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase):
"""Tests for CommentListGetForm""" """Tests for CommentListGetForm"""
FORM_CLASS = CommentListGetForm FORM_CLASS = CommentListGetForm
...@@ -167,3 +188,17 @@ class CommentListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase): ...@@ -167,3 +188,17 @@ class CommentListGetFormTest(FormTestMixin, PaginationTestMixin, TestCase):
def test_missing_endorsed(self): def test_missing_endorsed(self):
self.form_data.pop("endorsed") self.form_data.pop("endorsed")
self.assert_field_value("endorsed", None) 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.")
...@@ -1014,6 +1014,39 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase): ...@@ -1014,6 +1014,39 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
parsed_content = json.loads(response.content) parsed_content = json.loads(response.content)
self.assertEqual(parsed_content["results"][0]["id"], comment_id) 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 @httpretty.activate
@disable_signal(api, 'comment_deleted') @disable_signal(api, 'comment_deleted')
......
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