Exemplo n.º 1
0
 def test_following(self):
     self.register_post_thread_response({"id": "test_id"})
     self.register_subscription_response(self.user)
     data = self.minimal_data.copy()
     data["following"] = "True"
     result = create_thread(self.request, data)
     self.assertEqual(result["following"], True)
     cs_request = httpretty.last_request()
     self.assertEqual(urlparse(cs_request.path).path, "/api/v1/users/{}/subscriptions".format(self.user.id))
     self.assertEqual(cs_request.parsed_body, {"source_type": ["thread"], "source_id": ["test_id"]})
Exemplo n.º 2
0
 def test_following(self):
     self.register_post_thread_response({"id": "test_id"})
     self.register_subscription_response(self.user)
     data = self.minimal_data.copy()
     data["following"] = "True"
     result = create_thread(self.request, data)
     self.assertEqual(result["following"], True)
     cs_request = httpretty.last_request()
     self.assertEqual(
         urlparse(cs_request.path).path,
         "/api/v1/users/{}/subscriptions".format(self.user.id)
     )
     self.assertEqual(
         cs_request.parsed_body,
         {"source_type": ["thread"], "source_id": ["test_id"]}
     )
Exemplo n.º 3
0
 def create(self, request):
     """
     Implements the POST method for the list endpoint as described in the
     class docstring.
     """
     return Response(create_thread(request, request.DATA))
Exemplo n.º 4
0
 def test_invalid_field(self):
     data = self.minimal_data.copy()
     data["type"] = "invalid_type"
     with self.assertRaises(ValidationError):
         create_thread(self.request, data)
Exemplo n.º 5
0
 def test_discussions_disabled(self):
     _remove_discussion_tab(self.course, self.user.id)
     with self.assertRaises(ValidationError) as assertion:
         create_thread(self.request, self.minimal_data)
     self.assertEqual(assertion.exception.message_dict, {"course_id": ["Invalid value."]})
Exemplo n.º 6
0
 def test_not_enrolled(self):
     self.request.user = UserFactory.create()
     with self.assertRaises(ValidationError) as assertion:
         create_thread(self.request, self.minimal_data)
     self.assertEqual(assertion.exception.message_dict, {"course_id": ["Invalid value."]})
Exemplo n.º 7
0
 def test_nonexistent_course(self):
     with self.assertRaises(ValidationError) as assertion:
         create_thread(self.request, {"course_id": "non/existent/course"})
     self.assertEqual(assertion.exception.message_dict, {"course_id": ["Invalid value."]})
Exemplo n.º 8
0
 def test_course_id_missing(self):
     with self.assertRaises(ValidationError) as assertion:
         create_thread(self.request, {})
     self.assertEqual(assertion.exception.message_dict, {"course_id": ["This field is required."]})
Exemplo n.º 9
0
 def test_basic(self, mock_emit):
     self.register_post_thread_response({
         "id": "test_id",
         "username": self.user.username,
         "created_at": "2015-05-19T00:00:00Z",
         "updated_at": "2015-05-19T00:00:00Z",
     })
     actual = create_thread(self.request, self.minimal_data)
     expected = {
         "id": "test_id",
         "course_id": unicode(self.course.id),
         "topic_id": "test_topic",
         "group_id": None,
         "group_name": None,
         "author": self.user.username,
         "author_label": None,
         "created_at": "2015-05-19T00:00:00Z",
         "updated_at": "2015-05-19T00:00:00Z",
         "type": "discussion",
         "title": "Test Title",
         "raw_body": "Test body",
         "pinned": False,
         "closed": False,
         "following": False,
         "abuse_flagged": False,
         "voted": False,
         "vote_count": 0,
         "comment_count": 0,
         "unread_comment_count": 0,
         "comment_list_url": "http://testserver/api/discussion/v1/comments/?thread_id=test_id",
         "endorsed_comment_list_url": None,
         "non_endorsed_comment_list_url": None,
     }
     self.assertEqual(actual, expected)
     self.assertEqual(
         httpretty.last_request().parsed_body,
         {
             "course_id": [unicode(self.course.id)],
             "commentable_id": ["test_topic"],
             "thread_type": ["discussion"],
             "title": ["Test Title"],
             "body": ["Test body"],
             "user_id": [str(self.user.id)],
         }
     )
     event_name, event_data = mock_emit.call_args[0]
     self.assertEqual(event_name, "edx.forum.thread.created")
     self.assertEqual(
         event_data,
         {
             "commentable_id": "test_topic",
             "group_id": None,
             "thread_type": "discussion",
             "title": "Test Title",
             "anonymous": False,
             "anonymous_to_peers": False,
             "options": {"followed": False},
             "id": "test_id",
             "truncated": False,
             "body": "Test body",
             "url": "",
             "user_forums_roles": [FORUM_ROLE_STUDENT],
             "user_course_roles": [],
         }
     )