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
8c94fdcf
Commit
8c94fdcf
authored
Jan 11, 2016
by
Ehtesham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[MA-1862] updating views tests
parent
73aceb5d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
36 deletions
+30
-36
lms/djangoapps/discussion_api/tests/test_pagination.py
+6
-19
lms/djangoapps/discussion_api/tests/test_views.py
+24
-17
No files found.
lms/djangoapps/discussion_api/tests/test_pagination.py
View file @
8c94fdcf
...
...
@@ -6,6 +6,7 @@ from unittest import TestCase
from
django.test
import
RequestFactory
from
discussion_api.pagination
import
DiscussionAPIPagination
from
discussion_api.tests.utils
import
make_paginated_api_response
class
PaginationSerializerTest
(
TestCase
):
...
...
@@ -20,47 +21,33 @@ class PaginationSerializerTest(TestCase):
actual
=
paginator
.
get_paginated_response
(
objects
)
self
.
assertEqual
(
actual
.
data
,
expected
)
def
get_expected_response
(
self
,
results
,
count
,
num_pages
,
next
,
previous
):
"""
Generates the response dictionary with passed data
"""
return
{
"pagination"
:
{
"next"
:
next
,
"previous"
:
previous
,
"count"
:
count
,
"num_pages"
:
num_pages
,
},
"results"
:
results
}
def
test_empty
(
self
):
self
.
do_case
(
[],
1
,
0
,
self
.
get_expected
_response
([],
0
,
0
,
None
,
None
)
[],
1
,
0
,
make_paginated_api
_response
([],
0
,
0
,
None
,
None
)
)
def
test_only_page
(
self
):
self
.
do_case
(
[
"foo"
],
1
,
1
,
self
.
get_expected
_response
([
"foo"
],
0
,
1
,
None
,
None
)
[
"foo"
],
1
,
1
,
make_paginated_api
_response
([
"foo"
],
0
,
1
,
None
,
None
)
)
def
test_first_of_many
(
self
):
self
.
do_case
(
[
"foo"
],
1
,
3
,
self
.
get_expected
_response
(
[
"foo"
],
1
,
3
,
make_paginated_api
_response
(
[
"foo"
],
0
,
3
,
"http://testserver/test?page=2"
,
None
)
)
def
test_last_of_many
(
self
):
self
.
do_case
(
[
"foo"
],
3
,
3
,
self
.
get_expected
_response
(
[
"foo"
],
3
,
3
,
make_paginated_api
_response
(
[
"foo"
],
0
,
3
,
None
,
"http://testserver/test?page=2"
)
)
def
test_middle_of_many
(
self
):
self
.
do_case
(
[
"foo"
],
2
,
3
,
self
.
get_expected
_response
(
[
"foo"
],
2
,
3
,
make_paginated_api
_response
(
[
"foo"
],
0
,
3
,
"http://testserver/test?page=3"
,
"http://testserver/test?page=1"
)
)
lms/djangoapps/discussion_api/tests/test_views.py
View file @
8c94fdcf
...
...
@@ -23,6 +23,7 @@ from discussion_api.tests.utils import (
CommentsServiceMockMixin
,
make_minimal_cs_comment
,
make_minimal_cs_thread
,
make_paginated_api_response
)
from
student.tests.factories
import
CourseEnrollmentFactory
,
UserFactory
from
util.testing
import
UrlResetMixin
,
PatchMediaTypeMixin
...
...
@@ -307,15 +308,18 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
}]
self
.
register_get_threads_response
(
source_threads
,
page
=
1
,
num_pages
=
2
)
response
=
self
.
client
.
get
(
self
.
url
,
{
"course_id"
:
unicode
(
self
.
course
.
id
),
"following"
:
""
})
expected_respoonse
=
make_paginated_api_response
(
expected_threads
,
0
,
2
,
"http://testserver/api/discussion/v1/threads/?course_id=x
%2
Fy
%2
Fz&page=2"
,
None
)
expected_respoonse
.
update
({
"text_search_rewrite"
:
None
})
self
.
assert_response_correct
(
response
,
200
,
{
"results"
:
expected_threads
,
"next"
:
"http://testserver/api/discussion/v1/threads/?course_id=x
%2
Fy
%2
Fz&page=2"
,
"previous"
:
None
,
"text_search_rewrite"
:
None
,
}
expected_respoonse
)
self
.
assert_last_query_params
({
"user_id"
:
[
unicode
(
self
.
user
.
id
)],
...
...
@@ -374,15 +378,18 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
def
test_text_search
(
self
):
self
.
register_get_user_response
(
self
.
user
)
self
.
register_get_threads_search_response
([],
None
)
self
.
register_get_threads_search_response
([],
None
,
num_pages
=
0
)
response
=
self
.
client
.
get
(
self
.
url
,
{
"course_id"
:
unicode
(
self
.
course
.
id
),
"text_search"
:
"test search string"
}
)
expected_response
=
make_paginated_api_response
([],
0
,
0
,
None
,
None
)
expected_response
.
update
({
"text_search_rewrite"
:
None
})
self
.
assert_response_correct
(
response
,
200
,
{
"results"
:
[],
"next"
:
None
,
"previous"
:
None
,
"text_search_rewrite"
:
None
}
expected_response
)
self
.
assert_last_query_params
({
"user_id"
:
[
unicode
(
self
.
user
.
id
)],
...
...
@@ -398,7 +405,7 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
@ddt.data
(
True
,
"true"
,
"1"
)
def
test_following_true
(
self
,
following
):
self
.
register_get_user_response
(
self
.
user
)
self
.
register_subscribed_threads_response
(
self
.
user
,
[],
page
=
1
,
num_pages
=
1
)
self
.
register_subscribed_threads_response
(
self
.
user
,
[],
page
=
1
,
num_pages
=
0
)
response
=
self
.
client
.
get
(
self
.
url
,
{
...
...
@@ -406,10 +413,13 @@ class ThreadViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"following"
:
following
,
}
)
expected_response
=
make_paginated_api_response
([],
0
,
0
,
None
,
None
)
expected_response
.
update
({
"text_search_rewrite"
:
None
})
self
.
assert_response_correct
(
response
,
200
,
{
"results"
:
[],
"next"
:
None
,
"previous"
:
None
,
"text_search_rewrite"
:
None
}
expected_response
)
self
.
assertEqual
(
urlparse
(
httpretty
.
last_request
()
.
path
)
.
path
,
...
...
@@ -933,16 +943,13 @@ class CommentViewSetListTest(DiscussionAPIViewTestMixin, ModuleStoreTestCase):
"resp_total"
:
100
,
})
response
=
self
.
client
.
get
(
self
.
url
,
{
"thread_id"
:
self
.
thread_id
})
next_link
=
"http://testserver/api/discussion/v1/comments/?page=2&thread_id={}"
.
format
(
self
.
thread_id
)
self
.
assert_response_correct
(
response
,
200
,
{
"results"
:
expected_comments
,
"next"
:
"http://testserver/api/discussion/v1/comments/?page=2&thread_id={}"
.
format
(
self
.
thread_id
),
"previous"
:
None
,
}
make_paginated_api_response
(
expected_comments
,
0
,
10
,
next_link
,
None
)
)
self
.
assert_query_params_equal
(
httpretty
.
httpretty
.
latest_requests
[
-
2
],
...
...
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