Created
October 21, 2013 09:44
-
-
Save roadsideseb/7081276 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml | |
from boto.mws import response | |
from boto.handler import XmlHandler | |
from boto.mws.connection import MWSConnection | |
from unittest import TestCase | |
NESTED_MEMBER_LIST_XML = """<GetTestResponse> | |
<TestResult> | |
<TestItem> | |
<member> | |
<TestElement>First Element</TestElement> | |
<NestedItem> | |
<member> | |
<NestedTitle>First Title</NestedTitle> | |
</member> | |
<member> | |
<NestedTitle>Second Title</NestedTitle> | |
</member> | |
</NestedItem> | |
</member> | |
<member> | |
<TestElement>Second Element</TestElement> | |
</member> | |
</TestItem> | |
</TestResult> | |
</GetTestResponse>""" | |
MEMBER_LIST_XML = """<GetTestResponse> | |
<TestResult> | |
<TestItem> | |
<member> | |
<TestElement>First Element</TestElement> | |
</member> | |
<member> | |
<TestElement>Second Element</TestElement> | |
</member> | |
</TestItem> | |
</TestResult> | |
</GetTestResponse>""" | |
class TestResponseParser(TestCase): | |
def test_parsing_member_list_response(self): | |
class TestResult(response.ResponseElement): | |
TestItem = response.MemberList() | |
mws = MWSConnection('fake', 'fake') | |
obj = TestResult(mws) | |
h = XmlHandler(obj, mws) | |
xml.sax.parseString(MEMBER_LIST_XML, h) | |
self.assertTrue(hasattr(obj, 'TestItem')) | |
self.assertSequenceEqual( | |
[e.TestElement.text for e in obj.TestItem], | |
['First Element', 'Second Element'], | |
) | |
def test_parsing_nested_member_list_response(self): | |
class TestResult(response.ResponseElement): | |
TestItem = response.MemberList( | |
TestElement=response.Element(), | |
NestedItem=response.MemberList(), | |
) | |
mws = MWSConnection('fake', 'fake') | |
obj = TestResult(mws) | |
h = XmlHandler(obj, mws) | |
xml.sax.parseString(NESTED_MEMBER_LIST_XML, h) | |
self.assertTrue(hasattr(obj, 'TestItem')) | |
self.assertSequenceEqual( | |
[e.TestElement.text for e in obj.TestItem], | |
['First Element', 'Second Element'], | |
) | |
self.assertSequenceEqual( | |
[e.NestedTitle.text for e in obj.TestItem[0].NestedItem], | |
['First Title', 'Second Title'], | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment