コード例 #1
0
ファイル: services.py プロジェクト: grannydatasoup/gapiutils
def authorize_datastore(dataset=None, conf=None, conf_file='/etc/gaw/gapi.yaml'):
    conf = conf or yaml.load(file(conf_file), Loader)

    cert_file = conf['gapi']['auth']['cert']
    dataset = dataset or conf['gapi']['app']

    scope = 'https://www.googleapis.com/auth/datastore https://www.googleapis.com/auth/userinfo.email'

    credentials = ServiceAccountCredentials.from_json_keyfile_name(cert_file, scopes=scope)

    connection = datastore.Connection(credentials=credentials)
    datastore.set_default_connection(connection)
    datastore.set_default_dataset_id(dataset)

    return connection
コード例 #2
0
ファイル: test_model.py プロジェクト: cjrh/gcloud-python-orm
    def testInsert(self):
        connection = _Connection()
        transaction = connection._transaction = _Transaction()
        dataset = _Dataset(connection)
        key = _Key()
        set_default_connection(connection)

        class TestModel(model.Model):
            test_value = properties.TextProperty()

        entity = TestModel()
        entity.key = key
        entity.test_value = '123'
        entity.save()

        self.assertEqual(entity['test_value'], '123')
        self.assertEqual(connection._saved, (_DATASET_ID, 'KEY', {
            'test_value': '123'
        }, ()))
        self.assertEqual(key._path, None)
コード例 #3
0
 def _callFUT(self, connection=None):
     from gcloud.datastore import set_default_connection
     return set_default_connection(connection=connection)
コード例 #4
0
 def _callFUT(self, connection=None):
     from gcloud.datastore import set_default_connection
     return set_default_connection(connection=connection)