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
16e4eacb
Commit
16e4eacb
authored
Dec 15, 2017
by
bmedx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure httpretty usage cleans up after itself
parent
b67e3e9e
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
3 deletions
+36
-3
common/djangoapps/course_modes/tests/test_views.py
+0
-1
common/djangoapps/third_party_auth/tests/specs/test_testshib.py
+3
-2
lms/djangoapps/discussion_api/tests/test_api.py
+9
-0
lms/djangoapps/discussion_api/tests/test_serializers.py
+3
-0
lms/djangoapps/discussion_api/tests/test_views.py
+1
-0
lms/djangoapps/discussion_api/tests/utils.py
+20
-0
No files found.
common/djangoapps/course_modes/tests/test_views.py
View file @
16e4eacb
...
...
@@ -484,6 +484,5 @@ class TrackSelectionEmbargoTest(UrlResetMixin, ModuleStoreTestCase):
@httpretty.activate
def
test_embargo_allow
(
self
):
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assertEqual
(
response
.
status_code
,
200
)
common/djangoapps/third_party_auth/tests/specs/test_testshib.py
View file @
16e4eacb
...
...
@@ -49,6 +49,9 @@ class SamlIntegrationTestUtilities(object):
)
# Mock out HTTP requests that may be made to TestShib:
httpretty
.
enable
()
httpretty
.
reset
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
def
metadata_callback
(
_request
,
_uri
,
headers
):
""" Return a cached copy of TestShib's metadata by reading it from disk """
...
...
@@ -66,8 +69,6 @@ class SamlIntegrationTestUtilities(object):
content_type
=
'text/xml'
,
body
=
cache_duration_metadata_callback
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
addCleanup
(
httpretty
.
reset
)
# Configure the SAML library to use the same request ID for every request.
# Doing this and freezing the time allows us to play back recorded request/response pairs
...
...
lms/djangoapps/discussion_api/tests/test_api.py
View file @
16e4eacb
...
...
@@ -581,6 +581,7 @@ class GetThreadListTest(ForumsEnableMixin, CommentsServiceMockMixin, UrlResetMix
super
(
GetThreadListTest
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
maxDiff
=
None
# pylint: disable=invalid-name
self
.
user
=
UserFactory
.
create
()
...
...
@@ -998,6 +999,7 @@ class GetCommentListTest(ForumsEnableMixin, CommentsServiceMockMixin, SharedModu
super
(
GetCommentListTest
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
maxDiff
=
None
# pylint: disable=invalid-name
self
.
user
=
UserFactory
.
create
()
...
...
@@ -1477,6 +1479,7 @@ class CreateThreadTest(
super
(
CreateThreadTest
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
user
=
UserFactory
.
create
()
self
.
register_get_user_response
(
self
.
user
)
...
...
@@ -1741,6 +1744,7 @@ class CreateCommentTest(
super
(
CreateCommentTest
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
user
=
UserFactory
.
create
()
self
.
register_get_user_response
(
self
.
user
)
...
...
@@ -2006,6 +2010,7 @@ class UpdateThreadTest(
super
(
UpdateThreadTest
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
user
=
UserFactory
.
create
()
...
...
@@ -2388,6 +2393,7 @@ class UpdateCommentTest(
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
user
=
UserFactory
.
create
()
...
...
@@ -2787,6 +2793,7 @@ class DeleteThreadTest(
super
(
DeleteThreadTest
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
user
=
UserFactory
.
create
()
self
.
register_get_user_response
(
self
.
user
)
...
...
@@ -2924,6 +2931,7 @@ class DeleteCommentTest(
super
(
DeleteCommentTest
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
user
=
UserFactory
.
create
()
self
.
register_get_user_response
(
self
.
user
)
...
...
@@ -3078,6 +3086,7 @@ class RetrieveThreadTest(
super
(
RetrieveThreadTest
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
user
=
UserFactory
.
create
()
self
.
register_get_user_response
(
self
.
user
)
...
...
lms/djangoapps/discussion_api/tests/test_serializers.py
View file @
16e4eacb
...
...
@@ -44,6 +44,7 @@ class SerializerTestMixin(ForumsEnableMixin, CommentsServiceMockMixin, UrlResetM
super
(
SerializerTestMixin
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
maxDiff
=
None
# pylint: disable=invalid-name
self
.
user
=
UserFactory
.
create
()
...
...
@@ -411,6 +412,7 @@ class ThreadSerializerDeserializationTest(
super
(
ThreadSerializerDeserializationTest
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
user
=
UserFactory
.
create
()
self
.
register_get_user_response
(
self
.
user
)
...
...
@@ -612,6 +614,7 @@ class CommentSerializerDeserializationTest(ForumsEnableMixin, CommentsServiceMoc
super
(
CommentSerializerDeserializationTest
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
user
=
UserFactory
.
create
()
self
.
register_get_user_response
(
self
.
user
)
...
...
lms/djangoapps/discussion_api/tests/test_views.py
View file @
16e4eacb
...
...
@@ -1421,6 +1421,7 @@ class CommentViewSetPartialUpdateTest(DiscussionAPIViewTestMixin, ModuleStoreTes
super
(
CommentViewSetPartialUpdateTest
,
self
)
.
setUp
()
httpretty
.
reset
()
httpretty
.
enable
()
self
.
addCleanup
(
httpretty
.
reset
)
self
.
addCleanup
(
httpretty
.
disable
)
self
.
register_get_user_response
(
self
.
user
)
self
.
url
=
reverse
(
"comment-detail"
,
kwargs
=
{
"comment_id"
:
"test_comment"
})
...
...
lms/djangoapps/discussion_api/tests/utils.py
View file @
16e4eacb
...
...
@@ -71,6 +71,8 @@ class CommentsServiceMockMixin(object):
"""Mixin with utility methods for mocking the comments service"""
def
register_get_threads_response
(
self
,
threads
,
page
,
num_pages
):
"""Register a mock response for GET on the CS thread list endpoint"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
GET
,
"http://localhost:4567/api/v1/threads"
,
...
...
@@ -85,6 +87,7 @@ class CommentsServiceMockMixin(object):
def
register_get_threads_search_response
(
self
,
threads
,
rewrite
,
num_pages
=
1
):
"""Register a mock response for GET on the CS thread search endpoint"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
GET
,
"http://localhost:4567/api/v1/search/threads"
,
...
...
@@ -100,6 +103,7 @@ class CommentsServiceMockMixin(object):
def
register_post_thread_response
(
self
,
thread_data
):
"""Register a mock response for POST on the CS commentable endpoint"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
POST
,
re
.
compile
(
r"http://localhost:4567/api/v1/(\w+)/threads"
),
...
...
@@ -111,6 +115,7 @@ class CommentsServiceMockMixin(object):
Register a mock response for PUT on the CS endpoint for the given
thread_id.
"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
PUT
,
"http://localhost:4567/api/v1/threads/{}"
.
format
(
thread_data
[
"id"
]),
...
...
@@ -119,6 +124,7 @@ class CommentsServiceMockMixin(object):
def
register_get_thread_error_response
(
self
,
thread_id
,
status_code
):
"""Register a mock error response for GET on the CS thread endpoint."""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
GET
,
"http://localhost:4567/api/v1/threads/{id}"
.
format
(
id
=
thread_id
),
...
...
@@ -130,6 +136,7 @@ class CommentsServiceMockMixin(object):
"""
Register a mock response for GET on the CS thread instance endpoint.
"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
GET
,
"http://localhost:4567/api/v1/threads/{id}"
.
format
(
id
=
thread
[
"id"
]),
...
...
@@ -148,6 +155,7 @@ class CommentsServiceMockMixin(object):
else
:
url
=
"http://localhost:4567/api/v1/threads/{}/comments"
.
format
(
thread_id
)
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
POST
,
url
,
...
...
@@ -161,6 +169,7 @@ class CommentsServiceMockMixin(object):
"""
thread_id
=
comment_data
[
"thread_id"
]
parent_id
=
comment_data
.
get
(
"parent_id"
)
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
PUT
,
"http://localhost:4567/api/v1/comments/{}"
.
format
(
comment_data
[
"id"
]),
...
...
@@ -172,6 +181,7 @@ class CommentsServiceMockMixin(object):
Register a mock error response for GET on the CS comment instance
endpoint.
"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
GET
,
"http://localhost:4567/api/v1/comments/{id}"
.
format
(
id
=
comment_id
),
...
...
@@ -184,6 +194,7 @@ class CommentsServiceMockMixin(object):
Register a mock response for GET on the CS comment instance endpoint.
"""
comment
=
make_minimal_cs_comment
(
response_overrides
)
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
GET
,
"http://localhost:4567/api/v1/comments/{id}"
.
format
(
id
=
comment
[
"id"
]),
...
...
@@ -193,6 +204,7 @@ class CommentsServiceMockMixin(object):
def
register_get_user_response
(
self
,
user
,
subscribed_thread_ids
=
None
,
upvoted_ids
=
None
):
"""Register a mock response for GET on the CS user instance endpoint"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
GET
,
"http://localhost:4567/api/v1/users/{id}"
.
format
(
id
=
user
.
id
),
...
...
@@ -206,6 +218,7 @@ class CommentsServiceMockMixin(object):
def
register_subscribed_threads_response
(
self
,
user
,
threads
,
page
,
num_pages
):
"""Register a mock response for GET on the CS user instance endpoint"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
GET
,
"http://localhost:4567/api/v1/users/{}/subscribed_threads"
.
format
(
user
.
id
),
...
...
@@ -223,6 +236,7 @@ class CommentsServiceMockMixin(object):
Register a mock response for POST and DELETE on the CS user subscription
endpoint
"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
for
method
in
[
httpretty
.
POST
,
httpretty
.
DELETE
]:
httpretty
.
register_uri
(
method
,
...
...
@@ -236,6 +250,7 @@ class CommentsServiceMockMixin(object):
Register a mock response for PUT and DELETE on the CS thread votes
endpoint
"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
for
method
in
[
httpretty
.
PUT
,
httpretty
.
DELETE
]:
httpretty
.
register_uri
(
method
,
...
...
@@ -249,6 +264,7 @@ class CommentsServiceMockMixin(object):
Register a mock response for PUT and DELETE on the CS comment votes
endpoint
"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
for
method
in
[
httpretty
.
PUT
,
httpretty
.
DELETE
]:
httpretty
.
register_uri
(
method
,
...
...
@@ -259,6 +275,7 @@ class CommentsServiceMockMixin(object):
def
register_flag_response
(
self
,
content_type
,
content_id
):
"""Register a mock response for PUT on the CS flag endpoints"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
for
path
in
[
"abuse_flag"
,
"abuse_unflag"
]:
httpretty
.
register_uri
(
"PUT"
,
...
...
@@ -275,6 +292,7 @@ class CommentsServiceMockMixin(object):
"""
Register a mock response for POST on the CS 'read' endpoint
"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
POST
,
"http://localhost:4567/api/v1/users/{id}/read"
.
format
(
id
=
user
.
id
),
...
...
@@ -295,6 +313,7 @@ class CommentsServiceMockMixin(object):
"""
Register a mock response for DELETE on the CS thread instance endpoint
"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
DELETE
,
"http://localhost:4567/api/v1/threads/{id}"
.
format
(
id
=
thread_id
),
...
...
@@ -306,6 +325,7 @@ class CommentsServiceMockMixin(object):
"""
Register a mock response for DELETE on the CS comment instance endpoint
"""
assert
httpretty
.
is_enabled
(),
'httpretty must be enabled to mock calls.'
httpretty
.
register_uri
(
httpretty
.
DELETE
,
"http://localhost:4567/api/v1/comments/{id}"
.
format
(
id
=
comment_id
),
...
...
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