Add acceptance tests for forums comment deletion.
JIRA: FOR-472
This commit is contained in:
@@ -57,6 +57,8 @@ from collections import namedtuple
|
||||
from courseware.courses import get_courses, sort_by_announcement
|
||||
from courseware.access import has_access
|
||||
|
||||
from django_comment_common.models import Role
|
||||
|
||||
from external_auth.models import ExternalAuthMap
|
||||
import external_auth.views
|
||||
|
||||
@@ -1211,6 +1213,7 @@ def auto_auth(request):
|
||||
* `full_name` for the user profile (the user's full name; defaults to the username)
|
||||
* `staff`: Set to "true" to make the user global staff.
|
||||
* `course_id`: Enroll the student in the course with `course_id`
|
||||
* `roles`: Comma-separated list of roles to grant the student in the course with `course_id`
|
||||
|
||||
If username, email, or password are not provided, use
|
||||
randomly generated credentials.
|
||||
@@ -1226,6 +1229,7 @@ def auto_auth(request):
|
||||
full_name = request.GET.get('full_name', username)
|
||||
is_staff = request.GET.get('staff', None)
|
||||
course_id = request.GET.get('course_id', None)
|
||||
role_names = [v.strip() for v in request.GET.get('roles', '').split(',') if v.strip()]
|
||||
|
||||
# Get or create the user object
|
||||
post_data = {
|
||||
@@ -1268,6 +1272,11 @@ def auto_auth(request):
|
||||
if course_id is not None:
|
||||
CourseEnrollment.enroll(user, course_id)
|
||||
|
||||
# Apply the roles
|
||||
for role_name in role_names:
|
||||
role = Role.objects.get(name=role_name, course_id=course_id)
|
||||
user.roles.add(role)
|
||||
|
||||
# Log in as the user
|
||||
user = authenticate(username=username, password=password)
|
||||
login(request, user)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
Stub implementation of cs_comments_service for acceptance tests
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
import re
|
||||
import urlparse
|
||||
from .http import StubHttpRequestHandler, StubHttpService
|
||||
@@ -14,6 +13,7 @@ class StubCommentsServiceHandler(StubHttpRequestHandler):
|
||||
"/api/v1/users/(?P<user_id>\\d+)$": self.do_user,
|
||||
"/api/v1/threads$": self.do_threads,
|
||||
"/api/v1/threads/(?P<thread_id>\\w+)$": self.do_thread,
|
||||
"/api/v1/comments/(?P<comment_id>\\w+)$": self.do_comment,
|
||||
}
|
||||
path = urlparse.urlparse(self.path).path
|
||||
for pattern in pattern_handlers:
|
||||
@@ -25,8 +25,13 @@ class StubCommentsServiceHandler(StubHttpRequestHandler):
|
||||
self.send_response(404, content="404 Not Found")
|
||||
|
||||
def do_PUT(self):
|
||||
if self.path.startswith('/set_config'):
|
||||
return StubHttpRequestHandler.do_PUT(self)
|
||||
self.send_response(204, "")
|
||||
|
||||
def do_DELETE(self):
|
||||
self.send_json_response({})
|
||||
|
||||
def do_user(self, user_id):
|
||||
self.send_json_response({
|
||||
"id": user_id,
|
||||
@@ -36,44 +41,28 @@ class StubCommentsServiceHandler(StubHttpRequestHandler):
|
||||
})
|
||||
|
||||
def do_thread(self, thread_id):
|
||||
match = re.search("(?P<num>\\d+)_responses", thread_id)
|
||||
resp_total = int(match.group("num")) if match else 0
|
||||
thread = {
|
||||
"id": thread_id,
|
||||
"commentable_id": "dummy",
|
||||
"type": "thread",
|
||||
"title": "Thread title",
|
||||
"body": "Thread body",
|
||||
"created_at": datetime.utcnow().isoformat(),
|
||||
"unread_comments_count": 0,
|
||||
"comments_count": resp_total,
|
||||
"votes": {"up_count": 0},
|
||||
"abuse_flaggers": [],
|
||||
"closed": "closed" in thread_id,
|
||||
}
|
||||
params = urlparse.parse_qs(urlparse.urlparse(self.path).query)
|
||||
if "recursive" in params and params["recursive"][0] == "True":
|
||||
thread["resp_total"] = resp_total
|
||||
thread["children"] = []
|
||||
resp_skip = int(params.get("resp_skip", ["0"])[0])
|
||||
resp_limit = int(params.get("resp_limit", ["10000"])[0])
|
||||
num_responses = min(resp_limit, resp_total - resp_skip)
|
||||
self.log_message("Generating {} children; resp_limit={} resp_total={} resp_skip={}".format(num_responses, resp_limit, resp_total, resp_skip))
|
||||
for i in range(num_responses):
|
||||
response_id = str(resp_skip + i)
|
||||
thread["children"].append({
|
||||
"id": str(response_id),
|
||||
"type": "comment",
|
||||
"body": response_id,
|
||||
"created_at": datetime.utcnow().isoformat(),
|
||||
"votes": {"up_count": 0},
|
||||
"abuse_flaggers": [],
|
||||
})
|
||||
self.send_json_response(thread)
|
||||
if thread_id in self.server.config.get('threads', {}):
|
||||
thread = self.server.config['threads'][thread_id].copy()
|
||||
params = urlparse.parse_qs(urlparse.urlparse(self.path).query)
|
||||
if "recursive" in params and params["recursive"][0] == "True":
|
||||
thread.setdefault('children', [])
|
||||
resp_total = thread.setdefault('resp_total', len(thread['children']))
|
||||
resp_skip = int(params.get("resp_skip", ["0"])[0])
|
||||
resp_limit = int(params.get("resp_limit", ["10000"])[0])
|
||||
thread['children'] = thread['children'][resp_skip:(resp_skip + resp_limit)]
|
||||
self.send_json_response(thread)
|
||||
else:
|
||||
self.send_response(404, content="404 Not Found")
|
||||
|
||||
def do_threads(self):
|
||||
self.send_json_response({"collection": [], "page": 1, "num_pages": 1})
|
||||
|
||||
def do_comment(self, comment_id):
|
||||
# django_comment_client calls GET comment before doing a DELETE, so that's what this is here to support.
|
||||
if comment_id in self.server.config.get('comments', {}):
|
||||
comment = self.server.config['comments'][comment_id]
|
||||
self.send_json_response(comment)
|
||||
|
||||
|
||||
class StubCommentsService(StubHttpService):
|
||||
HANDLER_CLASS = StubCommentsServiceHandler
|
||||
|
||||
Reference in New Issue
Block a user