From 55808e672f9eb2717b5ced800b92c3cf4932cdb4 Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Wed, 20 Dec 2017 11:43:12 -0800 Subject: [PATCH] Slight re-organization of tests. --- datastore/tests/unit/test_key.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/datastore/tests/unit/test_key.py b/datastore/tests/unit/test_key.py index a9baef71f062..ddd04d161967 100644 --- a/datastore/tests/unit/test_key.py +++ b/datastore/tests/unit/test_key.py @@ -34,12 +34,10 @@ class TestKey(unittest.TestCase): _URLSAFE_FLAT_PATH1 = ('Parent', 59, 'Child', 'Feather') _URLSAFE_EXAMPLE2 = b'agZzfmZpcmVyDwsSBEtpbmQiBVRoaW5nDA' _URLSAFE_APP2 = 's~fire' - _URLSAFE_APP3 = 'sample-app-no-location' - _URLSAFE_LOCATION_PREFIX = 's~' - _URLSAFE_EXAMPLE3 = ( - b'ahhzfnNhbXBsZS1hcHAtbm8tbG9jYXRpb25yHgsSBlBhcmVudBg7DAsSBUNoaWxkIgdG' - b'ZWF0aGVyDKIBBXNwYWNl') _URLSAFE_FLAT_PATH2 = ('Kind', 'Thing') + _URLSAFE_EXAMPLE3 = b'ahhzfnNhbXBsZS1hcHAtbm8tbG9jYXRpb25yCgsSBFpvcnAYWAw' + _URLSAFE_APP3 = 'sample-app-no-location' + _URLSAFE_FLAT_PATH3 = ('Zorp', 88) @staticmethod def _get_target_class(): @@ -415,11 +413,9 @@ def test_to_legacy_urlsafe_strip_padding(self): def test_to_legacy_urlsafe_with_location_prefix(self): key = self._make_one( - *self._URLSAFE_FLAT_PATH1, - project=self._URLSAFE_APP3, - namespace=self._URLSAFE_NAMESPACE1) - # NOTE: ``key.project`` is somewhat "invalid" but that is OK. - urlsafe = key.to_legacy_urlsafe(self._URLSAFE_LOCATION_PREFIX) + *self._URLSAFE_FLAT_PATH3, + project=self._URLSAFE_APP3) + urlsafe = key.to_legacy_urlsafe(location_prefix='s~') self.assertEqual(urlsafe, self._URLSAFE_EXAMPLE3) def test_from_legacy_urlsafe(self): @@ -444,6 +440,15 @@ def test_from_legacy_urlsafe_needs_padding(self): self.assertIsNone(key.namespace) self.assertEqual(key.flat_path, self._URLSAFE_FLAT_PATH2) + def test_from_legacy_urlsafe_with_location_prefix(self): + klass = self._get_target_class() + # Make sure it will have base64 padding added. + key = klass.from_legacy_urlsafe(self._URLSAFE_EXAMPLE3) + + self.assertEqual(key.project, self._URLSAFE_APP3) + self.assertIsNone(key.namespace) + self.assertEqual(key.flat_path, self._URLSAFE_FLAT_PATH3) + def test_is_partial_no_name_or_id(self): key = self._make_one('KIND', project=self._DEFAULT_PROJECT) self.assertTrue(key.is_partial)