<s> from boto . mws . connection import MWSConnection <EOL> from boto . mws . response import ( ResponseFactory , ResponseElement , Element , <EOL> MemberList , ElementList , SimpleList ) <EOL> from tests . unit import AWSMockServiceTestCase <EOL> from boto . compat import filter , map <EOL> from tests . compat import unittest <EOL> class TestMWSResponse ( AWSMockServiceTestCase ) : <EOL> connection_class = MWSConnection <EOL> mws = True <EOL> def test_parsing_nested_elements ( self ) : <EOL> class Test9one ( ResponseElement ) : <EOL> Nest = Element ( ) <EOL> Zoom = Element ( ) <EOL> class Test9Result ( ResponseElement ) : <EOL> Item = Element ( Test9one ) <EOL> text = b"""<STR_LIT>""" <EOL> obj = self . check_issue ( Test9Result , text ) <EOL> Item = obj . _result . Item <EOL> useful = lambda x : not x [ <NUM_LIT:0> ] . startswith ( '<STR_LIT:_>' ) <EOL> nest = dict ( filter ( useful , Item . Nest . __dict__ . items ( ) ) ) <EOL> self . assertEqual ( nest , dict ( Zip = '<STR_LIT>' , Zam = '<STR_LIT>' ) ) <EOL> useful = lambda x : not x [ <NUM_LIT:0> ] . startswith ( '<STR_LIT:_>' ) and not x [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> item = dict ( filter ( useful , Item . __dict__ . items ( ) ) ) <EOL> self . assertEqual ( item , dict ( Foo = '<STR_LIT>' , Bif = '<STR_LIT>' , Zoom = None ) ) <EOL> def test_parsing_member_list_specification ( self ) : <EOL> class Test8extra ( ResponseElement ) : <EOL> Foo = SimpleList ( ) <EOL> class Test8Result ( ResponseElement ) : <EOL> Item = MemberList ( SimpleList ) <EOL> Extra = MemberList ( Test8extra ) <EOL> text = b"""<STR_LIT>""" <EOL> obj = self . check_issue ( Test8Result , text ) <EOL> self . assertSequenceEqual ( <EOL> list ( map ( int , obj . _result . Item ) ) , <EOL> list ( range ( <NUM_LIT:4> ) ) , <EOL> ) <EOL> self . assertSequenceEqual ( <EOL> list ( map ( lambda x : list ( map ( int , x . Foo ) ) , obj . _result . Extra ) ) , <EOL> [ [ <NUM_LIT:4> , <NUM_LIT:5> ] , [ ] , [ <NUM_LIT:6> , <NUM_LIT:7> ] ] , <EOL> ) <EOL> def test_parsing_nested_lists ( self ) : <EOL> class Test7Result ( ResponseElement ) : <EOL> Item = MemberList ( Nest = MemberList ( ) , <EOL> List = ElementList ( Simple = SimpleList ( ) ) ) <EOL> text = b"""<STR_LIT>""" <EOL> obj = self . check_issue ( Test7Result , text ) <EOL> item = obj . _result . Item <EOL> self . assertEqual ( len ( item ) , <NUM_LIT:3> ) <EOL> nests = [ z . Nest for z in filter ( lambda x : x . Nest , item ) ] <EOL> self . assertSequenceEqual ( <EOL> [ [ y . Data for y in nest ] for nest in nests ] , <EOL> [ [ u'<STR_LIT:2>' , u'<STR_LIT:4>' , u'<STR_LIT>' ] , [ u'<STR_LIT:1>' , u'<STR_LIT:3>' , u'<STR_LIT:5>' ] ] , <EOL> ) <EOL> self . assertSequenceEqual ( <EOL> [ element . Simple for element in item [ <NUM_LIT:1> ] . List ] , <EOL> [ [ u'<STR_LIT:4>' , u'<STR_LIT:5>' , u'<STR_LIT>' ] , [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] ] , <EOL> ) <EOL> self . assertSequenceEqual ( <EOL> item [ - <NUM_LIT:1> ] . List [ <NUM_LIT:0> ] . Simple , <EOL> [ '<STR_LIT:1>' , '<STR_LIT:2>' , '<STR_LIT:3>' ] , <EOL> ) <EOL> self . assertEqual ( item [ - <NUM_LIT:1> ] . List [ <NUM_LIT:1> ] . Simple , [ ] ) <EOL> self . assertSequenceEqual ( <EOL> [ e . Value for e in obj . _result . Item ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ) <EOL> def test_parsing_member_list ( self ) : <EOL> class Test6Result ( ResponseElement ) : <EOL> Item = MemberList ( ) <EOL> text = b"""<STR_LIT>""" <EOL> obj = self . check_issue ( Test6Result , text ) <EOL> self . assertSequenceEqual ( <EOL> [ e . Value for e in obj . _result . Item ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ) <EOL> self . assertTrue ( obj . _result . Item [ <NUM_LIT:1> ] . Error == '<STR_LIT>' ) <EOL> with self . assertRaises ( AttributeError ) as e : <EOL> obj . _result . Item [ <NUM_LIT:2> ] . Error <EOL> def test_parsing_empty_member_list ( self ) : <EOL> class Test5Result ( ResponseElement ) : <EOL> Item = MemberList ( Nest = MemberList ( ) ) <EOL> text = b"""<STR_LIT>""" <EOL> obj = self . check_issue ( Test5Result , text ) <EOL> self . assertSequenceEqual ( obj . _result . Item , [ ] ) <EOL> def test_parsing_missing_member_list ( self ) : <EOL> class Test4Result ( ResponseElement ) : <EOL> Item = MemberList ( NestedItem = MemberList ( ) ) <EOL> text = b"""<STR_LIT>""" <EOL> obj = self . check_issue ( Test4Result , text ) <EOL> self . assertSequenceEqual ( obj . _result . Item , [ ] ) <EOL> def test_parsing_element_lists ( self ) : <EOL> class Test1Result ( ResponseElement ) : <EOL> Item = ElementList ( ) <EOL> text = b"""<STR_LIT>""" <EOL> obj = self . check_issue ( Test1Result , text ) <EOL> self . assertTrue ( len ( obj . _result . Item ) == <NUM_LIT:3> ) <EOL> elements = lambda x : getattr ( x , '<STR_LIT>' , getattr ( x , '<STR_LIT>' , '<STR_LIT:?>' ) ) <EOL> elements = list ( map ( elements , obj . _result . Item ) ) <EOL> self . assertSequenceEqual ( elements , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_parsing_missing_lists ( self ) : <EOL> class Test2Result ( ResponseElement ) : <EOL> Item = ElementList ( ) <EOL> text = b"""<STR_LIT>""" <EOL> obj = self . check_issue ( Test2Result , text ) <EOL> self . assertEqual ( obj . _result . Item , [ ] ) <EOL> def test_parsing_simple_lists ( self ) : <EOL> class Test3Result ( ResponseElement ) : <EOL> Item = SimpleList ( ) <EOL> text = b"""<STR_LIT>""" <EOL> obj = self . check_issue ( Test3Result , text ) <EOL> self . assertSequenceEqual ( obj . _result . Item , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def check_issue ( self , klass , text ) : <EOL> action = klass . __name__ [ : - len ( '<STR_LIT>' ) ] <EOL> factory = ResponseFactory ( scopes = [ { klass . __name__ : klass } ] ) <EOL> parser = factory ( action , connection = self . service_connection ) <EOL> return self . service_connection . _parse_response ( parser , '<STR_LIT>' , text ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
