def testQueryEmptyNamespace(self): # Test that we can pass a namespace of None. self._test_client.namespace = None q = Query(project=self._PROJECT, namespace=None) cq = q._to_client_query(self._test_client) self.assertEqual(self._test_client.project, cq.project) self.assertEqual(None, cq.namespace)
def testQuery(self): filters = [('property_name', '=', 'value')] projection = ['f1', 'f2'] order = projection distinct_on = projection ancestor_key = Key(['kind', 'id'], project=self._PROJECT) q = Query(kind='kind', project=self._PROJECT, namespace=self._NAMESPACE, ancestor=ancestor_key, filters=filters, projection=projection, order=order, distinct_on=distinct_on) cq = q._to_client_query(self._test_client) self.assertEqual(self._PROJECT, cq.project) self.assertEqual(self._NAMESPACE, cq.namespace) self.assertEqual('kind', cq.kind) self.assertEqual(ancestor_key.to_client_key(), cq.ancestor) self.assertEqual(filters, cq.filters) self.assertEqual(projection, cq.projection) self.assertEqual(order, cq.order) self.assertEqual(distinct_on, cq.distinct_on) logging.info('query: %s', q) # Test __repr__()
def testValueProviderFilters(self): self.vp_filters = [ [(StaticValueProvider(str, 'property_name'), StaticValueProvider(str, '='), StaticValueProvider(str, 'value'))], [(StaticValueProvider(str, 'property_name'), StaticValueProvider(str, '='), StaticValueProvider(str, 'value')), ('property_name', '=', 'value')], ] self.expected_filters = [ [('property_name', '=', 'value')], [('property_name', '=', 'value'), ('property_name', '=', 'value')], ] for vp_filter, exp_filter in zip(self.vp_filters, self.expected_filters): q = Query(kind='kind', project=self._PROJECT, namespace=self._NAMESPACE, filters=vp_filter) cq = q._to_client_query(self._test_client) self.assertEqual(exp_filter, cq.filters) logging.info('query: %s', q) # Test __repr__()
def testValueProviderNamespace(self): self.vp_namespace = StaticValueProvider(str, 'vp_namespace') self.expected_namespace = 'vp_namespace' q = Query(kind='kind', project=self._PROJECT, namespace=self.vp_namespace) cq = q._to_client_query(self._test_client) self.assertEqual(self.expected_namespace, cq.namespace) _LOGGER.info('query: %s', q) # Test __repr__()