Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
73aceb5d
Commit
73aceb5d
authored
Jan 11, 2016
by
Ehtesham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[MA-1862] updating api tests
parent
e9622f0d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
83 deletions
+107
-83
lms/djangoapps/discussion_api/tests/test_api.py
+90
-81
lms/djangoapps/discussion_api/tests/utils.py
+17
-2
No files found.
lms/djangoapps/discussion_api/tests/test_api.py
View file @
73aceb5d
...
...
@@ -39,6 +39,7 @@ from discussion_api.tests.utils import (
CommentsServiceMockMixin
,
make_minimal_cs_comment
,
make_minimal_cs_thread
,
make_paginated_api_response
)
from
django_comment_common.models
import
(
FORUM_ROLE_ADMINISTRATOR
,
...
...
@@ -538,11 +539,15 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
def
test_empty
(
self
):
self
.
assertEqual
(
self
.
get_thread_list
([]
)
,
self
.
get_thread_list
([]
,
num_pages
=
0
)
.
data
,
{
"pagination"
:
{
"next"
:
None
,
"previous"
:
None
,
"num_pages"
:
0
,
"count"
:
0
},
"results"
:
[],
"next"
:
None
,
"previous"
:
None
,
"text_search_rewrite"
:
None
,
}
)
...
...
@@ -688,14 +693,14 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
"read"
:
False
,
},
]
expected_result
=
make_paginated_api_response
(
expected_threads
,
0
,
1
,
None
,
None
)
expected_result
.
update
({
"text_search_rewrite"
:
None
})
self
.
assertEqual
(
self
.
get_thread_list
(
source_threads
),
{
"results"
:
expected_threads
,
"next"
:
None
,
"previous"
:
None
,
"text_search_rewrite"
:
None
,
}
self
.
get_thread_list
(
source_threads
)
.
data
,
expected_result
)
@ddt.data
(
...
...
@@ -723,32 +728,29 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
def
test_pagination
(
self
):
# N.B. Empty thread list is not realistic but convenient for this test
expected_result
=
make_paginated_api_response
([],
0
,
3
,
"http://testserver/test_path?page=2"
,
None
)
expected_result
.
update
({
"text_search_rewrite"
:
None
})
self
.
assertEqual
(
self
.
get_thread_list
([],
page
=
1
,
num_pages
=
3
),
{
"results"
:
[],
"next"
:
"http://testserver/test_path?page=2"
,
"previous"
:
None
,
"text_search_rewrite"
:
None
,
}
self
.
get_thread_list
([],
page
=
1
,
num_pages
=
3
)
.
data
,
expected_result
)
expected_result
=
make_paginated_api_response
(
[],
0
,
3
,
"http://testserver/test_path?page=3"
,
"http://testserver/test_path?page=1"
)
expected_result
.
update
({
"text_search_rewrite"
:
None
})
self
.
assertEqual
(
self
.
get_thread_list
([],
page
=
2
,
num_pages
=
3
),
{
"results"
:
[],
"next"
:
"http://testserver/test_path?page=3"
,
"previous"
:
"http://testserver/test_path?page=1"
,
"text_search_rewrite"
:
None
,
}
self
.
get_thread_list
([],
page
=
2
,
num_pages
=
3
)
.
data
,
expected_result
)
expected_result
=
make_paginated_api_response
(
[],
0
,
3
,
None
,
"http://testserver/test_path?page=2"
)
expected_result
.
update
({
"text_search_rewrite"
:
None
})
self
.
assertEqual
(
self
.
get_thread_list
([],
page
=
3
,
num_pages
=
3
),
{
"results"
:
[],
"next"
:
None
,
"previous"
:
"http://testserver/test_path?page=2"
,
"text_search_rewrite"
:
None
,
}
self
.
get_thread_list
([],
page
=
3
,
num_pages
=
3
)
.
data
,
expected_result
)
# Test page past the last one
...
...
@@ -758,7 +760,11 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
@ddt.data
(
None
,
"rewritten search string"
)
def
test_text_search
(
self
,
text_search_rewrite
):
self
.
register_get_threads_search_response
([],
text_search_rewrite
)
expected_result
=
make_paginated_api_response
(
[],
0
,
0
,
None
,
None
)
expected_result
.
update
({
"text_search_rewrite"
:
text_search_rewrite
})
self
.
register_get_threads_search_response
([],
text_search_rewrite
,
num_pages
=
0
)
self
.
assertEqual
(
get_thread_list
(
self
.
request
,
...
...
@@ -766,13 +772,8 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
page
=
1
,
page_size
=
10
,
text_search
=
"test search string"
),
{
"results"
:
[],
"next"
:
None
,
"previous"
:
None
,
"text_search_rewrite"
:
text_search_rewrite
,
}
)
.
data
,
expected_result
)
self
.
assert_last_query_params
({
"user_id"
:
[
unicode
(
self
.
user
.
id
)],
...
...
@@ -786,17 +787,20 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
})
def
test_following
(
self
):
self
.
register_subscribed_threads_response
(
self
.
user
,
[],
page
=
1
,
num_pages
=
1
)
self
.
register_subscribed_threads_response
(
self
.
user
,
[],
page
=
1
,
num_pages
=
0
)
result
=
get_thread_list
(
self
.
request
,
self
.
course
.
id
,
page
=
1
,
page_size
=
11
,
following
=
True
,
)
)
.
data
expected_result
=
make_paginated_api_response
([],
0
,
0
,
None
,
None
)
expected_result
.
update
({
"text_search_rewrite"
:
None
})
self
.
assertEqual
(
result
,
{
"results"
:
[],
"next"
:
None
,
"previous"
:
None
,
"text_search_rewrite"
:
None
}
expected_result
)
self
.
assertEqual
(
urlparse
(
httpretty
.
last_request
()
.
path
)
.
path
,
...
...
@@ -813,17 +817,22 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
@ddt.data
(
"unanswered"
,
"unread"
)
def
test_view_query
(
self
,
query
):
self
.
register_get_threads_response
([],
page
=
1
,
num_pages
=
1
)
self
.
register_get_threads_response
([],
page
=
1
,
num_pages
=
0
)
result
=
get_thread_list
(
self
.
request
,
self
.
course
.
id
,
page
=
1
,
page_size
=
11
,
view
=
query
,
)
.
data
expected_result
=
make_paginated_api_response
(
[],
0
,
0
,
None
,
None
)
expected_result
.
update
({
"text_search_rewrite"
:
None
})
self
.
assertEqual
(
result
,
{
"results"
:
[],
"next"
:
None
,
"previous"
:
None
,
"text_search_rewrite"
:
None
}
expected_result
)
self
.
assertEqual
(
urlparse
(
httpretty
.
last_request
()
.
path
)
.
path
,
...
...
@@ -854,18 +863,18 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
http_query (str): Query string sent in the http request
cc_query (str): Query string used for the comments client service
"""
self
.
register_get_threads_response
([],
page
=
1
,
num_pages
=
1
)
self
.
register_get_threads_response
([],
page
=
1
,
num_pages
=
0
)
result
=
get_thread_list
(
self
.
request
,
self
.
course
.
id
,
page
=
1
,
page_size
=
11
,
order_by
=
http_query
,
)
self
.
assertEqual
(
result
,
{
"results"
:
[],
"next"
:
None
,
"previous"
:
None
,
"text_search_rewrite"
:
None
}
)
)
.
data
expected_result
=
make_paginated_api_response
([],
0
,
0
,
None
,
None
)
expected_result
.
update
({
"text_search_rewrite"
:
None
})
self
.
assertEqual
(
result
,
expected_result
)
self
.
assertEqual
(
urlparse
(
httpretty
.
last_request
()
.
path
)
.
path
,
"/api/v1/threads"
...
...
@@ -882,18 +891,18 @@ class GetThreadListTest(CommentsServiceMockMixin, UrlResetMixin, SharedModuleSto
@ddt.data
(
"asc"
,
"desc"
)
def
test_order_direction_query
(
self
,
http_query
):
self
.
register_get_threads_response
([],
page
=
1
,
num_pages
=
1
)
self
.
register_get_threads_response
([],
page
=
1
,
num_pages
=
0
)
result
=
get_thread_list
(
self
.
request
,
self
.
course
.
id
,
page
=
1
,
page_size
=
11
,
order_direction
=
http_query
,
)
self
.
assertEqual
(
result
,
{
"results"
:
[],
"next"
:
None
,
"previous"
:
None
,
"text_search_rewrite"
:
None
}
)
)
.
data
expected_result
=
make_paginated_api_response
([],
0
,
0
,
None
,
None
)
expected_result
.
update
({
"text_search_rewrite"
:
None
})
self
.
assertEqual
(
result
,
expected_result
)
self
.
assertEqual
(
urlparse
(
httpretty
.
last_request
()
.
path
)
.
path
,
"/api/v1/threads"
...
...
@@ -1055,8 +1064,8 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
{
"thread_type"
:
"discussion"
,
"children"
:
[],
"resp_total"
:
0
}
)
self
.
assertEqual
(
self
.
get_comment_list
(
discussion_thread
),
{
"results"
:
[],
"next"
:
None
,
"previous"
:
None
}
self
.
get_comment_list
(
discussion_thread
)
.
data
,
make_paginated_api_response
([],
0
,
1
,
None
,
None
)
)
question_thread
=
self
.
make_minimal_cs_thread
({
...
...
@@ -1066,12 +1075,12 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
"non_endorsed_resp_total"
:
0
})
self
.
assertEqual
(
self
.
get_comment_list
(
question_thread
,
endorsed
=
False
),
{
"results"
:
[],
"next"
:
None
,
"previous"
:
None
}
self
.
get_comment_list
(
question_thread
,
endorsed
=
False
)
.
data
,
make_paginated_api_response
([],
0
,
1
,
None
,
None
)
)
self
.
assertEqual
(
self
.
get_comment_list
(
question_thread
,
endorsed
=
True
),
{
"results"
:
[],
"next"
:
None
,
"previous"
:
None
}
self
.
get_comment_list
(
question_thread
,
endorsed
=
True
)
.
data
,
make_paginated_api_response
([],
0
,
1
,
None
,
None
)
)
def
test_basic_query_params
(
self
):
...
...
@@ -1173,7 +1182,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
]
actual_comments
=
self
.
get_comment_list
(
self
.
make_minimal_cs_thread
({
"children"
:
source_comments
})
)[
"results"
]
)
.
data
[
"results"
]
self
.
assertEqual
(
actual_comments
,
expected_comments
)
def
test_question_content
(
self
):
...
...
@@ -1184,10 +1193,10 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
"non_endorsed_resp_total"
:
1
,
})
endorsed_actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
True
)
endorsed_actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
True
)
.
data
self
.
assertEqual
(
endorsed_actual
[
"results"
][
0
][
"id"
],
"endorsed_comment"
)
non_endorsed_actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
False
)
non_endorsed_actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
False
)
.
data
self
.
assertEqual
(
non_endorsed_actual
[
"results"
][
0
][
"id"
],
"non_endorsed_comment"
)
def
test_endorsed_by_anonymity
(
self
):
...
...
@@ -1203,7 +1212,7 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
})
]
})
actual_comments
=
self
.
get_comment_list
(
thread
)[
"results"
]
actual_comments
=
self
.
get_comment_list
(
thread
)
.
data
[
"results"
]
self
.
assertIsNone
(
actual_comments
[
0
][
"endorsed_by"
])
@ddt.data
(
...
...
@@ -1231,24 +1240,24 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
})
# Only page
actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
endorsed_arg
,
page
=
1
,
page_size
=
5
)
self
.
assertIsNone
(
actual
[
"next"
])
self
.
assertIsNone
(
actual
[
"previous"
])
actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
endorsed_arg
,
page
=
1
,
page_size
=
5
)
.
data
self
.
assertIsNone
(
actual
[
"
pagination"
][
"
next"
])
self
.
assertIsNone
(
actual
[
"p
agination"
][
"p
revious"
])
# First page of many
actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
endorsed_arg
,
page
=
1
,
page_size
=
2
)
self
.
assertEqual
(
actual
[
"next"
],
"http://testserver/test_path?page=2"
)
self
.
assertIsNone
(
actual
[
"previous"
])
actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
endorsed_arg
,
page
=
1
,
page_size
=
2
)
.
data
self
.
assertEqual
(
actual
[
"
pagination"
][
"
next"
],
"http://testserver/test_path?page=2"
)
self
.
assertIsNone
(
actual
[
"p
agination"
][
"p
revious"
])
# Middle page of many
actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
endorsed_arg
,
page
=
2
,
page_size
=
2
)
self
.
assertEqual
(
actual
[
"next"
],
"http://testserver/test_path?page=3"
)
self
.
assertEqual
(
actual
[
"previous"
],
"http://testserver/test_path?page=1"
)
actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
endorsed_arg
,
page
=
2
,
page_size
=
2
)
.
data
self
.
assertEqual
(
actual
[
"
pagination"
][
"
next"
],
"http://testserver/test_path?page=3"
)
self
.
assertEqual
(
actual
[
"p
agination"
][
"p
revious"
],
"http://testserver/test_path?page=1"
)
# Last page of many
actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
endorsed_arg
,
page
=
3
,
page_size
=
2
)
self
.
assertIsNone
(
actual
[
"next"
])
self
.
assertEqual
(
actual
[
"previous"
],
"http://testserver/test_path?page=2"
)
actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
endorsed_arg
,
page
=
3
,
page_size
=
2
)
.
data
self
.
assertIsNone
(
actual
[
"
pagination"
][
"
next"
])
self
.
assertEqual
(
actual
[
"p
agination"
][
"p
revious"
],
"http://testserver/test_path?page=2"
)
# Page past the end
thread
=
self
.
make_minimal_cs_thread
({
...
...
@@ -1272,18 +1281,18 @@ class GetCommentListTest(CommentsServiceMockMixin, SharedModuleStoreTestCase):
Check that requesting the given page/page_size returns the expected
output
"""
actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
True
,
page
=
page
,
page_size
=
page_size
)
actual
=
self
.
get_comment_list
(
thread
,
endorsed
=
True
,
page
=
page
,
page_size
=
page_size
)
.
data
result_ids
=
[
result
[
"id"
]
for
result
in
actual
[
"results"
]]
self
.
assertEqual
(
result_ids
,
[
"comment_{}"
.
format
(
i
)
for
i
in
range
(
expected_start
,
expected_stop
)]
)
self
.
assertEqual
(
actual
[
"next"
],
actual
[
"
pagination"
][
"
next"
],
"http://testserver/test_path?page={}"
.
format
(
expected_next
)
if
expected_next
else
None
)
self
.
assertEqual
(
actual
[
"previous"
],
actual
[
"p
agination"
][
"p
revious"
],
"http://testserver/test_path?page={}"
.
format
(
expected_prev
)
if
expected_prev
else
None
)
...
...
lms/djangoapps/discussion_api/tests/utils.py
View file @
73aceb5d
...
...
@@ -71,7 +71,7 @@ class CommentsServiceMockMixin(object):
status
=
200
)
def
register_get_threads_search_response
(
self
,
threads
,
rewrite
):
def
register_get_threads_search_response
(
self
,
threads
,
rewrite
,
num_pages
=
1
):
"""Register a mock response for GET on the CS thread search endpoint"""
httpretty
.
register_uri
(
httpretty
.
GET
,
...
...
@@ -79,7 +79,7 @@ class CommentsServiceMockMixin(object):
body
=
json
.
dumps
({
"collection"
:
threads
,
"page"
:
1
,
"num_pages"
:
1
,
"num_pages"
:
num_pages
,
"corrected_text"
:
rewrite
,
}),
status
=
200
...
...
@@ -371,3 +371,18 @@ def make_minimal_cs_comment(overrides=None):
}
ret
.
update
(
overrides
or
{})
return
ret
def
make_paginated_api_response
(
results
,
count
,
num_pages
,
next
,
previous
):
"""
Generates the response dictionary of paginated APIs with passed data
"""
return
{
"pagination"
:
{
"next"
:
next
,
"previous"
:
previous
,
"count"
:
count
,
"num_pages"
:
num_pages
,
},
"results"
:
results
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment