本文整理汇总了Python中responses.replace方法的典型用法代码示例。如果您正苦于以下问题:Python responses.replace方法的具体用法?Python responses.replace怎么用?Python responses.replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类responses
的用法示例。
在下文中一共展示了responses.replace方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_video_refresh_error
# 需要导入模块: import responses [as 别名]
# 或者: from responses import replace [as 别名]
def test_create_video_refresh_error(self) -> None:
responses.add(
responses.POST,
"https://zoom.us/oauth/token",
json={"access_token": "token", "expires_in": -60},
)
response = self.client_get(
"/calls/zoom/complete",
{"code": "code", "state": '{"realm":"zulip","sid":""}'},
)
self.assertEqual(response.status_code, 200)
responses.replace(responses.POST, "https://zoom.us/oauth/token", status=400)
response = self.client_post("/json/calls/zoom/create")
self.assert_json_error(response, "Invalid Zoom access token")
示例2: test_bad_oss_licenses
# 需要导入模块: import responses [as 别名]
# 或者: from responses import replace [as 别名]
def test_bad_oss_licenses(self):
""" Test when is not possible to retrieve the supported OSS license list from Bintray.
The hook must stop when is not possible to request OSS licenses.
"""
responses.replace(responses.GET, "https://api.bintray.com/licenses/oss_licenses", status=500, json={"message": "You have reached a dark spot"})
tools.save('conanfile.py', content=self.conanfile_complete)
self.conan(['export', '.', 'dummy/0.1.0@foobar/stable'])
output = self.conan(['upload', '--remote=fake', 'dummy/0.1.0@foobar/stable'])
self.assertIn("Uploading dummy/0.1.0@foobar/stable to remote 'fake'", output)
self.assertIn("Uploaded conan recipe 'dummy/0.1.0@foobar/stable' to 'fake'", output)
self.assertIn("post_upload_recipe(): Reading package info from Bintray.", output)
self.assertIn("post_upload_recipe(): Inspecting recipe info.", output)
self.assertIn('post_upload_recipe(): ERROR: Could not request OSS licenses. This hook ' \
'requires access to OSS license list in Bintray (URL), you may deactivate ' \
'the hook if the situation persists. Error (500): {"message": "You have ' \
'reached a dark spot"}', output)
示例3: test_bad_patch_package_info
# 需要导入模块: import responses [as 别名]
# 或者: from responses import replace [as 别名]
def test_bad_patch_package_info(self):
""" Test bad request when patching the package information on Bintray.
The hook must not continue when is not possible to patch the information.
"""
responses.replace(responses.PATCH, "https://api.bintray.com/packages/foobar/conan/dummy%3Afoobar", status=500, json={"message": "You have reached a dark spot"})
tools.save('conanfile.py', content=self.conanfile_complete)
self.conan(['export', '.', 'dummy/0.1.0@foobar/stable'])
output = self.conan(['upload', '--remote=fake', 'dummy/0.1.0@foobar/stable'])
self.assertIn("Uploading dummy/0.1.0@foobar/stable to remote 'fake'", output)
self.assertIn("Uploaded conan recipe 'dummy/0.1.0@foobar/stable' to 'fake': https://bintray.com/foobar/conan", output)
self.assertIn("post_upload_recipe(): Reading package info from Bintray.", output)
self.assertIn("post_upload_recipe(): Inspecting recipe info.", output)
self.assertIn("post_upload_recipe(): Bintray is outdated. Updating Bintray package info:" \
" 'desc', 'github_repo', 'issue_tracker_url', 'labels', 'licenses', " \
"'vcs_url', 'website_url'.", output)
self.assertIn('post_upload_recipe(): ERROR: Could not patch package info: {"message": "You have reached a dark spot"}', output)
self.assertNotIn("post_upload_recipe(): Bintray package information has been updated with success.", output)
示例4: test_up_to_date_info
# 需要导入模块: import responses [as 别名]
# 或者: from responses import replace [as 别名]
def test_up_to_date_info(self):
""" Do not update when the information is up-to-date.
The hook must not patch when there is no different between local recipe and remote info.
"""
information = {
"desc": "This a dummy library",
"labels":["conan", "dummy", "qux", "baz"],
"licenses":["MIT"],
"website_url": "https://dummy.org",
"issue_tracker_url":"https://github.com/foobar/community/issues",
"vcs_url":"https://github.com/foobar/conan-dummy",
"github_repo": "foobar/conan-dummy",
"maturity":"Stable"
}
responses.replace(responses.GET, 'https://api.bintray.com/packages/foobar/conan/dummy%3Afoobar', json=information)
tools.save('conanfile.py', content=self.conanfile_complete)
self.conan(['export', '.', 'dummy/0.1.0@foobar/stable'])
output = self.conan(['upload', '--remote=fake', 'dummy/0.1.0@foobar/stable'])
self.assertIn("Uploading dummy/0.1.0@foobar/stable to remote 'fake'", output)
self.assertIn("Uploaded conan recipe 'dummy/0.1.0@foobar/stable' to 'fake': https://bintray.com/foobar/conan", output)
self.assertIn("post_upload_recipe(): Reading package info from Bintray.", output)
self.assertIn("post_upload_recipe(): Inspecting recipe info.", output)
self.assertNotIn("post_upload_recipe(): Bintray is outdated.", output)
self.assertIn("post_upload_recipe(): Bintray package info is up-to-date.", output)
self.assertNotIn("post_upload_recipe(): Bintray package information has been updated with success.", output)
示例5: test_create_video_request_success
# 需要导入模块: import responses [as 别名]
# 或者: from responses import replace [as 别名]
def test_create_video_request_success(self) -> None:
responses.add(
responses.POST,
"https://zoom.us/oauth/token",
json={"access_token": "oldtoken", "expires_in": -60},
)
response = self.client_get(
"/calls/zoom/complete",
{"code": "code", "state": '{"realm":"zulip","sid":""}'},
)
self.assertEqual(response.status_code, 200)
responses.replace(
responses.POST,
"https://zoom.us/oauth/token",
json={"access_token": "newtoken", "expires_in": 60},
)
responses.add(
responses.POST,
"https://api.zoom.us/v2/users/me/meetings",
json={"join_url": "example.com"},
)
response = self.client_post("/json/calls/zoom/create")
self.assertEqual(
responses.calls[-1].request.url, "https://api.zoom.us/v2/users/me/meetings",
)
self.assertEqual(
responses.calls[-1].request.headers["Authorization"], "Bearer newtoken",
)
json = self.assert_json_success(response)
self.assertEqual(json["url"], "example.com")
self.logout()
self.login_user(self.user)
response = self.client_post("/json/calls/zoom/create")
self.assert_json_error(response, "Invalid Zoom access token")
示例6: test_create_video_request_error
# 需要导入模块: import responses [as 别名]
# 或者: from responses import replace [as 别名]
def test_create_video_request_error(self) -> None:
responses.add(
responses.POST,
"https://zoom.us/oauth/token",
json={"access_token": "token"},
)
responses.add(
responses.POST, "https://api.zoom.us/v2/users/me/meetings", status=400,
)
response = self.client_get(
"/calls/zoom/complete",
{"code": "code", "state": '{"realm":"zulip","sid":""}'},
)
self.assertEqual(response.status_code, 200)
response = self.client_post("/json/calls/zoom/create")
self.assert_json_error(response, "Failed to create Zoom call")
responses.replace(
responses.POST, "https://api.zoom.us/v2/users/me/meetings", status=401,
)
response = self.client_post("/json/calls/zoom/create")
self.assert_json_error(response, "Invalid Zoom access token")
示例7: test_get_display_name
# 需要导入模块: import responses [as 别名]
# 或者: from responses import replace [as 别名]
def test_get_display_name(self, user, room):
displayname_url = HOSTNAME + MATRIX_V2_API_PATH + \
"/profile/{}/displayname".format(user.user_id)
displayname = 'test'
room_displayname = 'room_test'
# No displayname
assert user.get_display_name(room) == user.user_id
responses.add(responses.GET, displayname_url, json={})
assert user.get_display_name() == user.user_id
assert len(responses.calls) == 1
# Get global displayname
responses.replace(responses.GET, displayname_url,
json={"displayname": displayname})
assert user.get_display_name() == displayname
assert len(responses.calls) == 2
# Global displayname already present
assert user.get_display_name() == displayname
# No new request
assert len(responses.calls) == 2
# Per-room displayname
room.members_displaynames[user.user_id] = room_displayname
assert user.get_display_name(room) == room_displayname
# No new request
assert len(responses.calls) == 2
示例8: accept_conan_upload
# 需要导入模块: import responses [as 别名]
# 或者: from responses import replace [as 别名]
def accept_conan_upload(func):
""" Decorator to replace remote URLs
:param func: Wrapped function
"""
def wrapper(*args, **kwargs):
empty_package_response = {
"desc":None,
"labels":[],
"licenses":[],
"website_url":None,
"issue_tracker_url":None,
"github_repo":None,
"vcs_url":None,
"maturity":""
}
oss_licenses = [{
"name": "MIT",
"longname": "The MIT License",
"url": "http://www.opensource.org/licenses/mit-license.php"
}, {
"name": "BSD 2-Clause",
"longname": "Berkeley Software Distribution Simplified (BSD Simplified)",
"url": "http://opensource.org/licenses/BSD-2-Clause"
}]
responses.add(responses.GET, 'https://api.bintray.com/conan/foobar/conan/v1/ping')
responses.add(responses.GET, 'https://api.bintray.com/conan/foobar/conan/v1/conans/dummy/0.1.0/foobar/stable/digest', json={"conanmanifest.txt":""})
responses.add(responses.GET, 'https://api.bintray.com/conan/foobar/conan', status=404)
responses.add(responses.GET, 'https://api.bintray.com/conan/foobar/conan/v1/users/check_credentials')
responses.add(responses.GET, 'https://api.bintray.com/conan/foobar/conan/v1/conans/dummy/0.1.0/foobar/stable', json={})
responses.add(responses.POST, 'https://api.bintray.com/conan/foobar/conan/v1/conans/dummy/0.1.0/foobar/stable/upload_urls', json={})
responses.add(responses.GET, "https://api.bintray.com/licenses/oss_licenses", json=oss_licenses)
responses.add(responses.PATCH, "https://api.bintray.com/packages/foobar/conan/dummy%3Afoobar", json={})
responses.add(responses.GET, 'https://api.bintray.com/packages/foobar/conan/dummy%3Afoobar', json=empty_package_response)
func(*args, **kwargs)
return wrapper
示例9: test_bad_package_info_request
# 需要导入模块: import responses [as 别名]
# 或者: from responses import replace [as 别名]
def test_bad_package_info_request(self):
""" Test bad request when retrieving package information from Bintray.
The hook must not continue when is not possible to retrieve the cached information.
"""
responses.replace(responses.GET, 'https://api.bintray.com/packages/foobar/conan/dummy%3Afoobar', status=500, json={"message": "You have reached a dark spot"})
tools.save('conanfile.py', content=self.conanfile_complete)
self.conan(['export', '.', 'dummy/0.1.0@foobar/stable'])
output = self.conan(['upload', '--remote=fake', 'dummy/0.1.0@foobar/stable'])
self.assertIn("Uploading dummy/0.1.0@foobar/stable to remote 'fake'", output)
self.assertIn("Uploaded conan recipe 'dummy/0.1.0@foobar/stable' to 'fake': https://bintray.com/foobar/conan", output)
self.assertIn("post_upload_recipe(): Reading package info from Bintray.", output)
self.assertIn('ERROR: Could not request package info (500): {"message": "You have reached a dark spot"}', output)
self.assertNotIn("post_upload_recipe(): Inspecting recipe info.", output)
示例10: test_push_tracks_to_lms
# 需要导入模块: import responses [as 别名]
# 或者: from responses import replace [as 别名]
def test_push_tracks_to_lms(self):
"""
Verify that we notify the LMS about tracks without seats on a save() to reviewed
"""
self.partner.lms_url = 'http://127.0.0.1:8000'
self.partner.save()
self.mock_access_token()
self.mock_ecommerce_publication()
url = '{root}courses/{key}/'.format(root=self.partner.lms_coursemode_api_url, key=self.course_run.key)
# Mark course as draft
self.course_run.course.draft = True
self.course_run.course.save()
# Set up and save run
self.course_run.type = factories.CourseRunTypeFactory(
tracks=[
factories.TrackFactory(mode__slug='no-seat', seat_type=None),
factories.TrackFactory(mode__slug='has-seat'),
],
)
self.course_run.draft = True
self.course_run.status = CourseRunStatus.Reviewed
responses.add(responses.GET, url, json=[], status=200)
responses.add(responses.POST, url, json={}, status=201)
with LogCapture(utils_logger.name) as log_capture:
self.course_run.save()
log_capture.check_present((utils_logger.name, 'INFO',
'Successfully published [no-seat] LMS mode for [%s].' % self.course_run.key))
# Test that we don't re-publish modes
self.course_run.status = CourseRunStatus.Unpublished
self.course_run.save()
self.course_run.status = CourseRunStatus.Reviewed
responses.replace(responses.GET, url, json=[{'mode_slug': 'no-seat'}], status=200)
with LogCapture(utils_logger.name) as log_capture:
self.course_run.save()
log_capture.check() # no messages at all, we skipped sending
# Test we report failures
self.course_run.status = CourseRunStatus.Unpublished
self.course_run.save()
self.course_run.status = CourseRunStatus.Reviewed
responses.replace(responses.GET, url, json=[], status=200)
responses.replace(responses.POST, url, body='Shrug', status=500)
with LogCapture(utils_logger.name) as log_capture:
self.course_run.save()
log_capture.check_present((utils_logger.name, 'WARNING',
'Failed publishing [no-seat] LMS mode for [%s]: Shrug' % self.course_run.key))