def test_on_gae_empty_key_fails(self): """If empty key is passed on GAE, dies with error.""" self.mock(service_account.utils, 'is_local_dev_server', lambda: False) calls = self.mock_methods() with self.assertRaises(service_account.AccessTokenError): service_account.get_access_token('scope', EMPTY_SECRET_KEY) self.assertFalse(calls)
def test_on_dev_good_key_is_used(self): """On dev server if good key is passed, invokes JWT based fetch.""" calls = self.mock_methods() self.assertEqual( ('token', 0), service_account.get_access_token('scope', FAKE_SECRET_KEY)) self.assertEqual([('jwt_based', ('scope', FAKE_SECRET_KEY))], calls)
def test_on_dev_empty_key_uses_datastore(self): """On dev server uses token from datastore if secret key is empty.""" calls = self.mock_methods() self.assertEqual( ('token', 0), service_account.get_access_token('scope', EMPTY_SECRET_KEY)) self.assertEqual([('dev_server', ())], calls)
def test_on_gae_good_key_is_used(self): """If good key is passed on GAE, invokes JWT based fetch.""" self.mock(service_account.utils, 'is_local_dev_server', lambda: False) calls = self.mock_methods() self.assertEqual( ('token', 0), service_account.get_access_token('scope', FAKE_SECRET_KEY)) self.assertEqual([('jwt_based', ('scope', FAKE_SECRET_KEY))], calls)
def test_on_gae_no_key_uses_gae_api(self): """Uses GAE api if secret key is not used and running on GAE.""" self.mock(service_account.utils, 'is_local_dev_server', lambda: False) calls = self.mock_methods() self.assertEqual(('token', 0), service_account.get_access_token('scope')) self.assertEqual([('gae_api', ('scope',))], calls)
def test_on_dev_no_key_uses_datastore(self): """On dev server uses token from datastore if secret key is not used.""" calls = self.mock_methods() self.assertEqual(('token', 0), service_account.get_access_token('scope')) self.assertEqual([('dev_server', ())], calls)