Python responses.replace() Examples
The following are 11
code examples of responses.replace().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
responses
, or try the search function
.
Example #1
Source File: test_create_video_call.py From zulip with Apache License 2.0 | 6 votes |
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")
Example #2
Source File: test_bintray_updater.py From hooks with MIT License | 6 votes |
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)
Example #3
Source File: test_bintray_updater.py From hooks with MIT License | 6 votes |
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)
Example #4
Source File: test_bintray_updater.py From hooks with MIT License | 6 votes |
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)
Example #5
Source File: test_create_video_call.py From zulip with Apache License 2.0 | 5 votes |
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")
Example #6
Source File: test_create_video_call.py From zulip with Apache License 2.0 | 5 votes |
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")
Example #7
Source File: user_test.py From matrixcli with GNU General Public License v3.0 | 5 votes |
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
Example #8
Source File: user_test.py From matrix-python-sdk with Apache License 2.0 | 5 votes |
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
Example #9
Source File: test_bintray_updater.py From hooks with MIT License | 5 votes |
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
Example #10
Source File: test_bintray_updater.py From hooks with MIT License | 5 votes |
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)
Example #11
Source File: test_models.py From course-discovery with GNU Affero General Public License v3.0 | 4 votes |
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))