How to use add_passthru method in responses

Best Python code snippet using responses

fixtures.py

Source:fixtures.py Github

copy

Full Screen

...365 version = client.version()['ApiVersion']366 if "CIRCLECI" in os.environ:367 docker_host = os.environ['DOCKER_HOST']368 docker_host = docker_host.replace("tcp", "https")369 responses.add_passthru(370 f"{docker_host}/v{version}/images/default-default-labbook1/json")371 responses.add_passthru(372 f"{docker_host}/v{version}/containers/default-default-labbook1/json")373 responses.add_passthru(374 f"{docker_host}/v{version}/images/default-default-labbook1/json")375 responses.add_passthru(376 f"{docker_host}/v{version}/containers/default-default-labbook1/json")377 responses.add_passthru(378 f"{docker_host}/v{version}/images/default-test-sample-repo-lb/json")379 responses.add_passthru(380 f"{docker_host}/v{version}/containers/default-test-sample-repo-lb/json")381 responses.add_passthru(382 #'http+docker://35.196.196.144:2376/v1.30/containers/default-test-sample-repo-lb/json')383 '{docker_host}/v{version}/containers/default-test-sample-repo-lb/json')384 else:385 responses.add_passthru(386 f"http+docker://localunixsocket/v{version}/images/default-default-labbook1/json")387 responses.add_passthru(388 f"http+docker://localunixsocket/v{version}/containers/default-default-labbook1/json")389 responses.add_passthru(390 f"http+docker://localunixsocket/v{version}/images/default-test-sample-repo-lb/json")391 responses.add_passthru(392 f"http+docker://localunixsocket/v{version}/containers/default-test-sample-repo-lb/json")...

Full Screen

Full Screen

test_new.py

Source:test_new.py Github

copy

Full Screen

...79 "https://api.github.com/repos/{0}/releases".format(self.default_repo),80 body='[{"name": "v2.3.6", "tag_name": "v2.3.6", "zipball_url": "https://api.github.com/repos/MasoniteFramework/cookie-cutter/zipball/v2.3.6"}]',81 )82 # authorize requests not using the API83 responses.add_passthru(84 "https://api.github.com/repos/MasoniteFramework/cookie-cutter/zipball/v2.3.6"85 )86 responses.add_passthru(87 "https://codeload.github.com/MasoniteFramework/cookie-cutter/legacy.zip/v2.3.6"88 )89 self.command_tester.execute("new_project --release 2.3.6")90 self.assertTrue(91 self.command_tester.io.fetch_output().startswith(92 "Installing version v2.3.6"93 )94 )95 @responses.activate96 def test_warning_is_displayed_when_no_tags_in_repo_if_not_official(self):97 # there is no tags on this test repo98 # mock this one as it can be rate limited99 responses.add(100 responses.GET,101 "https://gitlab.com/api/v4/projects/samuelgirardin%2Fmasonite-tests/releases",102 body="[]",103 )104 # authorize requests not using the API105 responses.add_passthru(106 "https://gitlab.com/api/v4/projects/samuelgirardin%2Fmasonite-tests/repository/archive.zip?sha=master"107 )108 self.command_tester.execute(109 "new_project --repo samuelgirardin/masonite-tests --provider gitlab"110 )111 self.assertTrue(112 "No tags has been found, using latest commit on master."113 in self.command_tester.io.fetch_output()114 )115 @responses.activate116 def test_api_rate_limit_are_handled(self):117 responses.add(118 responses.GET,119 "https://api.github.com/repos/{0}/branches/{1}".format(120 self.default_repo, self.default_branch121 ),122 status=403,123 )124 # allow reproducing error raised by Github API125 with patch(126 "six.moves.http_client.responses", get=lambda status: "rate limit exceeded"127 ):128 with self.assertRaises(ProjectLimitReached):129 self.command_tester.execute("new_project")130 @responses.activate131 def test_unknown_repos_are_handled(self):132 responses.add(133 responses.GET,134 "https://api.github.com/repos/MasoniteFramework/unknown_repo/releases",135 status=404,136 )137 with self.assertRaises(ProjectProviderHttpError) as e:138 self.command_tester.execute(139 "new_project --repo MasoniteFramework/unknown_repo"140 )141 self.assertTrue(str(e.exception).startswith("Not Found(404)"))142 @responses.activate143 def test_private_repos_errors_are_handled(self):144 responses.add(145 responses.GET,146 "https://api.github.com/repos/MasoniteFramework/secret/releases",147 status=403,148 )149 with self.assertRaises(ProjectProviderHttpError) as e:150 self.command_tester.execute("new_project --repo MasoniteFramework/secret")151 self.assertTrue(str(e.exception).startswith("Forbidden(403)"))152 @responses.activate153 def test_timeouts_are_handled(self):154 responses.add(155 responses.GET,156 "https://api.github.com/repos/{0}/branches/{1}".format(157 self.default_repo, self.default_branch158 ),159 body=requests.Timeout(),160 )161 with self.assertRaises(ProjectProviderTimeout) as e:162 self.command_tester.execute("new_project")163 self.assertTrue(str(e.exception).startswith("github provider is not reachable"))164 # Following tests are close to integration tests but still quick and without rate limiting issue so165 # they can be ran as unit tests166 # ----------------------------------------------------------------------------------------------167 @responses.activate168 def test_can_craft_default_repo_successfully(self):169 # still mocking requests to avoid failures from api rate limits170 body = {"name": self.default_branch}171 responses.add(172 responses.GET,173 "https://api.github.com/repos/{0}/branches/{1}".format(174 self.default_repo, self.default_branch175 ),176 body=json.dumps(body),177 )178 # authorize requests not using the API179 responses.add_passthru(180 "https://github.com/MasoniteFramework/cookie-cutter/archive/{0}.zip".format(181 self.default_branch182 )183 )184 responses.add_passthru(185 "https://codeload.github.com/MasoniteFramework/cookie-cutter/zip/{0}".format(186 self.default_branch187 )188 )189 self.command_tester.execute("new_project")190 self.assertTrue(191 "Project Created Successfully" in self.command_tester.io.fetch_output()192 )193 # verify that project has really been created by checking files194 self.assertTrue("craft" in os.listdir(self.test_project_dir))195 self.assertTrue("app" in os.listdir(self.test_project_dir))196 @responses.activate197 def test_can_craft_default_repo_successfully_with_release(self):198 # still mocking requests to avoid failures from api rate limits199 responses.add(200 responses.GET,201 "https://api.github.com/repos/{0}/releases".format(self.default_repo),202 body='[{"name": "v2.3.6", "tag_name": "v2.3.6", "zipball_url": "https://api.github.com/repos/MasoniteFramework/cookie-cutter/zipball/v2.3.6", "prerelease": false}]',203 )204 responses.add(205 responses.GET,206 "https://api.github.com/repos/{0}/releases/tags/v2.3.6".format(207 self.default_repo208 ),209 body='{"zipball_url": "https://api.github.com/repos/MasoniteFramework/cookie-cutter/zipball/v2.3.6"}',210 )211 # authorize requests not using the API212 responses.add_passthru(213 "https://api.github.com/repos/MasoniteFramework/cookie-cutter/zipball/v2.3.6"214 )215 responses.add_passthru(216 "https://codeload.github.com/MasoniteFramework/cookie-cutter/legacy.zip/refs/tags/v2.3.6"217 )218 self.command_tester.execute("new_project --release 2.3.6")219 self.assertTrue(220 "Project Created Successfully" in self.command_tester.io.fetch_output()221 )222 # verify that project has really been created by checking files223 self.assertTrue("craft" in os.listdir(self.test_project_dir))224 self.assertTrue("app" in os.listdir(self.test_project_dir))225 @responses.activate226 def test_can_craft_default_repo_successfully_with_branch(self):227 # still mocking requests to avoid failures from api rate limits228 responses.add(229 responses.GET,230 "https://api.github.com/repos/{0}/branches/2.3".format(self.default_repo),231 body='{"name": "2.3"}',232 )233 # authorize requests not using the API234 responses.add_passthru(235 "https://github.com/MasoniteFramework/cookie-cutter/archive/2.3.zip"236 )237 responses.add_passthru(238 "https://codeload.github.com/MasoniteFramework/cookie-cutter/zip/2.3"239 )240 self.command_tester.execute("new_project --branch 2.3")241 self.assertTrue(242 "Project Created Successfully" in self.command_tester.io.fetch_output()243 )244 # verify that project has really been created by checking files245 self.assertTrue("craft" in os.listdir(self.test_project_dir))246 self.assertTrue("app" in os.listdir(self.test_project_dir))247 @responses.activate248 def test_can_craft_project_with_gitlab_provider(self):249 # mock this one as it can be rate limited250 responses.add(251 responses.GET,252 "https://gitlab.com/api/v4/projects/samuelgirardin%2Fmasonite-tests/releases",253 body="[]",254 )255 # authorize requests not using the API256 responses.add_passthru(257 "https://gitlab.com/api/v4/projects/samuelgirardin%2Fmasonite-tests/repository/archive.zip?sha=master"258 )259 repo = "samuelgirardin/masonite-tests"260 self.command_tester.execute(261 "new_project --provider gitlab --repo {0}".format(repo)262 )263 self.assertTrue(264 "Project Created Successfully" in self.command_tester.io.fetch_output()265 )266 # verify that project has really been created by checking files...

