Skip to content

Commit

Permalink
Check exclude from indexes type in Entity ctor.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed May 20, 2015
1 parent 301378f commit 7c9bacb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gcloud/datastore/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,21 @@ class Entity(dict):
:type exclude_from_indexes: tuple of string
:param exclude_from_indexes: Names of fields whose values are not to be
indexed for this entity.
:raises: class:`TypeError` if ``exclude_from_indexes`` is not a tuple or
list.
"""

def __init__(self, key=None, exclude_from_indexes=()):
super(Entity, self).__init__()
self.key = key

# NOTE: This is the same whitelist used for sequence inputs
# in query.py.
if not isinstance(exclude_from_indexes, (tuple, list)):
raise TypeError('Expected exclude_from_indexes to be a tuple or '
'list. Received %r' % (exclude_from_indexes,))

self._exclude_from_indexes = set(exclude_from_indexes)

def __eq__(self, other):
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 7c9bacb

Please sign in to comment.