Pep8 fixes of django_comment_client code
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -12,7 +12,7 @@ class Command(BaseCommand):
|
||||
dest='remove',
|
||||
default=False,
|
||||
help='Remove the role instead of adding it'),
|
||||
)
|
||||
)
|
||||
|
||||
args = '<user|email> <role> <course_id>'
|
||||
help = 'Assign a discussion forum role to a user '
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import string
|
||||
import random
|
||||
import collections
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from django_comment_client.helpers import pluralize
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
#########################################################################################
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user