Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_group_invalidkeys_fail(self):
sObj = Splitwise('consumerkey', 'consumersecret', {"oauth_token": "sdsd", "oauth_token_secret": "sdsdd"})
group = Group()
with self.assertRaises(SplitwiseUnauthorizedException):
sObj.createGroup(group)
dict: dict containing:
oauth_token(str): The OAuth 1.0 token
oauth_token_secret(str): The OAuth 1.0 token secret
"""
oauth1 = OAuth1(
self.consumer_key,
client_secret=self.consumer_secret,
resource_owner_key=oauth_token,
resource_owner_secret=oauth_token_secret,
verifier=oauth_verifier
)
try:
content = self.__makeRequest(Splitwise.ACCESS_TOKEN_URL, 'POST', auth=oauth1)
except SplitwiseUnauthorizedException as e:
e.setMessage("Your oauth token could be expired or check your consumer id and secret")
raise
credentials = parse_qs(content)
return {
"oauth_token": credentials.get("oauth_token")[0],
"oauth_token_secret": credentials.get("oauth_token_secret")[0],
}
auth = self.auth
requestObj = Request(method=method, url=url, data=data, auth=auth)
prep_req = requestObj.prepare()
with sessions.Session() as session:
response = session.send(prep_req)
if response.status_code == 200:
if (response.content and hasattr(response.content, "decode")):
return response.content.decode("utf-8")
return response.content
if response.status_code == 401:
raise SplitwiseUnauthorizedException("Please check your token or consumer id and secret", response=response)
if response.status_code == 403:
raise SplitwiseNotAllowedException("You are not allowed to perform this operation", response=response)
if response.status_code == 400:
raise SplitwiseBadRequestException("Please check your request", response=response)
if response.status_code == 404:
raise SplitwiseNotFoundException("Required resource is not found", response)
raise SplitwiseException("Unknown error happened", response)