Beispiel #1
0
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
Beispiel #2
0
    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)
Beispiel #3
0
 def _callFUT(self, connection=None):
     from gcloud.datastore import set_default_connection
     return set_default_connection(connection=connection)
Beispiel #4
0
 def _callFUT(self, connection=None):
     from gcloud.datastore import set_default_connection
     return set_default_connection(connection=connection)