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
ec1b056d
Commit
ec1b056d
authored
Mar 26, 2014
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use requests library utility method for getting json results
parent
cb93b665
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
164 additions
and
125 deletions
+164
-125
lms/djangoapps/django_comment_client/base/tests.py
+157
-110
lms/djangoapps/django_comment_client/forum/tests.py
+6
-14
lms/lib/comment_client/utils.py
+1
-1
No files found.
lms/djangoapps/django_comment_client/base/tests.py
View file @
ec1b056d
...
@@ -23,9 +23,16 @@ log = logging.getLogger(__name__)
...
@@ -23,9 +23,16 @@ log = logging.getLogger(__name__)
CS_PREFIX
=
"http://localhost:4567/api/v1"
CS_PREFIX
=
"http://localhost:4567/api/v1"
class
MockRequestSetupMixin
(
object
):
def
_set_mock_request_data
(
self
,
mock_request
,
data
):
mock_request
.
return_value
.
text
=
json
.
dumps
(
data
)
mock_request
.
return_value
.
json
.
return_value
=
data
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
class
ViewsTestCase
(
UrlResetMixin
,
ModuleStoreTestCase
):
class
ViewsTestCase
(
UrlResetMixin
,
ModuleStoreTestCase
,
MockRequestSetupMixin
):
@patch.dict
(
"django.conf.settings.FEATURES"
,
{
"ENABLE_DISCUSSION_SERVICE"
:
True
})
@patch.dict
(
"django.conf.settings.FEATURES"
,
{
"ENABLE_DISCUSSION_SERVICE"
:
True
})
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -63,26 +70,35 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -63,26 +70,35 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
def
test_create_thread
(
self
,
mock_request
):
def
test_create_thread
(
self
,
mock_request
):
mock_request
.
return_value
.
status_code
=
200
mock_request
.
return_value
.
status_code
=
200
mock_request
.
return_value
.
text
=
u'{"title":"Hello",
\
self
.
_set_mock_request_data
(
mock_request
,
{
"body":"this is a post",
\
"title"
:
"Hello"
,
"course_id":"MITx/999/Robot_Super_Course",
\
"body"
:
"this is a post"
,
"anonymous":false,
\
"course_id"
:
"MITx/999/Robot_Super_Course"
,
"anonymous_to_peers":false,
\
"anonymous"
:
False
,
"commentable_id":"i4x-MITx-999-course-Robot_Super_Course",
\
"anonymous_to_peers"
:
False
,
"created_at":"2013-05-10T18:53:43Z",
\
"commentable_id"
:
"i4x-MITx-999-course-Robot_Super_Course"
,
"updated_at":"2013-05-10T18:53:43Z",
\
"created_at"
:
"2013-05-10T18:53:43Z"
,
"at_position_list":[],
\
"updated_at"
:
"2013-05-10T18:53:43Z"
,
"closed":false,
\
"at_position_list"
:
[],
"id":"518d4237b023791dca00000d",
\
"closed"
:
False
,
"user_id":"1","username":"robot",
\
"id"
:
"518d4237b023791dca00000d"
,
"votes":{"count":0,"up_count":0,
\
"user_id"
:
"1"
,
"down_count":0,"point":0},
\
"username"
:
"robot"
,
"abuse_flaggers":[],
\
"votes"
:
{
"type":"thread","group_id":null,
\
"count"
:
0
,
"pinned":false,
\
"up_count"
:
0
,
"endorsed":false,
\
"down_count"
:
0
,
"unread_comments_count":0,
\
"point"
:
0
"read":false,"comments_count":0}'
},
"abuse_flaggers"
:
[],
"type"
:
"thread"
,
"group_id"
:
None
,
"pinned"
:
False
,
"endorsed"
:
False
,
"unread_comments_count"
:
0
,
"read"
:
False
,
"comments_count"
:
0
,
})
thread
=
{
"body"
:
[
"this is a post"
],
thread
=
{
"body"
:
[
"this is a post"
],
"anonymous_to_peers"
:
[
"false"
],
"anonymous_to_peers"
:
[
"false"
],
"auto_subscribe"
:
[
"false"
],
"auto_subscribe"
:
[
"false"
],
...
@@ -110,7 +126,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -110,7 +126,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
assert_equal
(
response
.
status_code
,
200
)
assert_equal
(
response
.
status_code
,
200
)
def
test_delete_comment
(
self
,
mock_request
):
def
test_delete_comment
(
self
,
mock_request
):
mock_request
.
return_value
.
text
=
json
.
dumps
(
{
self
.
_set_mock_request_data
(
mock_request
,
{
"user_id"
:
str
(
self
.
student
.
id
),
"user_id"
:
str
(
self
.
student
.
id
),
"closed"
:
False
,
"closed"
:
False
,
})
})
...
@@ -138,7 +154,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -138,7 +154,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
}
}
if
include_depth
:
if
include_depth
:
data
[
"depth"
]
=
0
data
[
"depth"
]
=
0
mock_request
.
return_value
.
text
=
json
.
dumps
(
data
)
self
.
_set_mock_request_data
(
mock_request
,
data
)
def
_test_request_error
(
self
,
view_name
,
view_kwargs
,
data
,
mock_request
):
def
_test_request_error
(
self
,
view_name
,
view_kwargs
,
data
,
mock_request
):
"""
"""
...
@@ -290,26 +306,34 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -290,26 +306,34 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
def
test_flag_thread
(
self
,
mock_request
):
def
test_flag_thread
(
self
,
mock_request
):
mock_request
.
return_value
.
status_code
=
200
mock_request
.
return_value
.
status_code
=
200
mock_request
.
return_value
.
text
=
u'{"title":"Hello",
\
self
.
_set_mock_request_data
(
mock_request
,
{
"body":"this is a post",
\
"title"
:
"Hello"
,
"course_id":"MITx/999/Robot_Super_Course",
\
"body"
:
"this is a post"
,
"anonymous":false,
\
"course_id"
:
"MITx/999/Robot_Super_Course"
,
"anonymous_to_peers":false,
\
"anonymous"
:
False
,
"commentable_id":"i4x-MITx-999-course-Robot_Super_Course",
\
"anonymous_to_peers"
:
False
,
"created_at":"2013-05-10T18:53:43Z",
\
"commentable_id"
:
"i4x-MITx-999-course-Robot_Super_Course"
,
"updated_at":"2013-05-10T18:53:43Z",
\
"created_at"
:
"2013-05-10T18:53:43Z"
,
"at_position_list":[],
\
"updated_at"
:
"2013-05-10T18:53:43Z"
,
"closed":false,
\
"at_position_list"
:
[],
"id":"518d4237b023791dca00000d",
\
"closed"
:
False
,
"user_id":"1","username":"robot",
\
"id"
:
"518d4237b023791dca00000d"
,
"votes":{"count":0,"up_count":0,
\
"user_id"
:
"1"
,
"username"
:
"robot"
,
"down_count":0,"point":0},
\
"votes"
:
{
"abuse_flaggers":[1],
\
"count"
:
0
,
"type":"thread","group_id":null,
\
"up_count"
:
0
,
"pinned":false,
\
"down_count"
:
0
,
"endorsed":false,
\
"point"
:
0
"unread_comments_count":0,
\
},
"read":false,"comments_count":0}'
"abuse_flaggers"
:
[
1
],
"type"
:
"thread"
,
"group_id"
:
None
,
"pinned"
:
False
,
"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
)
response
=
self
.
client
.
post
(
url
)
assert_true
(
mock_request
.
called
)
assert_true
(
mock_request
.
called
)
...
@@ -350,26 +374,35 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -350,26 +374,35 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
def
test_un_flag_thread
(
self
,
mock_request
):
def
test_un_flag_thread
(
self
,
mock_request
):
mock_request
.
return_value
.
status_code
=
200
mock_request
.
return_value
.
status_code
=
200
mock_request
.
return_value
.
text
=
u'{"title":"Hello",
\
self
.
_set_mock_request_data
(
mock_request
,
{
"body":"this is a post",
\
"title"
:
"Hello"
,
"course_id":"MITx/999/Robot_Super_Course",
\
"body"
:
"this is a post"
,
"anonymous":false,
\
"course_id"
:
"MITx/999/Robot_Super_Course"
,
"anonymous_to_peers":false,
\
"anonymous"
:
False
,
"commentable_id":"i4x-MITx-999-course-Robot_Super_Course",
\
"anonymous_to_peers"
:
False
,
"created_at":"2013-05-10T18:53:43Z",
\
"commentable_id"
:
"i4x-MITx-999-course-Robot_Super_Course"
,
"updated_at":"2013-05-10T18:53:43Z",
\
"created_at"
:
"2013-05-10T18:53:43Z"
,
"at_position_list":[],
\
"updated_at"
:
"2013-05-10T18:53:43Z"
,
"closed":false,
\
"at_position_list"
:
[],
"id":"518d4237b023791dca00000d",
\
"closed"
:
False
,
"user_id":"1","username":"robot",
\
"id"
:
"518d4237b023791dca00000d"
,
"votes":{"count":0,"up_count":0,
\
"user_id"
:
"1"
,
"down_count":0,"point":0},
\
"username"
:
"robot"
,
"abuse_flaggers":[],
\
"votes"
:
{
"type":"thread","group_id":null,
\
"count"
:
0
,
"pinned":false,
\
"up_count"
:
0
,
"endorsed":false,
\
"down_count"
:
0
,
"unread_comments_count":0,
\
"point"
:
0
"read":false,"comments_count":0}'
},
"abuse_flaggers"
:
[],
"type"
:
"thread"
,
"group_id"
:
None
,
"pinned"
:
False
,
"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
)
response
=
self
.
client
.
post
(
url
)
assert_true
(
mock_request
.
called
)
assert_true
(
mock_request
.
called
)
...
@@ -410,22 +443,29 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -410,22 +443,29 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
def
test_flag_comment
(
self
,
mock_request
):
def
test_flag_comment
(
self
,
mock_request
):
mock_request
.
return_value
.
status_code
=
200
mock_request
.
return_value
.
status_code
=
200
mock_request
.
return_value
.
text
=
u'{"body":"this is a comment",
\
self
.
_set_mock_request_data
(
mock_request
,
{
"course_id":"MITx/999/Robot_Super_Course",
\
"body"
:
"this is a comment"
,
"anonymous":false,
\
"course_id"
:
"MITx/999/Robot_Super_Course"
,
"anonymous_to_peers":false,
\
"anonymous"
:
False
,
"commentable_id":"i4x-MITx-999-course-Robot_Super_Course",
\
"anonymous_to_peers"
:
False
,
"created_at":"2013-05-10T18:53:43Z",
\
"commentable_id"
:
"i4x-MITx-999-course-Robot_Super_Course"
,
"updated_at":"2013-05-10T18:53:43Z",
\
"created_at"
:
"2013-05-10T18:53:43Z"
,
"at_position_list":[],
\
"updated_at"
:
"2013-05-10T18:53:43Z"
,
"closed":false,
\
"at_position_list"
:
[],
"id":"518d4237b023791dca00000d",
\
"closed"
:
False
,
"user_id":"1","username":"robot",
\
"id"
:
"518d4237b023791dca00000d"
,
"votes":{"count":0,"up_count":0,
\
"user_id"
:
"1"
,
"down_count":0,"point":0},
\
"username"
:
"robot"
,
"abuse_flaggers":[1],
\
"votes"
:
{
"type":"comment",
\
"count"
:
0
,
"endorsed":false}'
"up_count"
:
0
,
"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
})
url
=
reverse
(
'flag_abuse_for_comment'
,
kwargs
=
{
'comment_id'
:
'518d4237b023791dca00000d'
,
'course_id'
:
self
.
course_id
})
response
=
self
.
client
.
post
(
url
)
response
=
self
.
client
.
post
(
url
)
assert_true
(
mock_request
.
called
)
assert_true
(
mock_request
.
called
)
...
@@ -466,22 +506,29 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -466,22 +506,29 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
def
test_un_flag_comment
(
self
,
mock_request
):
def
test_un_flag_comment
(
self
,
mock_request
):
mock_request
.
return_value
.
status_code
=
200
mock_request
.
return_value
.
status_code
=
200
mock_request
.
return_value
.
text
=
u'{"body":"this is a comment",
\
self
.
_set_mock_request_data
(
mock_request
,
{
"course_id":"MITx/999/Robot_Super_Course",
\
"body"
:
"this is a comment"
,
"anonymous":false,
\
"course_id"
:
"MITx/999/Robot_Super_Course"
,
"anonymous_to_peers":false,
\
"anonymous"
:
False
,
"commentable_id":"i4x-MITx-999-course-Robot_Super_Course",
\
"anonymous_to_peers"
:
False
,
"created_at":"2013-05-10T18:53:43Z",
\
"commentable_id"
:
"i4x-MITx-999-course-Robot_Super_Course"
,
"updated_at":"2013-05-10T18:53:43Z",
\
"created_at"
:
"2013-05-10T18:53:43Z"
,
"at_position_list":[],
\
"updated_at"
:
"2013-05-10T18:53:43Z"
,
"closed":false,
\
"at_position_list"
:
[],
"id":"518d4237b023791dca00000d",
\
"closed"
:
False
,
"user_id":"1","username":"robot",
\
"id"
:
"518d4237b023791dca00000d"
,
"votes":{"count":0,"up_count":0,
\
"user_id"
:
"1"
,
"down_count":0,"point":0},
\
"username"
:
"robot"
,
"abuse_flaggers":[],
\
"votes"
:
{
"type":"comment",
\
"count"
:
0
,
"endorsed":false}'
"up_count"
:
0
,
"down_count"
:
0
,
"point"
:
0
},
"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
)
response
=
self
.
client
.
post
(
url
)
assert_true
(
mock_request
.
called
)
assert_true
(
mock_request
.
called
)
...
@@ -522,7 +569,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -522,7 +569,7 @@ class ViewsTestCase(UrlResetMixin, ModuleStoreTestCase):
@patch
(
"lms.lib.comment_client.utils.requests.request"
)
@patch
(
"lms.lib.comment_client.utils.requests.request"
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
class
ViewPermissionsTestCase
(
UrlResetMixin
,
ModuleStoreTestCase
):
class
ViewPermissionsTestCase
(
UrlResetMixin
,
ModuleStoreTestCase
,
MockRequestSetupMixin
):
@patch.dict
(
"django.conf.settings.FEATURES"
,
{
"ENABLE_DISCUSSION_SERVICE"
:
True
})
@patch.dict
(
"django.conf.settings.FEATURES"
,
{
"ENABLE_DISCUSSION_SERVICE"
:
True
})
def
setUp
(
self
):
def
setUp
(
self
):
super
(
ViewPermissionsTestCase
,
self
)
.
setUp
()
super
(
ViewPermissionsTestCase
,
self
)
.
setUp
()
...
@@ -536,7 +583,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -536,7 +583,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase):
self
.
moderator
.
roles
.
add
(
Role
.
objects
.
get
(
name
=
"Moderator"
,
course_id
=
self
.
course
.
id
))
self
.
moderator
.
roles
.
add
(
Role
.
objects
.
get
(
name
=
"Moderator"
,
course_id
=
self
.
course
.
id
))
def
test_pin_thread_as_student
(
self
,
mock_request
):
def
test_pin_thread_as_student
(
self
,
mock_request
):
mock_request
.
return_value
.
text
=
"{}"
self
.
_set_mock_request_data
(
mock_request
,
{})
self
.
client
.
login
(
username
=
self
.
student
.
username
,
password
=
self
.
password
)
self
.
client
.
login
(
username
=
self
.
student
.
username
,
password
=
self
.
password
)
response
=
self
.
client
.
post
(
response
=
self
.
client
.
post
(
reverse
(
"pin_thread"
,
kwargs
=
{
"course_id"
:
self
.
course
.
id
,
"thread_id"
:
"dummy"
})
reverse
(
"pin_thread"
,
kwargs
=
{
"course_id"
:
self
.
course
.
id
,
"thread_id"
:
"dummy"
})
...
@@ -544,7 +591,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -544,7 +591,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase):
self
.
assertEqual
(
response
.
status_code
,
401
)
self
.
assertEqual
(
response
.
status_code
,
401
)
def
test_pin_thread_as_moderator
(
self
,
mock_request
):
def
test_pin_thread_as_moderator
(
self
,
mock_request
):
mock_request
.
return_value
.
text
=
"{}"
self
.
_set_mock_request_data
(
mock_request
,
{})
self
.
client
.
login
(
username
=
self
.
moderator
.
username
,
password
=
self
.
password
)
self
.
client
.
login
(
username
=
self
.
moderator
.
username
,
password
=
self
.
password
)
response
=
self
.
client
.
post
(
response
=
self
.
client
.
post
(
reverse
(
"pin_thread"
,
kwargs
=
{
"course_id"
:
self
.
course
.
id
,
"thread_id"
:
"dummy"
})
reverse
(
"pin_thread"
,
kwargs
=
{
"course_id"
:
self
.
course
.
id
,
"thread_id"
:
"dummy"
})
...
@@ -552,7 +599,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -552,7 +599,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase):
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_un_pin_thread_as_student
(
self
,
mock_request
):
def
test_un_pin_thread_as_student
(
self
,
mock_request
):
mock_request
.
return_value
.
text
=
"{}"
self
.
_set_mock_request_data
(
mock_request
,
{})
self
.
client
.
login
(
username
=
self
.
student
.
username
,
password
=
self
.
password
)
self
.
client
.
login
(
username
=
self
.
student
.
username
,
password
=
self
.
password
)
response
=
self
.
client
.
post
(
response
=
self
.
client
.
post
(
reverse
(
"un_pin_thread"
,
kwargs
=
{
"course_id"
:
self
.
course
.
id
,
"thread_id"
:
"dummy"
})
reverse
(
"un_pin_thread"
,
kwargs
=
{
"course_id"
:
self
.
course
.
id
,
"thread_id"
:
"dummy"
})
...
@@ -560,7 +607,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -560,7 +607,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase):
self
.
assertEqual
(
response
.
status_code
,
401
)
self
.
assertEqual
(
response
.
status_code
,
401
)
def
test_un_pin_thread_as_moderator
(
self
,
mock_request
):
def
test_un_pin_thread_as_moderator
(
self
,
mock_request
):
mock_request
.
return_value
.
text
=
"{}"
self
.
_set_mock_request_data
(
mock_request
,
{})
self
.
client
.
login
(
username
=
self
.
moderator
.
username
,
password
=
self
.
password
)
self
.
client
.
login
(
username
=
self
.
moderator
.
username
,
password
=
self
.
password
)
response
=
self
.
client
.
post
(
response
=
self
.
client
.
post
(
reverse
(
"un_pin_thread"
,
kwargs
=
{
"course_id"
:
self
.
course
.
id
,
"thread_id"
:
"dummy"
})
reverse
(
"un_pin_thread"
,
kwargs
=
{
"course_id"
:
self
.
course
.
id
,
"thread_id"
:
"dummy"
})
...
@@ -569,7 +616,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase):
...
@@ -569,7 +616,7 @@ class ViewPermissionsTestCase(UrlResetMixin, ModuleStoreTestCase):
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
class
CreateThreadUnicodeTestCase
(
ModuleStoreTestCase
,
UnicodeTestMixin
):
class
CreateThreadUnicodeTestCase
(
ModuleStoreTestCase
,
UnicodeTestMixin
,
MockRequestSetupMixin
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
()
self
.
course
=
CourseFactory
.
create
()
seed_permissions_roles
(
self
.
course
.
id
)
seed_permissions_roles
(
self
.
course
.
id
)
...
@@ -578,7 +625,7 @@ class CreateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
...
@@ -578,7 +625,7 @@ class CreateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
def
_test_unicode_data
(
self
,
text
,
mock_request
):
def
_test_unicode_data
(
self
,
text
,
mock_request
):
mock_request
.
return_value
.
text
=
"{}"
self
.
_set_mock_request_data
(
mock_request
,
{})
request
=
RequestFactory
()
.
post
(
"dummy_url"
,
{
"body"
:
text
,
"title"
:
text
})
request
=
RequestFactory
()
.
post
(
"dummy_url"
,
{
"body"
:
text
,
"title"
:
text
})
request
.
user
=
self
.
student
request
.
user
=
self
.
student
request
.
view_name
=
"create_thread"
request
.
view_name
=
"create_thread"
...
@@ -591,7 +638,7 @@ class CreateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
...
@@ -591,7 +638,7 @@ class CreateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
class
UpdateThreadUnicodeTestCase
(
ModuleStoreTestCase
,
UnicodeTestMixin
):
class
UpdateThreadUnicodeTestCase
(
ModuleStoreTestCase
,
UnicodeTestMixin
,
MockRequestSetupMixin
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
()
self
.
course
=
CourseFactory
.
create
()
seed_permissions_roles
(
self
.
course
.
id
)
seed_permissions_roles
(
self
.
course
.
id
)
...
@@ -600,7 +647,7 @@ class UpdateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
...
@@ -600,7 +647,7 @@ class UpdateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
def
_test_unicode_data
(
self
,
text
,
mock_request
):
def
_test_unicode_data
(
self
,
text
,
mock_request
):
mock_request
.
return_value
.
text
=
json
.
dumps
(
{
self
.
_set_mock_request_data
(
mock_request
,
{
"user_id"
:
str
(
self
.
student
.
id
),
"user_id"
:
str
(
self
.
student
.
id
),
"closed"
:
False
,
"closed"
:
False
,
})
})
...
@@ -616,7 +663,7 @@ class UpdateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
...
@@ -616,7 +663,7 @@ class UpdateThreadUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
class
CreateCommentUnicodeTestCase
(
ModuleStoreTestCase
,
UnicodeTestMixin
):
class
CreateCommentUnicodeTestCase
(
ModuleStoreTestCase
,
UnicodeTestMixin
,
MockRequestSetupMixin
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
()
self
.
course
=
CourseFactory
.
create
()
seed_permissions_roles
(
self
.
course
.
id
)
seed_permissions_roles
(
self
.
course
.
id
)
...
@@ -625,7 +672,7 @@ class CreateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
...
@@ -625,7 +672,7 @@ class CreateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
def
_test_unicode_data
(
self
,
text
,
mock_request
):
def
_test_unicode_data
(
self
,
text
,
mock_request
):
mock_request
.
return_value
.
text
=
json
.
dumps
(
{
self
.
_set_mock_request_data
(
mock_request
,
{
"closed"
:
False
,
"closed"
:
False
,
})
})
request
=
RequestFactory
()
.
post
(
"dummy_url"
,
{
"body"
:
text
})
request
=
RequestFactory
()
.
post
(
"dummy_url"
,
{
"body"
:
text
})
...
@@ -639,7 +686,7 @@ class CreateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
...
@@ -639,7 +686,7 @@ class CreateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
class
UpdateCommentUnicodeTestCase
(
ModuleStoreTestCase
,
UnicodeTestMixin
):
class
UpdateCommentUnicodeTestCase
(
ModuleStoreTestCase
,
UnicodeTestMixin
,
MockRequestSetupMixin
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
()
self
.
course
=
CourseFactory
.
create
()
seed_permissions_roles
(
self
.
course
.
id
)
seed_permissions_roles
(
self
.
course
.
id
)
...
@@ -648,7 +695,7 @@ class UpdateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
...
@@ -648,7 +695,7 @@ class UpdateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
def
_test_unicode_data
(
self
,
text
,
mock_request
):
def
_test_unicode_data
(
self
,
text
,
mock_request
):
mock_request
.
return_value
.
text
=
json
.
dumps
(
{
self
.
_set_mock_request_data
(
mock_request
,
{
"user_id"
:
str
(
self
.
student
.
id
),
"user_id"
:
str
(
self
.
student
.
id
),
"closed"
:
False
,
"closed"
:
False
,
})
})
...
@@ -663,7 +710,7 @@ class UpdateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
...
@@ -663,7 +710,7 @@ class UpdateCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MIXED_MODULESTORE
)
class
CreateSubCommentUnicodeTestCase
(
ModuleStoreTestCase
,
UnicodeTestMixin
):
class
CreateSubCommentUnicodeTestCase
(
ModuleStoreTestCase
,
UnicodeTestMixin
,
MockRequestSetupMixin
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
course
=
CourseFactory
.
create
()
self
.
course
=
CourseFactory
.
create
()
seed_permissions_roles
(
self
.
course
.
id
)
seed_permissions_roles
(
self
.
course
.
id
)
...
@@ -672,7 +719,7 @@ class CreateSubCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
...
@@ -672,7 +719,7 @@ class CreateSubCommentUnicodeTestCase(ModuleStoreTestCase, UnicodeTestMixin):
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
@patch
(
'lms.lib.comment_client.utils.requests.request'
)
def
_test_unicode_data
(
self
,
text
,
mock_request
):
def
_test_unicode_data
(
self
,
text
,
mock_request
):
mock_request
.
return_value
.
text
=
json
.
dumps
(
{
self
.
_set_mock_request_data
(
mock_request
,
{
"closed"
:
False
,
"closed"
:
False
,
"depth"
:
1
,
"depth"
:
1
,
})
})
...
...
lms/djangoapps/django_comment_client/forum/tests.py
View file @
ec1b056d
...
@@ -109,26 +109,18 @@ def make_mock_request_impl(text, thread_id=None):
...
@@ -109,26 +109,18 @@ def make_mock_request_impl(text, thread_id=None):
def
mock_request_impl
(
*
args
,
**
kwargs
):
def
mock_request_impl
(
*
args
,
**
kwargs
):
url
=
args
[
1
]
url
=
args
[
1
]
if
url
.
endswith
(
"threads"
):
if
url
.
endswith
(
"threads"
):
return
Mock
(
data
=
{
status_code
=
200
,
text
=
json
.
dumps
({
"collection"
:
[
make_mock_thread_data
(
text
,
"dummy_thread_id"
,
False
)]
"collection"
:
[
make_mock_thread_data
(
text
,
"dummy_thread_id"
,
False
)]
})
}
)
elif
thread_id
and
url
.
endswith
(
thread_id
):
elif
thread_id
and
url
.
endswith
(
thread_id
):
return
Mock
(
data
=
make_mock_thread_data
(
text
,
thread_id
,
True
)
status_code
=
200
,
text
=
json
.
dumps
(
make_mock_thread_data
(
text
,
thread_id
,
True
))
)
else
:
# user query
else
:
# user query
return
Mock
(
data
=
{
status_code
=
200
,
text
=
json
.
dumps
({
"upvoted_ids"
:
[],
"upvoted_ids"
:
[],
"downvoted_ids"
:
[],
"downvoted_ids"
:
[],
"subscribed_thread_ids"
:
[],
"subscribed_thread_ids"
:
[],
})
}
)
return
Mock
(
status_code
=
200
,
text
=
json
.
dumps
(
data
),
json
=
Mock
(
return_value
=
data
)
)
return
mock_request_impl
return
mock_request_impl
...
...
lms/lib/comment_client/utils.py
View file @
ec1b056d
...
@@ -87,7 +87,7 @@ def perform_request(method, url, data_or_params=None, raw=False):
...
@@ -87,7 +87,7 @@ def perform_request(method, url, data_or_params=None, raw=False):
if
raw
:
if
raw
:
return
response
.
text
return
response
.
text
else
:
else
:
return
json
.
loads
(
response
.
text
)
return
response
.
json
(
)
class
CommentClientError
(
Exception
):
class
CommentClientError
(
Exception
):
...
...
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