From 0e625dae1c7a8bd22bce44f473103da88b81e7f4 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Wed, 24 Sep 2014 18:10:35 -0400 Subject: [PATCH] Fix #134: enforce contract that *args must be pairs. --- gcloud/datastore/key.py | 3 +++ gcloud/datastore/test_key.py | 11 +++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gcloud/datastore/key.py b/gcloud/datastore/key.py index 3356acf47562..0ab72bacbcb5 100644 --- a/gcloud/datastore/key.py +++ b/gcloud/datastore/key.py @@ -122,6 +122,9 @@ def from_path(cls, *args, **kwargs): :rtype: :class:`gcloud.datastore.key.Key` :returns: a new `Key` instance """ + if len(args) % 2: + raise ValueError('Must pass an even number of args.') + path = [] items = iter(args) diff --git a/gcloud/datastore/test_key.py b/gcloud/datastore/test_key.py index 5da0f8af19cf..f8c58b26a18f 100644 --- a/gcloud/datastore/test_key.py +++ b/gcloud/datastore/test_key.py @@ -164,12 +164,11 @@ def test_from_path_empty(self): self.assertEqual(key.path(), [{'kind': ''}]) def test_from_path_single_element(self): - # See https://github.com/GoogleCloudPlatform/gcloud-python/issues/134 - key = self._getTargetClass().from_path('abc') - self.assertEqual(key.dataset(), None) - self.assertEqual(key.namespace(), None) - self.assertEqual(key.kind(), '') # XXX s.b. 'abc'? - self.assertEqual(key.path(), [{'kind': ''}]) # XXX s.b. 'abc'? + self.assertRaises(ValueError, self._getTargetClass().from_path, 'abc') + + def test_from_path_three_elements(self): + self.assertRaises(ValueError, self._getTargetClass().from_path, + 'abc', 'def', 'ghi') def test_from_path_two_elements_second_string(self): key = self._getTargetClass().from_path('abc', 'def')