def test_query_w_defaults(self): from google.cloud.datastore import client as MUT from google.cloud._testing import _Monkey creds = object() client = self._makeOne(credentials=creds) with _Monkey(MUT, Query=_Dummy): query = client.query() self.assertIsInstance(query, _Dummy) self.assertEqual(query.args, (client,)) expected_kwargs = { 'project': self.PROJECT, 'namespace': None, } self.assertEqual(query.kwargs, expected_kwargs)
def test_query_w_namespace(self): from google.cloud.datastore import client as MUT from google.cloud._testing import _Monkey KIND = 'KIND' NAMESPACE = object() creds = object() client = self._makeOne(namespace=NAMESPACE, credentials=creds) with _Monkey(MUT, Query=_Dummy): query = client.query(kind=KIND) self.assertIsInstance(query, _Dummy) self.assertEqual(query.args, (client,)) expected_kwargs = { 'project': self.PROJECT, 'namespace': NAMESPACE, 'kind': KIND, } self.assertEqual(query.kwargs, expected_kwargs)
def test_query_explicit(self): from google.cloud.datastore import client as MUT from google.cloud._testing import _Monkey KIND = 'KIND' NAMESPACE = 'NAMESPACE' ANCESTOR = object() FILTERS = [('PROPERTY', '==', 'VALUE')] PROJECTION = ['__key__'] ORDER = ['PROPERTY'] DISTINCT_ON = ['DISTINCT_ON'] creds = object() client = self._makeOne(credentials=creds) with _Monkey(MUT, Query=_Dummy): query = client.query( kind=KIND, namespace=NAMESPACE, ancestor=ANCESTOR, filters=FILTERS, projection=PROJECTION, order=ORDER, distinct_on=DISTINCT_ON, ) self.assertIsInstance(query, _Dummy) self.assertEqual(query.args, (client,)) kwargs = { 'project': self.PROJECT, 'kind': KIND, 'namespace': NAMESPACE, 'ancestor': ANCESTOR, 'filters': FILTERS, 'projection': PROJECTION, 'order': ORDER, 'distinct_on': DISTINCT_ON, } self.assertEqual(query.kwargs, kwargs)