@@ -1318,6 +1318,61 @@ def test__set_pb_meaning_w_value_unset(orig_meaning):
13181318 assert value_pb .meaning == orig_meaning
13191319
13201320
1321+ def test__set_pb_meaning_w_list_and_single_value ():
1322+ """
1323+ v2.20.2 uses a tuple to represent list meanings (https://github.com/googleapis/python-datastore/pull/575)
1324+
1325+ This check ensures _set_pb_meaning_from_entity is backwards
1326+ compatible with the old meaning style, still used by python-ndb
1327+ """
1328+ from google .cloud .datastore_v1 .types import entity as entity_pb2
1329+ from google .cloud .datastore .helpers import _set_pb_meaning_from_entity
1330+ from google .cloud .datastore .entity import Entity
1331+
1332+ orig_root_meaning = 1
1333+ updated_meaning = 22
1334+ orig_pb = entity_pb2 .Entity ()
1335+ value_pb = orig_pb ._pb .properties .get_or_create ("value" )
1336+ value_pb .meaning = orig_root_meaning
1337+ sub_value_pb1 = value_pb .array_value .values .add ()
1338+ sub_value_pb2 = value_pb .array_value .values .add ()
1339+
1340+ entity = Entity (key = "key" )
1341+ entity ._meanings = {"value" : (updated_meaning , None )}
1342+ _set_pb_meaning_from_entity (entity , "value" , None , value_pb , is_list = True )
1343+ assert value_pb .meaning == orig_root_meaning
1344+ assert sub_value_pb1 .meaning == updated_meaning
1345+ assert sub_value_pb2 .meaning == updated_meaning
1346+
1347+
1348+ def test__set_pb_meaning_w_list_and_list ():
1349+ """
1350+ v2.20.2 uses a tuple to represent list meanings (https://github.com/googleapis/python-datastore/pull/575)
1351+
1352+ This check ensures _set_pb_meaning_from_entity is backwards
1353+ compatible with the old meaning style, still used by python-ndb
1354+ """
1355+ from google .cloud .datastore_v1 .types import entity as entity_pb2
1356+ from google .cloud .datastore .helpers import _set_pb_meaning_from_entity
1357+ from google .cloud .datastore .entity import Entity
1358+
1359+ orig_root_meaning = 1
1360+ updated_meaning_1 = 12
1361+ updated_meaning_2 = 4
1362+ orig_pb = entity_pb2 .Entity ()
1363+ value_pb = orig_pb ._pb .properties .get_or_create ("value" )
1364+ value_pb .meaning = orig_root_meaning
1365+ sub_value_pb1 = value_pb .array_value .values .add ()
1366+ sub_value_pb2 = value_pb .array_value .values .add ()
1367+
1368+ entity = Entity (key = "key" )
1369+ entity ._meanings = {"value" : ([updated_meaning_1 , updated_meaning_2 ], None )}
1370+ _set_pb_meaning_from_entity (entity , "value" , None , value_pb , is_list = True )
1371+ assert value_pb .meaning == orig_root_meaning
1372+ assert sub_value_pb1 .meaning == updated_meaning_1
1373+ assert sub_value_pb2 .meaning == updated_meaning_2
1374+
1375+
13211376def test__array_w_meaning_end_to_end ():
13221377 """
13231378 Test proto->entity->proto with an array with a meaning field
0 commit comments