Make sure httpretty usage cleans up after itself
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user