diff --git a/gcloud/datastore/dataset.py b/gcloud/datastore/dataset.py index dddb37544ca2b..676aeb7d42560 100644 --- a/gcloud/datastore/dataset.py +++ b/gcloud/datastore/dataset.py @@ -15,9 +15,6 @@ """Create / interact with gcloud datastore datasets.""" from gcloud.datastore import helpers -from gcloud.datastore.entity import Entity -from gcloud.datastore.query import Query -from gcloud.datastore.transaction import Transaction class Dataset(object): @@ -75,48 +72,6 @@ def id(self): return self._id - def query(self, *args, **kwargs): - """Create a query bound to this dataset. - - :param args: positional arguments, passed through to the Query - - :param kw: keyword arguments, passed through to the Query - - :rtype: :class:`gcloud.datastore.query.Query` - :returns: a new Query instance, bound to this dataset. - """ - kwargs['dataset'] = self - return Query(*args, **kwargs) - - def entity(self, kind, exclude_from_indexes=()): - """Create an entity bound to this dataset. - - :type kind: string - :param kind: the "kind" of the new entity (see - https://cloud.google.com/datastore/docs/concepts/entities#Datastore_Kinds_and_identifiers) - - :param exclude_from_indexes: names of fields whose values are not to - be indexed. - - :rtype: :class:`gcloud.datastore.entity.Entity` - :returns: a new Entity instance, bound to this dataset. - """ - return Entity(dataset=self, kind=kind, - exclude_from_indexes=exclude_from_indexes) - - def transaction(self, *args, **kwargs): - """Create a transaction bound to this dataset. - - :param args: positional arguments, passed through to the Transaction - - :param kw: keyword arguments, passed through to the Transaction - - :rtype: :class:`gcloud.datastore.transaction.Transaction` - :returns: a new Transaction instance, bound to this dataset. - """ - kwargs['dataset'] = self - return Transaction(*args, **kwargs) - def get_entity(self, key): """Retrieves entity from the dataset, along with its attributes. diff --git a/gcloud/datastore/test_dataset.py b/gcloud/datastore/test_dataset.py index cec7b70496bf9..7f3b74fc37b74 100644 --- a/gcloud/datastore/test_dataset.py +++ b/gcloud/datastore/test_dataset.py @@ -40,42 +40,6 @@ def test_ctor_explicit(self): self.assertEqual(dataset.id(), DATASET_ID) self.assertTrue(dataset.connection() is CONNECTION) - def test_query_factory(self): - from gcloud.datastore.query import Query - DATASET_ID = 'DATASET' - dataset = self._makeOne(DATASET_ID) - query = dataset.query() - self.assertIsInstance(query, Query) - self.assertTrue(query.dataset() is dataset) - - def test_entity_factory_defaults(self): - from gcloud.datastore.entity import Entity - DATASET_ID = 'DATASET' - KIND = 'KIND' - dataset = self._makeOne(DATASET_ID) - entity = dataset.entity(KIND) - self.assertIsInstance(entity, Entity) - self.assertEqual(entity.kind(), KIND) - self.assertEqual(sorted(entity.exclude_from_indexes()), []) - - def test_entity_factory_explicit(self): - from gcloud.datastore.entity import Entity - DATASET_ID = 'DATASET' - KIND = 'KIND' - dataset = self._makeOne(DATASET_ID) - entity = dataset.entity(KIND, ['foo', 'bar']) - self.assertIsInstance(entity, Entity) - self.assertEqual(entity.kind(), KIND) - self.assertEqual(sorted(entity.exclude_from_indexes()), ['bar', 'foo']) - - def test_transaction_factory(self): - from gcloud.datastore.transaction import Transaction - DATASET_ID = 'DATASET' - dataset = self._makeOne(DATASET_ID) - transaction = dataset.transaction() - self.assertIsInstance(transaction, Transaction) - self.assertTrue(transaction.dataset() is dataset) - def test_get_entity_miss(self): from gcloud.datastore.key import Key DATASET_ID = 'DATASET' diff --git a/regression/datastore.py b/regression/datastore.py index 87b23576c4e68..7dd141b6dfa41 100644 --- a/regression/datastore.py +++ b/regression/datastore.py @@ -18,6 +18,10 @@ import unittest2 from gcloud import datastore +from gcloud.datastore.entity import Entity +from gcloud.datastore.key import Key +from gcloud.datastore.query import Query +from gcloud.datastore.transaction import Transaction # This assumes the command is being run via tox hence the # repository root is the current directory. from regression import populate_datastore @@ -33,7 +37,7 @@ def setUp(self): self.case_entities_to_delete = [] def tearDown(self): - with datastore.transaction.Transaction(): + with Transaction(): for entity in self.case_entities_to_delete: entity.delete() @@ -41,7 +45,7 @@ def tearDown(self): class TestDatastoreAllocateIDs(TestDatastore): def test_allocate_ids(self): - incomplete_key = datastore.key.Key('Kind') + incomplete_key = Key('Kind') num_ids = 10 allocated_keys = datastore.allocate_ids(incomplete_key, num_ids) self.assertEqual(len(allocated_keys), num_ids) @@ -68,7 +72,7 @@ def _get_post(self, name=None, key_id=None, post_content=None): 'rating': 5.0, } # Create an entity with the given content. - entity = datastore.entity.Entity(kind='Post') + entity = Entity(kind='Post') entity.update(post_content) # Update the entity key. @@ -114,7 +118,7 @@ def test_post_with_generated_id(self): self._generic_test_post() def test_save_multiple(self): - with datastore.transaction.Transaction(): + with Transaction(): entity1 = self._get_post() entity1.save() # Register entity to be deleted. @@ -139,23 +143,22 @@ def test_save_multiple(self): self.assertEqual(len(matches), 2) def test_empty_kind(self): - posts = datastore.query.Query(kind='Post').limit(2).fetch() + posts = Query(kind='Post').limit(2).fetch() self.assertEqual(posts, []) class TestDatastoreSaveKeys(TestDatastore): def test_save_key_self_reference(self): - key = datastore.key.Key('Person', 'name') - entity = datastore.entity.Entity(kind=None).key(key) + key = Key('Person', 'name') + entity = Entity.from_key(key) entity['fullName'] = u'Full name' entity['linkedTo'] = key # Self reference. entity.save() self.case_entities_to_delete.append(entity) - query = datastore.query.Query(kind='Person').filter( - 'linkedTo', '=', key).limit(2) + query = Query(kind='Person').filter('linkedTo', '=', key).limit(2) stored_persons = query.fetch() self.assertEqual(len(stored_persons), 1) @@ -172,11 +175,10 @@ class TestDatastoreQuery(TestDatastore): def setUpClass(cls): super(TestDatastoreQuery, cls).setUpClass() cls.CHARACTERS = populate_datastore.CHARACTERS - cls.ANCESTOR_KEY = datastore.key.Key(*populate_datastore.ANCESTOR) + cls.ANCESTOR_KEY = Key(*populate_datastore.ANCESTOR) def _base_query(self): - return datastore.query.Query(kind='Character').ancestor( - self.ANCESTOR_KEY) + return Query(kind='Character').ancestor(self.ANCESTOR_KEY) def test_limit_queries(self): limit = 5 @@ -219,7 +221,7 @@ def test_ancestor_query(self): self.assertEqual(len(entities), expected_matches) def test_query___key___filter(self): - rickard_key = datastore.key.Key(*populate_datastore.RICKARD) + rickard_key = Key(*populate_datastore.RICKARD) query = self._base_query().filter('__key__', '=', rickard_key) expected_matches = 1 @@ -335,11 +337,11 @@ def test_query_group_by(self): class TestDatastoreTransaction(TestDatastore): def test_transaction(self): - key = datastore.key.Key('Company', 'Google') - entity = datastore.entity.Entity(kind=None).key(key) + key = Key('Company', 'Google') + entity = Entity.from_key(key) entity['url'] = u'www.google.com' - with datastore.transaction.Transaction(): + with Transaction(): retrieved_entity = datastore.get_entity(key) if retrieved_entity is None: entity.save()