<s> from botocore . model import DenormalizedStructureBuilder <EOL> from boto3 . resources . model import ResourceModel , Action , Collection , Waiter <EOL> from tests import BaseTestCase <EOL> class TestModels ( BaseTestCase ) : <EOL> def test_resource_name ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { } , { } ) <EOL> self . assertEqual ( model . name , '<STR_LIT:test>' ) <EOL> def test_resource_shape ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , { } ) <EOL> self . assertEqual ( model . shape , '<STR_LIT>' ) <EOL> def test_resource_identifiers ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> ] <EOL> } , { } ) <EOL> self . assertEqual ( model . identifiers [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( model . identifiers [ <NUM_LIT:1> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( model . identifiers [ <NUM_LIT:1> ] . member_name , '<STR_LIT>' ) <EOL> def test_resource_action_raw ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:target>' : '<STR_LIT>' , '<STR_LIT:source>' : '<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' } <EOL> ] <EOL> } , <EOL> '<STR_LIT:path>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } , { } ) <EOL> self . assertIsInstance ( model . actions , list ) <EOL> self . assertEqual ( len ( model . actions ) , <NUM_LIT:1> ) <EOL> action = model . actions [ <NUM_LIT:0> ] <EOL> self . assertIsInstance ( action , Action ) <EOL> self . assertEqual ( action . request . operation , '<STR_LIT>' ) <EOL> self . assertIsInstance ( action . request . params , list ) <EOL> self . assertEqual ( len ( action . request . params ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( action . request . params [ <NUM_LIT:0> ] . target , '<STR_LIT>' ) <EOL> self . assertEqual ( action . request . params [ <NUM_LIT:0> ] . source , '<STR_LIT>' ) <EOL> self . assertEqual ( action . request . params [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( action . path , '<STR_LIT>' ) <EOL> def test_resource_action_response_resource ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } , { <EOL> '<STR_LIT>' : { } <EOL> } ) <EOL> action = model . actions [ <NUM_LIT:0> ] <EOL> self . assertEqual ( action . resource . type , '<STR_LIT>' ) <EOL> self . assertEqual ( action . resource . path , '<STR_LIT>' ) <EOL> self . assertIsInstance ( action . resource . model , ResourceModel ) <EOL> self . assertEqual ( action . resource . model . name , '<STR_LIT>' ) <EOL> def test_resource_load_action ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT:path>' : '<STR_LIT:$>' <EOL> } <EOL> } , { } ) <EOL> self . assertIsInstance ( model . load , Action ) <EOL> self . assertEqual ( model . load . request . operation , '<STR_LIT>' ) <EOL> self . assertEqual ( model . load . path , '<STR_LIT:$>' ) <EOL> def test_resource_batch_action ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:target>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:source>' : '<STR_LIT>' } <EOL> ] <EOL> } <EOL> } <EOL> } <EOL> } , { } ) <EOL> self . assertIsInstance ( model . batch_actions , list ) <EOL> action = model . batch_actions [ <NUM_LIT:0> ] <EOL> self . assertIsInstance ( action , Action ) <EOL> self . assertEqual ( action . request . operation , '<STR_LIT>' ) <EOL> self . assertEqual ( action . request . params [ <NUM_LIT:0> ] . target , '<STR_LIT>' ) <EOL> def test_sub_resources ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:target>' : '<STR_LIT>' , '<STR_LIT:source>' : '<STR_LIT:input>' } <EOL> ] <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:target>' : '<STR_LIT>' , '<STR_LIT:source>' : '<STR_LIT:input>' } <EOL> ] <EOL> } <EOL> } <EOL> } <EOL> } , { <EOL> '<STR_LIT>' : { } <EOL> } ) <EOL> self . assertIsInstance ( model . subresources , list ) <EOL> self . assertEqual ( len ( model . subresources ) , <NUM_LIT:2> ) <EOL> action = model . subresources [ <NUM_LIT:0> ] <EOL> resource = action . resource <EOL> self . assertIn ( action . name , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( resource . identifiers [ <NUM_LIT:0> ] . target , '<STR_LIT>' ) <EOL> self . assertEqual ( resource . identifiers [ <NUM_LIT:0> ] . source , '<STR_LIT:input>' ) <EOL> self . assertEqual ( resource . type , '<STR_LIT>' ) <EOL> def test_resource_references ( self ) : <EOL> model_def = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:target>' : '<STR_LIT>' , '<STR_LIT:source>' : '<STR_LIT:data>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' } <EOL> ] <EOL> } <EOL> } <EOL> } <EOL> } <EOL> resource_defs = { <EOL> '<STR_LIT>' : { } <EOL> } <EOL> model = ResourceModel ( '<STR_LIT:test>' , model_def , resource_defs ) <EOL> self . assertIsInstance ( model . references , list ) <EOL> self . assertEqual ( len ( model . references ) , <NUM_LIT:1> ) <EOL> ref = model . references [ <NUM_LIT:0> ] <EOL> self . assertEqual ( ref . name , '<STR_LIT>' ) <EOL> self . assertEqual ( ref . resource . type , '<STR_LIT>' ) <EOL> self . assertEqual ( ref . resource . identifiers [ <NUM_LIT:0> ] . target , '<STR_LIT>' ) <EOL> self . assertEqual ( ref . resource . identifiers [ <NUM_LIT:0> ] . source , '<STR_LIT:data>' ) <EOL> self . assertEqual ( ref . resource . identifiers [ <NUM_LIT:0> ] . path , '<STR_LIT>' ) <EOL> def test_resource_collections ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } , { <EOL> '<STR_LIT>' : { } <EOL> } ) <EOL> self . assertIsInstance ( model . collections , list ) <EOL> self . assertEqual ( len ( model . collections ) , <NUM_LIT:1> ) <EOL> self . assertIsInstance ( model . collections [ <NUM_LIT:0> ] , Collection ) <EOL> self . assertEqual ( model . collections [ <NUM_LIT:0> ] . request . operation , '<STR_LIT>' ) <EOL> self . assertEqual ( model . collections [ <NUM_LIT:0> ] . resource . type , '<STR_LIT>' ) <EOL> self . assertEqual ( model . collections [ <NUM_LIT:0> ] . resource . model . name , '<STR_LIT>' ) <EOL> self . assertEqual ( model . collections [ <NUM_LIT:0> ] . resource . path , '<STR_LIT>' ) <EOL> def test_waiter ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:target>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:source>' : '<STR_LIT>' } <EOL> ] <EOL> } <EOL> } <EOL> } , { } ) <EOL> self . assertIsInstance ( model . waiters , list ) <EOL> waiter = model . waiters [ <NUM_LIT:0> ] <EOL> self . assertIsInstance ( waiter , Waiter ) <EOL> self . assertEqual ( waiter . name , '<STR_LIT>' ) <EOL> self . assertEqual ( waiter . waiter_name , '<STR_LIT>' ) <EOL> self . assertEqual ( waiter . params [ <NUM_LIT:0> ] . target , '<STR_LIT>' ) <EOL> class TestRenaming ( BaseTestCase ) : <EOL> def test_multiple ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : [ { '<STR_LIT:name>' : '<STR_LIT>' } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:target>' : '<STR_LIT>' , '<STR_LIT:source>' : '<STR_LIT:data>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' } <EOL> ] <EOL> } <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { } <EOL> } <EOL> } , { <EOL> '<STR_LIT>' : { } <EOL> } ) <EOL> shape = DenormalizedStructureBuilder ( ) . with_members ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' <EOL> } <EOL> } ) . build_model ( ) <EOL> model . load_rename_map ( shape ) <EOL> self . assertEqual ( model . identifiers [ <NUM_LIT:0> ] . name , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( model . actions [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( model . references [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( model . collections [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( model . waiters [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertNotIn ( '<STR_LIT>' , model . get_attributes ( shape ) ) <EOL> self . assertIn ( '<STR_LIT:bar>' , model . get_attributes ( shape ) ) <EOL> def test_meta_beats_identifier ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : [ { '<STR_LIT:name>' : '<STR_LIT:Meta>' } ] <EOL> } , { } ) <EOL> model . load_rename_map ( ) <EOL> self . assertEqual ( model . identifiers [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> def test_load_beats_identifier ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : [ { '<STR_LIT:name>' : '<STR_LIT>' } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } , { } ) <EOL> model . load_rename_map ( ) <EOL> self . assertTrue ( model . load ) <EOL> self . assertEqual ( model . identifiers [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> def test_identifier_beats_action ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : [ { '<STR_LIT:name>' : '<STR_LIT:foo>' } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } , { } ) <EOL> model . load_rename_map ( ) <EOL> self . assertEqual ( model . identifiers [ <NUM_LIT:0> ] . name , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( model . actions [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> def test_action_beats_reference ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:target>' : '<STR_LIT>' , '<STR_LIT:source>' : '<STR_LIT:data>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' } <EOL> ] <EOL> } <EOL> } <EOL> } <EOL> } , { '<STR_LIT>' : { } } ) <EOL> model . load_rename_map ( ) <EOL> self . assertEqual ( model . actions [ <NUM_LIT:0> ] . name , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( model . references [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> def test_reference_beats_collection ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT:target>' : '<STR_LIT>' , '<STR_LIT:source>' : '<STR_LIT:data>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' } <EOL> ] <EOL> } <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } <EOL> } , { '<STR_LIT>' : { } } ) <EOL> model . load_rename_map ( ) <EOL> self . assertEqual ( model . references [ <NUM_LIT:0> ] . name , '<STR_LIT:foo>' ) <EOL> self . assertEqual ( model . collections [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> def test_collection_beats_waiter ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { } <EOL> } <EOL> } , { '<STR_LIT>' : { } } ) <EOL> model . load_rename_map ( ) <EOL> self . assertEqual ( model . collections [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( model . waiters [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> def test_waiter_beats_attribute ( self ) : <EOL> model = ResourceModel ( '<STR_LIT:test>' , { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : { } <EOL> } <EOL> } , { '<STR_LIT>' : { } } ) <EOL> shape = DenormalizedStructureBuilder ( ) . with_members ( { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> } <EOL> } ) . build_model ( ) <EOL> model . load_rename_map ( shape ) <EOL> self . assertEqual ( model . waiters [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , model . get_attributes ( shape ) ) </s>
