Commit 4655b914 by Jonathan Piacenti

Fixed low-hanging fruit in post-rebase discussion tests and functionality.

parent 87596152
<%! from django.utils.translation import ugettext as _ %> <%! from django.utils.translation import ugettext as _ %>
<%! from django.template.defaultfilters import escapejs %> <%! from django.template.defaultfilters import escapejs %>
<%! from django_comment_client.permissions import cached_has_permission %>
<%namespace name='static' file='../static_content.html'/> <%namespace name='static' file='../static_content.html'/>
<%! <%!
...@@ -22,7 +21,7 @@ from django_comment_client.permissions import has_permission ...@@ -22,7 +21,7 @@ from django_comment_client.permissions import has_permission
</div> </div>
<div class="post-extended-content"> <div class="post-extended-content">
<div class="response-count"/> <div class="response-count"/>
% if course is UNDEFINED or cached_has_permission(user, 'create_comment', course.id): % if course is UNDEFINED or has_permission(user, 'create_comment', course.id):
<div class="add-response"> <div class="add-response">
<button class="button add-response-btn"> <button class="button add-response-btn">
<i class="icon fa fa-reply"></i> <i class="icon fa fa-reply"></i>
...@@ -35,7 +34,7 @@ from django_comment_client.permissions import has_permission ...@@ -35,7 +34,7 @@ from django_comment_client.permissions import has_permission
<div class="post-status-closed bottom-post-status" style="display: none"> <div class="post-status-closed bottom-post-status" style="display: none">
${_("This thread is closed.")} ${_("This thread is closed.")}
</div> </div>
% if course is UNDEFINED or cached_has_permission(user, 'create_comment', course.id): % if course is UNDEFINED or has_permission(user, 'create_comment', course.id):
<form class="discussion-reply-new" data-id="${'<%- id %>'}"> <form class="discussion-reply-new" data-id="${'<%- id %>'}">
<h4>${_("Post a response:")}</h4> <h4>${_("Post a response:")}</h4>
<ul class="discussion-errors"></ul> <ul class="discussion-errors"></ul>
...@@ -83,7 +82,7 @@ from django_comment_client.permissions import has_permission ...@@ -83,7 +82,7 @@ from django_comment_client.permissions import has_permission
</a> </a>
<ol class="comments"> <ol class="comments">
<li class="new-comment"> <li class="new-comment">
% if course is UNDEFINED or cached_has_permission(user, 'create_sub_comment', course.id): % if course is UNDEFINED or has_permission(user, 'create_sub_comment', course.id):
<form class="comment-form" data-id="${'<%- wmdId %>'}"> <form class="comment-form" data-id="${'<%- wmdId %>'}">
<ul class="discussion-errors"></ul> <ul class="discussion-errors"></ul>
<label class="sr" for="add-new-comment">${_("Add a comment")}</label> <label class="sr" for="add-new-comment">${_("Add a comment")}</label>
......
...@@ -296,7 +296,6 @@ def create_thread(request, course_id, commentable_id): ...@@ -296,7 +296,6 @@ def create_thread(request, course_id, commentable_id):
data = thread.to_dict() data = thread.to_dict()
add_courseware_context([data], course)
if request.is_ajax(): if request.is_ajax():
return ajax_content_response(request, course_key, data) return ajax_content_response(request, course_key, data)
else: else:
......
...@@ -1003,6 +1003,7 @@ class InlineDiscussionTestCase(ModuleStoreTestCase): ...@@ -1003,6 +1003,7 @@ class InlineDiscussionTestCase(ModuleStoreTestCase):
@patch('requests.request') @patch('requests.request')
class SingleCohortedThreadTestCase(ModuleStoreTestCase): class SingleCohortedThreadTestCase(ModuleStoreTestCase):
def setUp(self): def setUp(self):
super(SingleCohortedThreadTestCase, self).setUp()
self.course = CourseFactory.create() self.course = CourseFactory.create()
self.student = UserFactory.create() self.student = UserFactory.create()
CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id)
......
...@@ -397,7 +397,6 @@ def single_thread(request, course_key, discussion_id, thread_id): ...@@ -397,7 +397,6 @@ def single_thread(request, course_key, discussion_id, thread_id):
threads, query_params = get_threads(request, course) threads, query_params = get_threads(request, course)
except ValueError: except ValueError:
return HttpResponseBadRequest("Invalid group_id") return HttpResponseBadRequest("Invalid group_id")
threads, query_params = get_threads(request, course_key)
threads.append(thread.to_dict()) threads.append(thread.to_dict())
with newrelic.agent.FunctionTrace(nr_transaction, "add_courseware_context"): with newrelic.agent.FunctionTrace(nr_transaction, "add_courseware_context"):
......
...@@ -238,7 +238,7 @@ class Extractor(object): ...@@ -238,7 +238,7 @@ class Extractor(object):
def _get_users(self, course_key): def _get_users(self, course_key):
""" Returns users enrolled to a course as dictionary user_id => user """ """ Returns users enrolled to a course as dictionary user_id => user """
users = CourseEnrollment.users_enrolled_in(course_key) users = CourseEnrollment.objects.users_enrolled_in(course_key)
return {user.id: user for user in users} return {user.id: user for user in users}
def _get_social_stats(self, course_key, end_date=None, thread_type=None, thread_ids=None): def _get_social_stats(self, course_key, end_date=None, thread_type=None, thread_ids=None):
......
...@@ -255,7 +255,7 @@ class ExtractorTest(TestCase): ...@@ -255,7 +255,7 @@ class ExtractorTest(TestCase):
@ddt.data(*_std_parameters_list) @ddt.data(*_std_parameters_list)
def test_extract_invokes_correct_data_extraction_methods(self, course_key, end_date, thread_type, thread_ids): def test_extract_invokes_correct_data_extraction_methods(self, course_key, end_date, thread_type, thread_ids):
""" Tests that correct underlying extractors are called with proper arguments """ """ Tests that correct underlying extractors are called with proper arguments """
with mock.patch(_target_module + '.CourseEnrollment.users_enrolled_in') as patched_users_enrolled_in, \ with mock.patch(_target_module + '.CourseEnrollment.objects.users_enrolled_in') as patched_users_enrolled_in, \
mock.patch(_target_module + ".User.all_social_stats") as patched_all_social_stats: mock.patch(_target_module + ".User.all_social_stats") as patched_all_social_stats:
self.extractor.extract(course_key, end_date=end_date, thread_type=thread_type, thread_ids=thread_ids) self.extractor.extract(course_key, end_date=end_date, thread_type=thread_type, thread_ids=thread_ids)
patched_users_enrolled_in.return_value = [] patched_users_enrolled_in.return_value = []
...@@ -306,7 +306,7 @@ class ExtractorTest(TestCase): ...@@ -306,7 +306,7 @@ class ExtractorTest(TestCase):
) )
def test_extract_correctly_merges_data(self, user_data, social_stats, expected_result): def test_extract_correctly_merges_data(self, user_data, social_stats, expected_result):
""" Tests that extracted data is merged correctly """ """ Tests that extracted data is merged correctly """
with mock.patch(_target_module + '.CourseEnrollment.users_enrolled_in') as patched_users_enrolled_in, \ with mock.patch(_target_module + '.CourseEnrollment.objects.users_enrolled_in') as patched_users_enrolled_in, \
mock.patch(_target_module + ".User.all_social_stats") as patched_all_social_stats: mock.patch(_target_module + ".User.all_social_stats") as patched_all_social_stats:
patched_users_enrolled_in.return_value = user_data patched_users_enrolled_in.return_value = user_data
patched_all_social_stats.return_value = social_stats patched_all_social_stats.return_value = social_stats
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import json import json
import datetime
import mock import mock
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
import ddt import ddt
...@@ -722,7 +723,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase): ...@@ -722,7 +723,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase):
) )
def test_ids_empty(self): def test_ids_empty(self):
self.assertEqual(utils.get_discussion_categories_ids(self.course), []) self.assertEqual(utils.get_discussion_categories_ids(self.course, self.user), [])
def test_ids_configured_topics(self): def test_ids_configured_topics(self):
self.course.discussion_topics = { self.course.discussion_topics = {
...@@ -731,7 +732,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase): ...@@ -731,7 +732,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase):
"Topic C": {"id": "Topic_C"} "Topic C": {"id": "Topic_C"}
} }
self.assertItemsEqual( self.assertItemsEqual(
utils.get_discussion_categories_ids(self.course), utils.get_discussion_categories_ids(self.course, self.user),
["Topic_A", "Topic_B", "Topic_C"] ["Topic_A", "Topic_B", "Topic_C"]
) )
...@@ -743,7 +744,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase): ...@@ -743,7 +744,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase):
self.create_discussion("Chapter 2 / Section 1 / Subsection 2", "Discussion") self.create_discussion("Chapter 2 / Section 1 / Subsection 2", "Discussion")
self.create_discussion("Chapter 3 / Section 1", "Discussion") self.create_discussion("Chapter 3 / Section 1", "Discussion")
self.assertItemsEqual( self.assertItemsEqual(
utils.get_discussion_categories_ids(self.course), utils.get_discussion_categories_ids(self.course, self.user),
["discussion1", "discussion2", "discussion3", "discussion4", "discussion5", "discussion6"] ["discussion1", "discussion2", "discussion3", "discussion4", "discussion5", "discussion6"]
) )
...@@ -757,7 +758,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase): ...@@ -757,7 +758,7 @@ class CategoryMapTestCase(CategoryMapTestMixin, ModuleStoreTestCase):
self.create_discussion("Chapter 2", "Discussion") self.create_discussion("Chapter 2", "Discussion")
self.create_discussion("Chapter 2 / Section 1 / Subsection 1", "Discussion") self.create_discussion("Chapter 2 / Section 1 / Subsection 1", "Discussion")
self.assertItemsEqual( self.assertItemsEqual(
utils.get_discussion_categories_ids(self.course), utils.get_discussion_categories_ids(self.course, self.user),
["Topic_A", "Topic_B", "Topic_C", "discussion1", "discussion2", "discussion3"] ["Topic_A", "Topic_B", "Topic_C", "discussion1", "discussion2", "discussion3"]
) )
......
...@@ -33,14 +33,6 @@ class CohortedContentTestCase(ModuleStoreTestCase): ...@@ -33,14 +33,6 @@ class CohortedContentTestCase(ModuleStoreTestCase):
"cohorted_discussions": ["cohorted_topic"] "cohorted_discussions": ["cohorted_topic"]
} }
) )
self.student_cohort = CohortFactory.create(
name="student_cohort",
course_id=self.course.id
)
self.moderator_cohort = CohortFactory.create(
name="moderator_cohort",
course_id=self.course.id
)
self.course.discussion_topics["cohorted topic"] = {"id": "cohorted_topic"} self.course.discussion_topics["cohorted topic"] = {"id": "cohorted_topic"}
self.course.discussion_topics["non-cohorted topic"] = {"id": "non_cohorted_topic"} self.course.discussion_topics["non-cohorted topic"] = {"id": "non_cohorted_topic"}
self.store.update_item(self.course, self.user.id) self.store.update_item(self.course, self.user.id)
......
...@@ -452,6 +452,7 @@ def add_courseware_context(content_list, course, user, id_map=None): ...@@ -452,6 +452,7 @@ def add_courseware_context(content_list, course, user, id_map=None):
id_map = get_discussion_id_map(course, user) id_map = get_discussion_id_map(course, user)
for content in content_list: for content in content_list:
print content
commentable_id = content['commentable_id'] commentable_id = content['commentable_id']
if commentable_id in id_map: if commentable_id in id_map:
location = id_map[commentable_id]["location"].to_deprecated_string() location = id_map[commentable_id]["location"].to_deprecated_string()
......
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