How to use _run_request method in gabbi

Best Python code snippet using gabbi_python

test_sentry_app_authorizations.py

Source: test_sentry_app_authorizations.py Github

copy

Full Screen

...24 self.install = self.create_sentry_app_installation(25 organization=self.org, slug="nulldb", user=self.user26 )27 self.url = reverse("sentry-api-0-sentry-app-authorizations", args=[self.install.uuid])28 def _run_request(self, *args, **kwargs):29 data = {30 "client_id": self.sentry_app.application.client_id,31 "client_secret": self.sentry_app.application.client_secret,32 "grant_type": "authorization_code",33 "code": self.install.api_grant.code,34 }35 data.update(**kwargs)36 return self.client.post(self.url, data, headers={"Content-Type": "application/​json"})37 def test_exchanges_for_token_successfully(self):38 expected_expires_at = (timezone.now() + timedelta(hours=8)).replace(second=0, microsecond=0)39 response = self._run_request()40 token = ApiToken.objects.get(application=self.sentry_app.application)41 assert response.status_code == 201, response.content42 assert response.data["scopes"] == self.sentry_app.scope_list43 assert response.data["token"] == token.token44 assert response.data["refreshToken"] == token.refresh_token45 expires_at = response.data["expiresAt"].replace(second=0, microsecond=0)46 assert expires_at == expected_expires_at47 def test_incorrect_grant_type(self):48 response = self._run_request(grant_type="notit")49 assert response.status_code == 40350 def test_invalid_installation(self):51 self.install = self.create_sentry_app_installation(52 organization=self.org, slug="slowdb", user=self.user53 )54 # URL with this new Install's uuid in it55 self.url = reverse("sentry-api-0-sentry-app-authorizations", args=[self.install.uuid])56 response = self._run_request()57 assert response.status_code == 40358 def test_non_sentry_app_user(self):59 app = ApiApplication.objects.create(owner=self.create_user())60 response = self._run_request(client_id=app.client_id, client_secret=app.client_secret)61 assert response.status_code == 40162 def test_invalid_grant(self):63 response = self._run_request(code="123")64 assert response.status_code == 40365 def test_expired_grant(self):66 self.install.api_grant.update(expires_at=timezone.now() - timedelta(minutes=2))67 response = self._run_request()68 assert response.status_code == 40369 assert response.data["error"] == "Grant has already expired."70 def test_request_with_exchanged_access_token(self):71 response = self._run_request()72 token = response.data["token"]73 url = reverse("sentry-api-0-organization-details", args=[self.org.slug])74 response = self.client.get(url, HTTP_AUTHORIZATION="Bearer {}".format(token))75 assert response.status_code == 20076 assert response.data["id"] == six.binary_type(self.org.id)77 def test_state(self):78 response = self._run_request(state="abc123")79 assert response.data["state"] == "abc123"80 def test_refresh_token_exchange(self):81 response = self._run_request()82 token_id = response.data["id"]83 token = response.data["token"]84 refresh_token = response.data["refreshToken"]85 response = self._run_request(86 code=None, refresh_token=refresh_token, grant_type="refresh_token"87 )88 assert response.data["token"] != token89 assert response.data["refreshToken"] != refresh_token90 assert response.data["expiresAt"] > timezone.now()91 old_token = ApiToken.objects.filter(id=token_id)...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Pair testing strategy in an Agile environment

Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.

Migrating Test Automation Suite To Cypress 10

There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.

Continuous Integration explained with jenkins deployment

Continuous integration is a coding philosophy and set of practices that encourage development teams to make small code changes and check them into a version control repository regularly. Most modern applications necessitate the development of code across multiple platforms and tools, so teams require a consistent mechanism for integrating and validating changes. Continuous integration creates an automated way for developers to build, package, and test their applications. A consistent integration process encourages developers to commit code changes more frequently, resulting in improved collaboration and code quality.

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 gabbi 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