@@ -35,6 +35,9 @@ class TestKey(unittest.TestCase):
3535 _URLSAFE_EXAMPLE2 = b'agZzfmZpcmVyDwsSBEtpbmQiBVRoaW5nDA'
3636 _URLSAFE_APP2 = 's~fire'
3737 _URLSAFE_FLAT_PATH2 = ('Kind' , 'Thing' )
38+ _URLSAFE_EXAMPLE3 = b'ahhzfnNhbXBsZS1hcHAtbm8tbG9jYXRpb25yCgsSBFpvcnAYWAw'
39+ _URLSAFE_APP3 = 'sample-app-no-location'
40+ _URLSAFE_FLAT_PATH3 = ('Zorp' , 88 )
3841
3942 @staticmethod
4043 def _get_target_class ():
@@ -408,6 +411,13 @@ def test_to_legacy_urlsafe_strip_padding(self):
408411 # Make sure it started with base64 padding.
409412 self .assertNotEqual (len (self ._URLSAFE_EXAMPLE2 ) % 4 , 0 )
410413
414+ def test_to_legacy_urlsafe_with_location_prefix (self ):
415+ key = self ._make_one (
416+ * self ._URLSAFE_FLAT_PATH3 ,
417+ project = self ._URLSAFE_APP3 )
418+ urlsafe = key .to_legacy_urlsafe (location_prefix = 's~' )
419+ self .assertEqual (urlsafe , self ._URLSAFE_EXAMPLE3 )
420+
411421 def test_from_legacy_urlsafe (self ):
412422 klass = self ._get_target_class ()
413423 key = klass .from_legacy_urlsafe (self ._URLSAFE_EXAMPLE1 )
@@ -430,6 +440,15 @@ def test_from_legacy_urlsafe_needs_padding(self):
430440 self .assertIsNone (key .namespace )
431441 self .assertEqual (key .flat_path , self ._URLSAFE_FLAT_PATH2 )
432442
443+ def test_from_legacy_urlsafe_with_location_prefix (self ):
444+ klass = self ._get_target_class ()
445+ # Make sure it will have base64 padding added.
446+ key = klass .from_legacy_urlsafe (self ._URLSAFE_EXAMPLE3 )
447+
448+ self .assertEqual (key .project , self ._URLSAFE_APP3 )
449+ self .assertIsNone (key .namespace )
450+ self .assertEqual (key .flat_path , self ._URLSAFE_FLAT_PATH3 )
451+
433452 def test_is_partial_no_name_or_id (self ):
434453 key = self ._make_one ('KIND' , project = self ._DEFAULT_PROJECT )
435454 self .assertTrue (key .is_partial )
0 commit comments