Skip to content

Commit

Permalink
Check exclude from indexes type in Entity ctor.
Browse files Browse the repository at this point in the history
Fixes #819.
  • Loading branch information
dhermes committed May 27, 2015
1 parent d77000d commit aa2c138
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gcloud/datastore/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"""Class for representing a single entity in the Cloud Datastore."""


from gcloud._helpers import _ensure_tuple_or_list


class Entity(dict):
"""Entities are akin to rows in a relational database
Expand Down Expand Up @@ -76,7 +79,8 @@ class Entity(dict):
def __init__(self, key=None, exclude_from_indexes=()):
super(Entity, self).__init__()
self.key = key
self._exclude_from_indexes = set(exclude_from_indexes)
self._exclude_from_indexes = set(_ensure_tuple_or_list(
'exclude_from_indexes', exclude_from_indexes))

def __eq__(self, other):
"""Compare two entities for equality.
Expand Down
6 changes: 6 additions & 0 deletions gcloud/datastore/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def test_ctor_explicit(self):
self.assertEqual(sorted(entity.exclude_from_indexes),
sorted(_EXCLUDE_FROM_INDEXES))

def test_ctor_bad_exclude_from_indexes(self):
BAD_EXCLUDE_FROM_INDEXES = object()
key = _Key()
self.assertRaises(TypeError, self._makeOne, key=key,
exclude_from_indexes=BAD_EXCLUDE_FROM_INDEXES)

def test___eq_____ne___w_non_entity(self):
from gcloud.datastore.key import Key
key = Key(_KIND, _ID, dataset_id=_DATASET_ID)
Expand Down

0 comments on commit aa2c138

Please sign in to comment.