@@ -4043,6 +4043,12 @@ def test_constructor_key_parts():
40434043 key = key_module .Key ("Model" , 124 )
40444044 assert entity .__dict__ == {"_values" : {}, "_entity_key" : key }
40454045
4046+ @staticmethod
4047+ @pytest .mark .usefixtures ("in_context" )
4048+ def test_constructor_namespace_no_key_parts ():
4049+ entity = model .Model (namespace = "myspace" )
4050+ assert entity .__dict__ == {"_values" : {}}
4051+
40464052 @staticmethod
40474053 @pytest .mark .usefixtures ("in_context" )
40484054 def test_constructor_app ():
@@ -4070,6 +4076,13 @@ def test_constructor_key_and_key_parts():
40704076 with pytest .raises (exceptions .BadArgumentError ):
40714077 model .Model (key = key , id = 124 )
40724078
4079+ @staticmethod
4080+ @pytest .mark .usefixtures ("in_context" )
4081+ def test_constructor_key_and_key_parts_with_namespace ():
4082+ key = key_module .Key ("Foo" , "bar" )
4083+ with pytest .raises (exceptions .BadArgumentError ):
4084+ model .Model (key = key , namespace = "myspace" )
4085+
40734086 @staticmethod
40744087 def test_constructor_user_property_collision ():
40754088 class SecretMap (model .Model ):
@@ -5754,6 +5767,34 @@ def test_get_indexes():
57545767 model .get_indexes ()
57555768
57565769
5770+ @pytest .mark .usefixtures ("in_context" )
5771+ def test_serialization ():
5772+
5773+ # THis is needed because pickle can't serialize local objects
5774+ global SomeKind , OtherKind
5775+
5776+ class OtherKind (model .Model ):
5777+ foo = model .IntegerProperty ()
5778+
5779+ @classmethod
5780+ def _get_kind (cls ):
5781+ return "OtherKind"
5782+
5783+ class SomeKind (model .Model ):
5784+ other = model .StructuredProperty (OtherKind )
5785+
5786+ @classmethod
5787+ def _get_kind (cls ):
5788+ return "SomeKind"
5789+
5790+ entity = SomeKind (
5791+ other = OtherKind (foo = 1 , namespace = "Test" ), namespace = "Test"
5792+ )
5793+ assert entity .other .key is None or entity .other .key .id () is None
5794+ entity = pickle .loads (pickle .dumps (entity ))
5795+ assert entity .other .foo == 1
5796+
5797+
57575798def ManyFieldsFactory ():
57585799 """Model type class factory.
57595800
0 commit comments