Ejemplo n.º 1
0
 def setUp(self):
     self.fake_model = tests_models.CredentialsModel()
     self.fake_model_field = self.fake_model._meta.get_field('credentials')
     self.field = models.CredentialsField(null=True)
     self.credentials = client.Credentials()
     self.pickle_str = _helpers._from_bytes(
         base64.b64encode(pickle.dumps(self.credentials)))
Ejemplo n.º 2
0
    def __init__(self, auth_obj, scope):
        self.auth_obj=auth_obj
        self.service = None
        self.execute_function = None
        
        if scope is None or scope=='':
            self.scope = 'https://www.googleapis.com/auth/userinfo.email'
        else:
            self.scope = scope
        
        try:
            if auth_obj is None or auth_obj=='':
                google_auth_obj = auth.GoogleAuth(self.scope)
                credentials = google_auth_obj.authorize()
                self.auth_obj = credentials
            else:
                credentials = client.Credentials()
                self.auth_obj = credentials.new_from_json(auth_obj)

            if self.auth_obj.invalid:
                google_auth_obj = auth.GoogleAuth(self.scope)
                credentials = google_auth_obj.authorize()

                self.auth_obj = credentials
        
        except Exception as err:
            apps_error_logger.info("GoogleAuthError:In "+str(self.__class__.__name__)+", "+str(err))
Ejemplo n.º 3
0
 def test__to_base_type_valid_creds(self):
     creds_prop = TestNDBModel.creds
     creds = client.Credentials()
     creds_json = json.loads(creds_prop._to_base_type(creds))
     self.assertDictEqual(creds_json, {
         '_class': 'Credentials',
         '_module': 'oauth2client.client',
         'token_expiry': None,
     })
Ejemplo n.º 4
0
 def testOauth2client(self):
     google_auth_cred = google_auth_creds.Credentials('google_auth_token')
     oauth2client_cred = client.Credentials()
     oauth2client_cred.access_token = 'oauth2client_token'
     self.c_store_refresh = self.StartObjectPatch(c_store,
                                                  'Refresh',
                                                  autospec=True,
                                                  return_value=None)
     self.AssertEqual('google_auth_token',
                      iap_tunnel._GetAccessTokenCallback(google_auth_cred))
     self.AssertEqual('oauth2client_token',
                      iap_tunnel._GetAccessTokenCallback(oauth2client_cred))
Ejemplo n.º 5
0
 def test_valid_creds_get_put(self):
     creds = client.Credentials()
     instance = TestNDBModel(creds=creds, id='bar')
     instance.put()
     retrieved = TestNDBModel.get_by_id('bar')
     self.assertIsInstance(retrieved.creds, client.Credentials)
Ejemplo n.º 6
0
 def test_validate_success(self, mock_logger):
     creds_prop = TestNDBModel.creds
     creds_val = client.Credentials()
     creds_prop._validate(creds_val)
     mock_logger.info.assert_called_once_with('validate: Got type %s',
                                              type(creds_val))