| Index: third_party/boto/tests/unit/mws/test_response.py
|
| ===================================================================
|
| --- third_party/boto/tests/unit/mws/test_response.py (revision 33376)
|
| +++ third_party/boto/tests/unit/mws/test_response.py (working copy)
|
| @@ -1,4 +1,5 @@
|
| #!/usr/bin/env python
|
| +import unittest
|
| from boto.mws.connection import MWSConnection
|
| from boto.mws.response import (ResponseFactory, ResponseElement, Element,
|
| MemberList, ElementList, SimpleList)
|
| @@ -29,7 +30,7 @@
|
| <Bif>Bam</Bif>
|
| </Item>
|
| </Test9Result></Test9Response>"""
|
| - obj = self.issue_test('Test9', Test9Result, text)
|
| + obj = self.check_issue(Test9Result, text)
|
| Item = obj._result.Item
|
| useful = lambda x: not x[0].startswith('_')
|
| nest = dict(filter(useful, Item.Nest.__dict__.items()))
|
| @@ -59,7 +60,7 @@
|
| <member><Foo>6</Foo><Foo>7</Foo></member>
|
| </Extra>
|
| </Test8Result></Test8Response>"""
|
| - obj = self.issue_test('Test8', Test8Result, text)
|
| + obj = self.check_issue(Test8Result, text)
|
| self.assertSequenceEqual(
|
| map(int, obj._result.Item),
|
| range(4),
|
| @@ -116,7 +117,7 @@
|
| </member>
|
| </Item>
|
| </Test7Result></Test7Response>"""
|
| - obj = self.issue_test('Test7', Test7Result, text)
|
| + obj = self.check_issue(Test7Result, text)
|
| item = obj._result.Item
|
| self.assertEqual(len(item), 3)
|
| nests = [z.Nest for z in filter(lambda x: x.Nest, item)]
|
| @@ -151,7 +152,7 @@
|
| <member><Value>Six</Value></member>
|
| </Item>
|
| </Test6Result></Test6Response>"""
|
| - obj = self.issue_test('Test6', Test6Result, text)
|
| + obj = self.check_issue(Test6Result, text)
|
| self.assertSequenceEqual(
|
| [e.Value for e in obj._result.Item],
|
| ['One', 'Two', 'Six'],
|
| @@ -167,7 +168,7 @@
|
| text = """<Test5Response><Test5Result>
|
| <Item/>
|
| </Test5Result></Test5Response>"""
|
| - obj = self.issue_test('Test5', Test5Result, text)
|
| + obj = self.check_issue(Test5Result, text)
|
| self.assertSequenceEqual(obj._result.Item, [])
|
|
|
| def test_parsing_missing_member_list(self):
|
| @@ -176,7 +177,7 @@
|
|
|
| text = """<Test4Response><Test4Result>
|
| </Test4Result></Test4Response>"""
|
| - obj = self.issue_test('Test4', Test4Result, text)
|
| + obj = self.check_issue(Test4Result, text)
|
| self.assertSequenceEqual(obj._result.Item, [])
|
|
|
| def test_parsing_element_lists(self):
|
| @@ -189,7 +190,7 @@
|
| <Item><Foo>Baz</Foo>
|
| <Zam>Zoo</Zam></Item>
|
| </Test1Result></Test1Response>"""
|
| - obj = self.issue_test('Test1', Test1Result, text)
|
| + obj = self.check_issue(Test1Result, text)
|
| self.assertTrue(len(obj._result.Item) == 3)
|
| elements = lambda x: getattr(x, 'Foo', getattr(x, 'Zip', '?'))
|
| elements = map(elements, obj._result.Item)
|
| @@ -201,7 +202,7 @@
|
|
|
| text = """<Test2Response><Test2Result>
|
| </Test2Result></Test2Response>"""
|
| - obj = self.issue_test('Test2', Test2Result, text)
|
| + obj = self.check_issue(Test2Result, text)
|
| self.assertEqual(obj._result.Item, [])
|
|
|
| def test_parsing_simple_lists(self):
|
| @@ -213,12 +214,14 @@
|
| <Item>Bif</Item>
|
| <Item>Baz</Item>
|
| </Test3Result></Test3Response>"""
|
| - obj = self.issue_test('Test3', Test3Result, text)
|
| + obj = self.check_issue(Test3Result, text)
|
| self.assertSequenceEqual(obj._result.Item, ['Bar', 'Bif', 'Baz'])
|
|
|
| - def issue_test(self, action, klass, text):
|
| - cls = ResponseFactory(action, force=klass)
|
| - return self.service_connection._parse_response(cls, text)
|
| + def check_issue(self, klass, text):
|
| + action = klass.__name__[:-len('Result')]
|
| + factory = ResponseFactory(scopes=[{klass.__name__: klass}])
|
| + parser = factory(action, connection=self.service_connection)
|
| + return self.service_connection._parse_response(parser, 'text/xml', text)
|
|
|
|
|
| if __name__ == "__main__":
|
|
|