def testboolean(self): '''boolean dump and load''' obj = {'bool': True} xml = '<bool>true</bool>' self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True)) obj = {'bool': False} xml = '<bool>false</bool>' self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testboolean(self): """boolean dump and load""" obj = {"bool": True} xml = "<bool>true</bool>" self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True)) obj = {"bool": False} xml = "<bool>false</bool>" self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testwrap(self): '''wrap an arbitrary object in a parent tag''' obj = {'one': 'two', 'three': ['four', 'five']} xml = ('<wrapper><one>two</one>' '<three>four</three><three>five</three></wrapper>') self.assertEqual(obj, xon.loads(xml, unwrap=True)) self.assertEqual(xml, xon.dumps(obj, wrap='wrapper'))
def testwrap(self): '''wrap an arbitrary object in a parent tag''' obj = {'one': 'two', 'three': ['four', 'five']} xml = ('<wrapper><three>four</three><three>five</three>' '<one>two</one></wrapper>') self.assertEqual(obj, xon.loads(xml, unwrap=True)) self.assertEqual(xml, xon.dumps(obj, wrap='wrapper'))
def method_call(self, method_calls): api_dict = { 'api': { 'authentication': { 'api_key': self.api_key, 'shared_secret': self.api_secret, }, 'data': method_calls, }, } request_xml = xon.dumps(api_dict) self.last_request = request_xml params = urllib.urlencode({'data': request_xml,}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} url = 'https://echo.bluehornet.com/api/xmlrpc/index.php' request = urllib2.Request(url, params, headers) response = urllib2.urlopen(request) response_xml = response.read() return xon.loads(response_xml)
def method_call(self, method_calls): api_dict = { 'api': { 'authentication': { 'api_key': self.api_key, 'shared_secret': self.api_secret, }, 'data': method_calls, }, } request_xml = xon.dumps(api_dict) self.last_request = request_xml params = urllib.urlencode({ 'data': request_xml, }) headers = { "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain" } url = 'https://echo.bluehornet.com/api/xmlrpc/index.php' request = urllib2.Request(url, params, headers) response = urllib2.urlopen(request) response_xml = response.read() return xon.loads(response_xml)
def testfloat(self): '''float dump and load''' obj = {'float': 123.456} xml = '<float>123.456</float>' self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testfloat(self): """float dump and load""" obj = {"float": 123.456} xml = "<float>123.456</float>" self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testint(self): """integer dump and load""" obj = {"int": 10} xml = "<int>10</int>" self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testroundtrip(self): """roundtrip objects to XON and back""" for obj, xml in self.dumps: self.assertEqual(obj, xon.loads(xon.dumps(obj)))
def testdumps(self): """dumping of objects to XON strings""" for obj, xml in self.dumps: self.assertEqual(xon.dumps(obj), xml)
def testunicode(self): '''unicode string dump and load''' obj = {'unicode': u'a string\u2014in Unicode'} xml = '<unicode>a string—in Unicode</unicode>' self.assertEqual(obj, xon.loads(xml)) self.assertEqual(xml, xon.dumps(obj))
def testunicode(self): """unicode string dump and load""" obj = {"unicode": u"a string\u2014in Unicode"} xml = "<unicode>a string—in Unicode</unicode>" self.assertEqual(obj, xon.loads(xml)) self.assertEqual(xml, xon.dumps(obj))
def testint(self): '''integer dump and load''' obj = {'int': 10} xml = '<int>10</int>' self.assertEqual(obj, xon.loads(xml, convertvalues=True)) self.assertEqual(xml, xon.dumps(obj, convertvalues=True))
def testroundtrip(self): '''roundtrip objects to XON and back''' for obj, xml in self.dumps: self.assertEqual(obj, xon.loads(xon.dumps(obj)))
def testdumps(self): '''dumping of objects to XON strings''' for obj, xml in self.dumps: self.assertEqual(xon.dumps(obj), xml)
def testwrap(self): """wrap an arbitrary object in a parent tag""" obj = {"one": "two", "three": ["four", "five"]} xml = "<wrapper><one>two</one>" "<three>four</three><three>five</three></wrapper>" self.assertEqual(obj, xon.loads(xml, unwrap=True)) self.assertEqual(xml, xon.dumps(obj, wrap="wrapper"))