diff --git a/lms/djangoapps/django_comment_client/base/tests.py b/lms/djangoapps/django_comment_client/base/tests.py index 6c17d6c4fa..3e06402ddd 100644 --- a/lms/djangoapps/django_comment_client/base/tests.py +++ b/lms/djangoapps/django_comment_client/base/tests.py @@ -46,7 +46,6 @@ class ViewsTestCase(ModuleStoreTestCase): self.client = Client() assert_true(self.client.login(username='student', password='test')) - def test_create_thread(self, mock_request): mock_request.return_value.status_code = 200 mock_request.return_value.text = u'{"title":"Hello",\ @@ -88,7 +87,7 @@ class ViewsTestCase(ModuleStoreTestCase): 'anonymous': False, 'course_id': u'MITx/999/Robot_Super_Course', 'api_key': 'PUT_YOUR_API_KEY_HERE'}, timeout=5) assert_equal(response.status_code, 200) - + def test_flag_thread(self, mock_request): mock_request.return_value.status_code = 200 mock_request.return_value.text = u'{"title":"Hello",\ @@ -111,18 +110,18 @@ class ViewsTestCase(ModuleStoreTestCase): "endorsed":false,\ "unread_comments_count":0,\ "read":false,"comments_count":0}' - url = reverse('flag_abuse_for_thread', kwargs={'thread_id': '518d4237b023791dca00000d','course_id': self.course_id }) + url = reverse('flag_abuse_for_thread', kwargs={'thread_id': '518d4237b023791dca00000d', 'course_id': self.course_id}) response = self.client.post(url) assert_true(mock_request.called) - call_list = [(('get', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d'), {'params':{'mark_as_read': True, 'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout':5}), - (('put', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d/abuse_flag'), {'data':{'api_key': 'PUT_YOUR_API_KEY_HERE', 'user_id': '1'}, 'timeout':5}), - (('get', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d'), {'params':{'mark_as_read': True, 'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout':5})] + call_list = [(('get', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d'), {'params': {'mark_as_read': True, 'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout': 5}), + (('put', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d/abuse_flag'), {'data': {'api_key': 'PUT_YOUR_API_KEY_HERE', 'user_id': '1'}, 'timeout': 5}), + (('get', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d'), {'params': {'mark_as_read': True, 'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout': 5})] - assert_equal (call_list,mock_request.call_args_list) + assert_equal(call_list, mock_request.call_args_list) assert_equal(response.status_code, 200) - + def test_un_flag_thread(self, mock_request): mock_request.return_value.status_code = 200 mock_request.return_value.text = u'{"title":"Hello",\ @@ -145,15 +144,15 @@ class ViewsTestCase(ModuleStoreTestCase): "endorsed":false,\ "unread_comments_count":0,\ "read":false,"comments_count":0}' - url = reverse('un_flag_abuse_for_thread', kwargs={'thread_id': '518d4237b023791dca00000d','course_id': self.course_id }) + url = reverse('un_flag_abuse_for_thread', kwargs={'thread_id': '518d4237b023791dca00000d', 'course_id': self.course_id}) response = self.client.post(url) assert_true(mock_request.called) - call_list = [(('get', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d'), {'params':{'mark_as_read': True, 'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout':5}), - (('put', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d/abuse_unflag'), {'data':{'api_key': 'PUT_YOUR_API_KEY_HERE', 'user_id': '1'}, 'timeout':5}), - (('get', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d'), {'params':{'mark_as_read': True, 'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout':5})] + call_list = [(('get', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d'), {'params': {'mark_as_read': True, 'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout': 5}), + (('put', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d/abuse_unflag'), {'data': {'api_key': 'PUT_YOUR_API_KEY_HERE', 'user_id': '1'}, 'timeout': 5}), + (('get', 'http://localhost:4567/api/v1/threads/518d4237b023791dca00000d'), {'params': {'mark_as_read': True, 'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout': 5})] - assert_equal (call_list,mock_request.call_args_list) + assert_equal(call_list, mock_request.call_args_list) assert_equal(response.status_code, 200) @@ -174,16 +173,16 @@ class ViewsTestCase(ModuleStoreTestCase): "down_count":0,"point":0},\ "abuse_flaggers":[1],\ "type":"comment",\ - "endorsed":false}' - url = reverse('flag_abuse_for_comment', kwargs={'comment_id': '518d4237b023791dca00000d','course_id': self.course_id }) + "endorsed":false}' + url = reverse('flag_abuse_for_comment', kwargs={'comment_id': '518d4237b023791dca00000d', 'course_id': self.course_id}) response = self.client.post(url) assert_true(mock_request.called) - call_list = [(('get', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d'), {'params':{'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout':5}), - (('put', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d/abuse_flag'), {'data':{'api_key': 'PUT_YOUR_API_KEY_HERE', 'user_id': '1'}, 'timeout':5}), - (('get', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d'), {'params':{'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout':5})] + call_list = [(('get', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d'), {'params': {'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout': 5}), + (('put', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d/abuse_flag'), {'data': {'api_key': 'PUT_YOUR_API_KEY_HERE', 'user_id': '1'}, 'timeout': 5}), + (('get', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d'), {'params': {'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout': 5})] - assert_equal (call_list,mock_request.call_args_list) + assert_equal(call_list, mock_request.call_args_list) assert_equal(response.status_code, 200) @@ -205,14 +204,14 @@ class ViewsTestCase(ModuleStoreTestCase): "abuse_flaggers":[],\ "type":"comment",\ "endorsed":false}' - url = reverse('un_flag_abuse_for_comment', kwargs={'comment_id': '518d4237b023791dca00000d','course_id': self.course_id }) + url = reverse('un_flag_abuse_for_comment', kwargs={'comment_id': '518d4237b023791dca00000d', 'course_id': self.course_id}) response = self.client.post(url) assert_true(mock_request.called) - call_list = [(('get', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d'), {'params':{'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout':5}), - (('put', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d/abuse_unflag'), {'data':{'api_key': 'PUT_YOUR_API_KEY_HERE', 'user_id': '1'}, 'timeout':5}), - (('get', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d'), {'params':{'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout':5})] + call_list = [(('get', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d'), {'params': {'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout': 5}), + (('put', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d/abuse_unflag'), {'data': {'api_key': 'PUT_YOUR_API_KEY_HERE', 'user_id': '1'}, 'timeout': 5}), + (('get', 'http://localhost:4567/api/v1/comments/518d4237b023791dca00000d'), {'params': {'api_key': 'PUT_YOUR_API_KEY_HERE'}, 'timeout': 5})] - assert_equal (call_list,mock_request.call_args_list) + assert_equal(call_list, mock_request.call_args_list) assert_equal(response.status_code, 200) diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index 8f7ea2f06b..e8cf1cf9c5 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -19,7 +19,7 @@ from django.core.files.storage import get_storage_class from django.utils.translation import ugettext as _ from django.contrib.auth.models import User -from mitxmako.shortcuts import render_to_response, render_to_string +from mitxmako.shortcuts import render_to_string from courseware.courses import get_course_with_access, get_course_by_id from course_groups.cohorts import get_cohort_id, is_commentable_cohorted diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index a94b9a07ad..55797227ea 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -7,12 +7,11 @@ from django.http import Http404 from django.core.context_processors import csrf from django.contrib.auth.models import User -from mitxmako.shortcuts import render_to_response, render_to_string +from mitxmako.shortcuts import render_to_response from courseware.courses import get_course_with_access from course_groups.cohorts import (is_course_cohorted, get_cohort_id, is_commentable_cohorted, get_cohorted_commentables, get_course_cohorts, get_cohort_by_id) from courseware.access import has_access -from django_comment_client.models import Role from django_comment_client.permissions import cached_has_permission from django_comment_client.utils import (merge_dict, extract, strip_none, get_courseware_context) @@ -395,7 +394,7 @@ def followed_threads(request, course_id, user_id): 'discussion_data': map(utils.safe_content, threads), 'page': query_params['page'], 'num_pages': query_params['num_pages'], - }) + }) else: context = { @@ -407,7 +406,7 @@ def followed_threads(request, course_id, user_id): 'user_info': saxutils.escape(json.dumps(user_info), escapedict), 'annotated_content_info': saxutils.escape(json.dumps(annotated_content_info), escapedict), # 'content': content, - } + } return render_to_response('discussion/user_profile.html', context) except (cc.utils.CommentClientError, cc.utils.CommentClientUnknownError): diff --git a/lms/djangoapps/django_comment_client/management/commands/assign_role.py b/lms/djangoapps/django_comment_client/management/commands/assign_role.py index 655631008f..1be3bff719 100644 --- a/lms/djangoapps/django_comment_client/management/commands/assign_role.py +++ b/lms/djangoapps/django_comment_client/management/commands/assign_role.py @@ -12,7 +12,7 @@ class Command(BaseCommand): dest='remove', default=False, help='Remove the role instead of adding it'), - ) + ) args = ' ' help = 'Assign a discussion forum role to a user ' diff --git a/lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py b/lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py index e84771d615..53d76cda8f 100644 --- a/lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py +++ b/lms/djangoapps/django_comment_client/management/commands/reload_forum_users.py @@ -1,7 +1,7 @@ """ Reload forum (comment client) users from existing users. """ -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from django.contrib.auth.models import User import comment_client as cc @@ -26,4 +26,3 @@ class Command(BaseCommand): for user in uset: self.adduser(user) - diff --git a/lms/djangoapps/django_comment_client/management/commands/show_permissions.py b/lms/djangoapps/django_comment_client/management/commands/show_permissions.py index ec3167aa0c..f24f183193 100644 --- a/lms/djangoapps/django_comment_client/management/commands/show_permissions.py +++ b/lms/djangoapps/django_comment_client/management/commands/show_permissions.py @@ -1,5 +1,4 @@ from django.core.management.base import BaseCommand, CommandError -from django_comment_client.models import Permission, Role from django.contrib.auth.models import User diff --git a/lms/djangoapps/django_comment_client/models.py b/lms/djangoapps/django_comment_client/models.py index e06aed1281..71e7a81f68 100644 --- a/lms/djangoapps/django_comment_client/models.py +++ b/lms/djangoapps/django_comment_client/models.py @@ -38,7 +38,7 @@ class Role(models.Model): def inherit_permissions(self, role): # TODO the name of this method is a little bit confusing, # since it's one-off and doesn't handle inheritance later if role.course_id and role.course_id != self.course_id: - logging.warning("%s cannot inherit permissions from %s due to course_id inconsistency", \ + logging.warning("%s cannot inherit permissions from %s due to course_id inconsistency", self, role) for per in role.permissions.all(): self.add_permission(per) diff --git a/lms/djangoapps/django_comment_client/tests.py b/lms/djangoapps/django_comment_client/tests.py index a35df54cd9..a5cfce4dc7 100644 --- a/lms/djangoapps/django_comment_client/tests.py +++ b/lms/djangoapps/django_comment_client/tests.py @@ -21,9 +21,9 @@ class PermissionsTestCase(TestCase): self.student_role = Role.objects.get_or_create(name="Student", course_id=self.course_id)[0] self.student = User.objects.create(username=self.random_str(), - password="123456", email="john@yahoo.com") + password="123456", email="john@yahoo.com") self.moderator = User.objects.create(username=self.random_str(), - password="123456", email="staff@edx.org") + password="123456", email="staff@edx.org") self.moderator.is_staff = True self.moderator.save() self.student_enrollment = CourseEnrollment.objects.create(user=self.student, course_id=self.course_id) diff --git a/lms/djangoapps/django_comment_client/tests/test_helpers.py b/lms/djangoapps/django_comment_client/tests/test_helpers.py index e2c074231f..6ca9680052 100644 --- a/lms/djangoapps/django_comment_client/tests/test_helpers.py +++ b/lms/djangoapps/django_comment_client/tests/test_helpers.py @@ -1,7 +1,3 @@ -import string -import random -import collections - from django.test import TestCase from django_comment_client.helpers import pluralize diff --git a/lms/djangoapps/django_comment_client/tests/test_models.py b/lms/djangoapps/django_comment_client/tests/test_models.py index 6f90b3c4b8..0835c841e2 100644 --- a/lms/djangoapps/django_comment_client/tests/test_models.py +++ b/lms/djangoapps/django_comment_client/tests/test_models.py @@ -9,24 +9,20 @@ class RoleClassTestCase(TestCase): # because xmodel.course_module.id_to_location looks for a string to split self.course_id = "edX/toy/2012_Fall" - self.student_role = models.Role.objects.get_or_create(name="Student", \ - course_id=self.course_id)[0] + self.student_role = models.Role.objects.get_or_create(name="Student", + course_id=self.course_id)[0] self.student_role.add_permission("delete_thread") - self.student_2_role = models.Role.objects.get_or_create(name="Student", \ + self.student_2_role = models.Role.objects.get_or_create(name="Student", + course_id=self.course_id)[0] + self.TA_role = models.Role.objects.get_or_create(name="Community TA", course_id=self.course_id)[0] - self.TA_role = models.Role.objects.get_or_create(name="Community TA",\ - course_id=self.course_id)[0] self.course_id_2 = "edx/6.002x/2012_Fall" - self.TA_role_2 = models.Role.objects.get_or_create(name="Community TA",\ - course_id=self.course_id_2)[0] + self.TA_role_2 = models.Role.objects.get_or_create(name="Community TA", + course_id=self.course_id_2)[0] + class Dummy(): def render_template(): pass - d = {"data": { - "textbooks": [], - 'wiki_slug': True, - } - } def testHasPermission(self): # Whenever you add a permission to student_role, @@ -47,7 +43,6 @@ class RoleClassTestCase(TestCase): class PermissionClassTestCase(TestCase): - def setUp(self): self.permission = permissions.Permission.objects.get_or_create(name="test")[0] diff --git a/lms/djangoapps/django_comment_client/tests/test_mustache_helpers.py b/lms/djangoapps/django_comment_client/tests/test_mustache_helpers.py index d5a403ecb8..b6b0cbe188 100644 --- a/lms/djangoapps/django_comment_client/tests/test_mustache_helpers.py +++ b/lms/djangoapps/django_comment_client/tests/test_mustache_helpers.py @@ -1,19 +1,8 @@ -import string -import random -import collections - from django.test import TestCase -from mock import MagicMock -from django.test.utils import override_settings -import django.core.urlresolvers as urlresolvers - import django_comment_client.mustache_helpers as mustache_helpers -######################################################################################### - class PluralizeTest(TestCase): - def setUp(self): self.text1 = '0 goat' self.text2 = '1 goat' @@ -25,11 +14,8 @@ class PluralizeTest(TestCase): self.assertEqual(mustache_helpers.pluralize(self.content, self.text2), 'goat') self.assertEqual(mustache_helpers.pluralize(self.content, self.text3), 'goats') -######################################################################################### - class CloseThreadTextTest(TestCase): - def setUp(self): self.contentClosed = {'closed': True} self.contentOpen = {'closed': False} @@ -37,5 +23,3 @@ class CloseThreadTextTest(TestCase): def test_close_thread_text(self): self.assertEqual(mustache_helpers.close_thread_text(self.contentClosed), 'Re-open thread') self.assertEqual(mustache_helpers.close_thread_text(self.contentOpen), 'Close thread') - -######################################################################################### diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index c79cc4cb89..0363607cfe 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -156,7 +156,7 @@ def initialize_discussion_info(course): # get all discussion models within this course_id all_modules = modulestore().get_items(['i4x', course.location.org, course.location.course, - 'discussion', None], course_id=course_id) + 'discussion', None], course_id=course_id) for module in all_modules: skip_module = False