@@ -28,9 +28,14 @@ def test_index_attribute_name(self):
2828 assert str (path ) == "'foo.bar'[0]"
2929 assert repr (path ) == "Path(['foo.bar[0]'])"
3030
31+ def test_index_map_attribute (self ):
32+ path = Path (['foo.bar' ])['baz' ]
33+ assert str (path ) == "'foo.bar'.baz"
34+ assert repr (path ) == "Path(['foo.bar', 'baz'])"
35+
3136 def test_index_invalid (self ):
3237 with self .assertRaises (TypeError ):
33- Path ('foo.bar' )['foo' ]
38+ Path ('foo.bar' )[0.0 ]
3439
3540
3641class ActionTestCase (TestCase ):
@@ -326,6 +331,19 @@ def test_dotted_attribute_name(self):
326331 assert placeholder_names == {'foo.bar' : '#0' }
327332 assert expression_attribute_values == {':0' : {'S' : 'baz' }}
328333
334+ def test_map_attribute_indexing (self ):
335+ # Simulate initialization from inside an AttributeContainer
336+ my_map_attribute = MapAttribute (attr_name = 'foo.bar' )
337+ my_map_attribute ._make_attribute ()
338+ my_map_attribute ._update_attribute_paths (my_map_attribute .attr_name )
339+
340+ condition = my_map_attribute ['foo' ] == 'baz'
341+ placeholder_names , expression_attribute_values = {}, {}
342+ expression = condition .serialize (placeholder_names , expression_attribute_values )
343+ assert expression == "#0.#1 = :0"
344+ assert placeholder_names == {'foo.bar' : '#0' , 'foo' : '#1' }
345+ assert expression_attribute_values == {':0' : {'S' : 'baz' }}
346+
329347 def test_map_attribute_dereference (self ):
330348 class MyMapAttribute (MapAttribute ):
331349 nested_string = self .attribute
@@ -342,6 +360,34 @@ class MyMapAttribute(MapAttribute):
342360 assert placeholder_names == {'foo.bar' : '#0' , 'foo' : '#1' }
343361 assert expression_attribute_values == {':0' : {'S' : 'baz' }}
344362
363+ def test_map_attribute_dereference_via_indexing (self ):
364+ class MyMapAttribute (MapAttribute ):
365+ nested_string = self .attribute
366+
367+ # Simulate initialization from inside an AttributeContainer
368+ my_map_attribute = MyMapAttribute (attr_name = 'foo.bar' )
369+ my_map_attribute ._make_attribute ()
370+ my_map_attribute ._update_attribute_paths (my_map_attribute .attr_name )
371+
372+ condition = my_map_attribute ['nested_string' ] == 'baz'
373+ placeholder_names , expression_attribute_values = {}, {}
374+ expression = condition .serialize (placeholder_names , expression_attribute_values )
375+ assert expression == "#0.#1 = :0"
376+ assert placeholder_names == {'foo.bar' : '#0' , 'foo' : '#1' }
377+ assert expression_attribute_values == {':0' : {'S' : 'baz' }}
378+
379+ def test_map_attribute_dereference_via_indexing_missing_attribute (self ):
380+ class MyMapAttribute (MapAttribute ):
381+ nested_string = self .attribute
382+
383+ # Simulate initialization from inside an AttributeContainer
384+ my_map_attribute = MyMapAttribute (attr_name = 'foo.bar' )
385+ my_map_attribute ._make_attribute ()
386+ my_map_attribute ._update_attribute_paths (my_map_attribute .attr_name )
387+
388+ with self .assertRaises (AttributeError ):
389+ my_map_attribute ['missing_attribute' ] == 'baz'
390+
345391
346392class UpdateExpressionTestCase (TestCase ):
347393
0 commit comments