def test_refresh(self): authorizer = prawcore.DeviceIDAuthorizer(self.authentication) with Betamax(REQUESTOR).use_cassette("DeviceIDAuthorizer_refresh"): authorizer.refresh() self.assertIsNotNone(authorizer.access_token) self.assertEqual(set(["*"]), authorizer.scopes) self.assertTrue(authorizer.is_valid())
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 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 test_init__with_device_id_authorizer(self): authenticator = prawcore.UntrustedAuthenticator(REQUESTOR, CLIENT_ID) authorizer = prawcore.DeviceIDAuthorizer(authenticator) prawcore.Session(authorizer)
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_initialize(self): authorizer = prawcore.DeviceIDAuthorizer(self.authentication) self.assertIsNone(authorizer.access_token) self.assertIsNone(authorizer.scopes) self.assertFalse(authorizer.is_valid())