def test_authorize(manager): access_name = "access" unauth_req = Request() user_creds = {"access_token": access_name} auth_req = manager.authorize(unauth_req, user_creds) assert auth_req.headers["Authorization"] == "Bearer " + access_name with pytest.raises(KeyError): auth_req = manager.authorize(unauth_req, {})
def test_authorize(manager): access_name = 'access' unauth_req = Request() user_creds = { 'access_token': access_name } auth_req = manager.authorize(unauth_req, user_creds) assert auth_req.headers['Authorization'] == 'Bearer ' + access_name with pytest.raises(KeyError): auth_req = manager.authorize(unauth_req, {})
async def refresh(self, client_creds: Dict[str, str] = None) -> Dict[str, str]: client_creds = client_creds or self.client_creds assertion = self._credentials.make_authorization_grant_assertion() request = Request( url=client_creds["token_uri"], method="POST", headers={"Content-Type": URLENCODED_CONTENT_TYPE}, data={ "grant_type": JWT_GRANT_TYPE, "assertion": assertion.decode() }, ) json_res: Dict[str, any] = await self._send_request(request) # The _build_user_creds_from_res needs the scope field filled in json_res["scope"] = " ".join(self._credentials.scopes) return self._build_user_creds_from_res(json_res)
def get_batch_request(*requests, delimiter='batch_foobarxz'): header = {} header['Content-Type'] = f'multipart/mixed; boundary="{delimiter}"' data = '' for r in requests: path = get_path(r.url) data += f'--{delimiter}\nContent-Type: application/http\n\n{r.method} {path}\n\n' data += f'--{delimiter}--' url = GMAIL_BASE_URL + GMAIL_BATCH_PATH batch_request = Request(method='POST', url=url, batch_url=url, headers=header, data=data) return batch_request
def test_adds_key_to_url_without_query_and_with_slash(manager, key1): url = "https://example.com/api/" req = Request(url=url) request_with_key = manager.authorize(req, key1) assert request_with_key.url == url[:-1] + "?key=" + key1
def test_request_add_query_param(): r = Request(url="https://example.com") r._add_query_param({'foo': 'bar'}) assert r.url == 'https://example.com?foo=bar'
def test_request_add_query_param3(): r = Request(url="https://example.com/foo?bar=baz") r._add_query_param({'idk': 'fuuu'}) assert r.url == 'https://example.com/foo?bar=baz&idk=fuuu'
def test_request_add_query_param2(): r = Request(url="https://example.com/") r._add_query_param({'bar': 'baz'}) assert r.url == 'https://example.com?bar=baz'
def test_adds_key_to_url_without_query(manager, key1): url = 'https://example.com/api' req = Request(url=url) request_with_key = manager.authorize(req, key1) assert request_with_key.url == url + '?key=' + key1