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_refresh__with_short_device_id(self):
authorizer = prawcore.DeviceIDAuthorizer(self.authentication, "a" * 19)
with Betamax(REQUESTOR).use_cassette(
"DeviceIDAuthorizer_refresh__with_short_device_id"
):
self.assertRaises(prawcore.OAuthException, authorizer.refresh)
def test_init__with_device_id_authorizer(self):
authenticator = prawcore.UntrustedAuthenticator(REQUESTOR, CLIENT_ID)
authorizer = prawcore.DeviceIDAuthorizer(authenticator)
prawcore.Session(authorizer)
def test_initialize(self):
authorizer = prawcore.DeviceIDAuthorizer(self.authentication)
self.assertIsNone(authorizer.access_token)
self.assertIsNone(authorizer.scopes)
self.assertFalse(authorizer.is_valid())
def test_initialize__with_trusted_authenticator(self):
authenticator = prawcore.TrustedAuthenticator(None, None, None)
self.assertRaises(
prawcore.InvalidInvocation,
prawcore.DeviceIDAuthorizer,
authenticator,
)
def main():
"""Provide the program's entry point when directly executed."""
if len(sys.argv) != 2:
print("Usage: {} USERNAME".format(sys.argv[0]))
return 1
authenticator = prawcore.UntrustedAuthenticator(
prawcore.Requestor("prawcore_device_id_auth_example"),
os.environ["PRAWCORE_CLIENT_ID"],
)
authorizer = prawcore.DeviceIDAuthorizer(authenticator)
authorizer.refresh()
user = sys.argv[1]
with prawcore.session(authorizer) as session:
data = session.request("GET", "/api/v1/user/{}/trophies".format(user))
for trophy in data["data"]["trophies"]:
description = trophy["data"]["description"]
print(
trophy["data"]["name"]
+ (" ({})".format(description) if description else "")
)
return 0
def _prepare_untrusted_prawcore(self, requestor):
authenticator = UntrustedAuthenticator(
requestor, self.config.client_id, self.config.redirect_uri
)
read_only_authorizer = DeviceIDAuthorizer(authenticator)
self._read_only_core = session(read_only_authorizer)
if self.config.refresh_token:
authorizer = Authorizer(authenticator, self.config.refresh_token)
self._core = self._authorized_core = session(authorizer)
else:
self._core = self._read_only_core