def setUp(self): self.fake_model = CredentialsModel() self.fake_model_field = self.fake_model._meta.get_field('credentials') self.field = CredentialsField(null=True) self.credentials = Credentials() self.pickle_str = _helpers._from_bytes( base64.b64encode(pickle.dumps(self.credentials)))
def get_authorize_http(): """ Method which is helpful to get authorize http from your credentials. Can be used for make some service from google api """ json = db(GoogleToken).first().credentials cred = Credentials() credentials = cred.new_from_json(json) http = httplib2.Http() http = credentials.authorize(http) return http
def test__to_base_type_valid_creds(self): creds_prop = TestNDBModel.creds creds = Credentials() creds_json = json.loads(creds_prop._to_base_type(creds)) self.assertDictEqual( creds_json, { '_class': 'Credentials', '_module': 'oauth2client.client', 'token_expiry': None, })
def get_credentials_from_db(): """ Static method. This method make query from db to get json-credentials, and then return object correct credentials which has been made from json. Set httplib2.debuglevel = 4 to debug http""" # httplib2.debuglevel = 4 json = db(GoogleToken).one().credentials cred = Credentials() credentials = cred.new_from_json(json) http = httplib2.Http() http = credentials.authorize(http) credentials.refresh(http) session['access_token'] = credentials.access_token return credentials
def test_to_from_json(self): credentials = Credentials() json = credentials.to_json() restored = Credentials.new_from_json(json)
def setUp(self): self.field = CredentialsField() self.credentials = Credentials() self.pickle = base64.b64encode(pickle.dumps(self.credentials))
def test_valid_creds_get_put(self): creds = Credentials() instance = TestNDBModel(creds=creds, id='bar') instance.put() retrieved = TestNDBModel.get_by_id('bar') self.assertIsInstance(retrieved.creds, Credentials)
def test_validate_success(self, mock_logger): creds_prop = TestNDBModel.creds creds_val = Credentials() creds_prop._validate(creds_val) mock_logger.info.assert_called_once_with('validate: Got type %s', type(creds_val))