Last active
August 29, 2015 14:08
-
-
Save michaelrice/b479bfa98e494b5938ac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| from __future__ import unicode_literals | |
| from xml.etree.ElementTree import Element | |
| from xml.etree.ElementTree import SubElement | |
| from xml.etree.ElementTree import tostring | |
| def _build_customer_payload(customer): | |
| """ | |
| <customer xmlns="http://www.vmware.com/UM"> | |
| <name>Customer Name</name> | |
| <country>US</country> | |
| <postalCode>90210</postalCode> | |
| </customer> | |
| """ | |
| if not 'country' in customer: | |
| raise MissingProperty("Missing required 'country'.") | |
| if not 'name' in customer: | |
| raise MissingProperty("Missing required 'name'") | |
| if not 'postal_code' in customer: | |
| raise MissingProperty("Missing required 'postal_code'") | |
| attribs = { | |
| 'xmlns': 'http://www.vmware.com/UM' | |
| } | |
| root = Element('customer', attribs) | |
| name = SubElement(root, 'name') | |
| name.text = customer['name'] | |
| country = SubElement(root, 'country') | |
| country.text = customer['country'] | |
| postal = SubElement(root, 'postalCode') | |
| postal.text = customer['postal_code'] | |
| return tostring(root) | |
| ################### | |
| # Method from my test | |
| def test_customer_builder(self): | |
| customer = { | |
| 'country': 'US', | |
| 'name': '¿Cómo', | |
| 'postal_code': '78555' | |
| } | |
| xml = customers._build_customer_payload(customer) | |
| self.assertIsInstance(xml, str) |
Author
michaelrice
commented
Oct 25, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment