-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2504 from edx/gprice/forum-pagination-acceptance
Add acceptance tests for forum response pagination
- Loading branch information
Showing
23 changed files
with
264 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
""" | ||
Stub implementation of cs_comments_service for acceptance tests | ||
""" | ||
|
||
from datetime import datetime | ||
import re | ||
import urlparse | ||
from .http import StubHttpRequestHandler, StubHttpService | ||
|
||
|
||
class StubCommentsServiceHandler(StubHttpRequestHandler): | ||
def do_GET(self): | ||
pattern_handlers = { | ||
"/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, | ||
} | ||
path = urlparse.urlparse(self.path).path | ||
for pattern in pattern_handlers: | ||
match = re.match(pattern, path) | ||
if match: | ||
pattern_handlers[pattern](**match.groupdict()) | ||
return | ||
|
||
self.send_response(404, content="404 Not Found") | ||
|
||
def do_PUT(self): | ||
self.send_response(204, "") | ||
|
||
def do_user(self, user_id): | ||
self.send_json_response({ | ||
"id": user_id, | ||
"upvoted_ids": [], | ||
"downvoted_ids": [], | ||
"subscribed_thread_ids": [], | ||
}) | ||
|
||
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) | ||
|
||
def do_threads(self): | ||
self.send_json_response({"collection": [], "page": 1, "num_pages": 1}) | ||
|
||
|
||
class StubCommentsService(StubHttpService): | ||
HANDLER_CLASS = StubCommentsServiceHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
common/test/acceptance/pages/lms/discussion_single_thread.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from bok_choy.page_object import unguarded | ||
from bok_choy.promise import EmptyPromise, fulfill | ||
|
||
from .course_page import CoursePage | ||
|
||
|
||
class DiscussionSingleThreadPage(CoursePage): | ||
def __init__(self, browser, course_id, thread_id): | ||
super(DiscussionSingleThreadPage, self).__init__(browser, course_id) | ||
self.thread_id = thread_id | ||
|
||
def is_browser_on_page(self): | ||
return self.is_css_present( | ||
"body.discussion .discussion-article[data-id='{thread_id}']".format(thread_id=self.thread_id) | ||
) | ||
|
||
@property | ||
@unguarded | ||
def url_path(self): | ||
return "discussion/forum/dummy/threads/" + self.thread_id | ||
|
||
def _get_element_text(self, selector): | ||
""" | ||
Returns the text of the first element matching the given selector, or | ||
None if no such element exists | ||
""" | ||
text_list = self.css_text(selector) | ||
return text_list[0] if text_list else None | ||
|
||
def get_response_total_text(self): | ||
"""Returns the response count text, or None if not present""" | ||
return self._get_element_text(".response-count") | ||
|
||
def get_num_displayed_responses(self): | ||
"""Returns the number of responses actually rendered""" | ||
return self.css_count(".discussion-response") | ||
|
||
def get_shown_responses_text(self): | ||
"""Returns the shown response count text, or None if not present""" | ||
return self._get_element_text(".response-display-count") | ||
|
||
def get_load_responses_button_text(self): | ||
"""Returns the load more responses button text, or None if not present""" | ||
return self._get_element_text(".load-response-button") | ||
|
||
def load_more_responses(self): | ||
"""Clicks the laod more responses button and waits for responses to load""" | ||
self.css_click(".load-response-button") | ||
fulfill(EmptyPromise( | ||
lambda: not self.is_css_present(".loading"), | ||
"Loading more responses completed" | ||
)) | ||
|
||
def has_add_response_button(self): | ||
"""Returns true if the add response button is visible, false otherwise""" | ||
return ( | ||
self.is_css_present(".add-response-btn") and | ||
self.css_map(".add-response-btn", lambda el: el.visible)[0] | ||
) | ||
|
||
def click_add_response_button(self): | ||
""" | ||
Clicks the add response button and ensures that the response text | ||
field receives focus | ||
""" | ||
self.css_click(".add-response-btn") | ||
fulfill(EmptyPromise( | ||
lambda: self.is_css_present("#wmd-input-reply-body-{thread_id}:focus".format(thread_id=self.thread_id)), | ||
"Response field received focus" | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.