Full Screen

Full Screen

relay.py

Source:relay.py Github

copy

Full Screen

...38 def use_relay(self):39 return True40 def post_and_retrieve_event(self, data):41 url = self.get_relay_store_url(self.project.id)42 responses.add_passthru(url)43 resp = requests.post(44 url,45 headers={"x-sentry-auth": self.auth_header, "content-type": "application/json"},46 json=data,47 )48 assert resp.ok49 resp_body = resp.json()50 event_id = resp_body["id"]51 event = self.wait_for_ingest_consumer(52 lambda: eventstore.get_event_by_id(self.project.id, event_id)53 )54 # check that we found it in Snuba55 assert event is not None56 return event57 def post_and_retrieve_security_report(self, data):58 url = self.get_relay_security_url(self.project.id, self.projectkey.public_key)59 responses.add_passthru(url)60 event_ids = {61 event.event_id62 for event in eventstore.get_events(eventstore.Filter(project_ids=[self.project.id]))63 }64 def has_new_event():65 # Hack: security report endpoint does not return event ID66 for event in eventstore.get_events(eventstore.Filter(project_ids=[self.project.id])):67 if event.event_id not in event_ids:68 return event69 resp = requests.post(url, json=data)70 assert resp.ok71 event = self.wait_for_ingest_consumer(has_new_event)72 # check that we found it in Snuba73 assert event74 return event75 def post_and_try_retrieve_event(self, data):76 try:77 return self.post_and_retrieve_event(data)78 except AssertionError:79 return None80 def post_and_retrieve_attachment(self, event_id, files):81 url = self.get_relay_attachments_url(self.project.id, event_id)82 responses.add_passthru(url)83 resp = requests.post(url, files=files, headers={"x-sentry-auth": self.auth_header})84 assert resp.ok85 exists = self.wait_for_ingest_consumer(86 lambda: EventAttachment.objects.filter(87 project_id=self.project.id, event_id=event_id88 ).exists()89 or None # must return None to continue waiting90 )91 assert exists92 def post_and_retrieve_minidump(self, files, data):93 url = self.get_relay_minidump_url(self.project.id, self.projectkey.public_key)94 responses.add_passthru(url)95 resp = requests.post(96 url,97 files=dict(files or ()),98 data=dict(data or ()),99 )100 assert resp.ok101 event_id = resp.text.strip().replace("-", "")102 event = self.wait_for_ingest_consumer(103 lambda: eventstore.get_event_by_id(self.project.id, event_id)104 )105 # check that we found it in Snuba106 assert event is not None107 return event108 def post_and_retrieve_unreal(self, payload):109 url = self.get_relay_unreal_url(self.project.id, self.projectkey.public_key)110 responses.add_passthru(url)111 resp = requests.post(112 url,113 data=payload,114 )115 assert resp.ok116 event_id = resp.text.strip().replace("-", "")117 event = self.wait_for_ingest_consumer(118 lambda: eventstore.get_event_by_id(self.project.id, event_id)119 )120 # check that we found it in Snuba121 assert event is not None122 return event123 @pytest.fixture(autouse=True)124 def relay_setup_fixtures(...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run responses automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful