|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +''' |
| 4 | +© 2012-2013 eBay Software Foundation |
| 5 | +Authored by: Tim Keefer |
| 6 | +Licensed under CDDL 1.0 |
| 7 | +''' |
| 8 | + |
| 9 | +from __future__ import absolute_import |
| 10 | +import os |
| 11 | +import unittest |
| 12 | +import re |
| 13 | +from ebaysdk.utils import dict2xml |
| 14 | + |
| 15 | +os.environ.setdefault("EBAY_YAML", "ebay.yaml") |
| 16 | + |
| 17 | + |
| 18 | +class TestBase(unittest.TestCase): |
| 19 | + |
| 20 | + def test_motors_compat_request_xml(self): |
| 21 | + motors_dict = { |
| 22 | + 'Item': { |
| 23 | + 'Category': '101', |
| 24 | + 'Title': 'My Title', |
| 25 | + 'ItemCompatibilityList': { |
| 26 | + 'Compatibility': [ |
| 27 | + { |
| 28 | + 'CompatibilityNotes': 'Fits for all trims and engines.', |
| 29 | + 'NameValueList': [ |
| 30 | + {'Name': 'Year', 'Value': '2001'}, |
| 31 | + {'Name': 'Make', 'Value': 'Honda'}, |
| 32 | + {'Name': 'Model', 'Value': 'Accord'} |
| 33 | + ] |
| 34 | + }, |
| 35 | + ] |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + motors_xml = """<Item> |
| 41 | + <Category>101</Category> |
| 42 | + <ItemCompatibilityList> |
| 43 | + <Compatibility> |
| 44 | + <CompatibilityNotes>Fits for all trims and engines.</CompatibilityNotes> |
| 45 | + <NameValueList> |
| 46 | + <Name>Year</Name><Value>2001</Value> |
| 47 | + </NameValueList> |
| 48 | + <NameValueList> |
| 49 | + <Name>Make</Name><Value>Honda</Value> |
| 50 | + </NameValueList> |
| 51 | + <NameValueList> |
| 52 | + <Name>Model</Name><Value>Accord</Value> |
| 53 | + </NameValueList> |
| 54 | + </Compatibility> |
| 55 | + </ItemCompatibilityList> |
| 56 | + <Title>My Title</Title> |
| 57 | +</Item> |
| 58 | + """ |
| 59 | + |
| 60 | + motors_xml = re.sub(r'>\s+<', '><', motors_xml) |
| 61 | + motors_xml = re.sub(r'\s+$', '', motors_xml) |
| 62 | + |
| 63 | + self.assertEqual(dict2xml(motors_dict), motors_xml) |
| 64 | + |
| 65 | + |
| 66 | +if __name__ == '__main__': |
| 67 | + unittest.main() |
0 commit comments