Convert bytes to request and pass tests

This commit is contained in:
Raimon Esteve 2020-10-04 16:31:32 +02:00
parent e67db95e11
commit 97b2c50887
2 changed files with 13 additions and 13 deletions

View File

@ -66,7 +66,7 @@ class API(object):
'Content-Type': 'text/xml; charset=utf-8', 'Content-Type': 'text/xml; charset=utf-8',
'Content-Length': len(xml), 'Content-Length': len(xml),
} }
rqst = request.Request(self.url, xml, headers) rqst = request.Request(self.url, bytes(xml.encode('utf-8')), headers)
try: try:
response = request.urlopen(rqst) response = request.urlopen(rqst)
return response.read() return response.read()

24
test.py
View File

@ -6,20 +6,20 @@ from seurvalencia.picking import *
from seurvalencia.utils import services from seurvalencia.utils import services
from base64 import decodestring from base64 import decodestring
print "Seur services" print("Seur services")
services = services() services = services()
print services print(services)
with API(username, password, debug=debug) as seurvalencia_api: with API(username, password, debug=debug) as seurvalencia_api:
print "Test connection" print("Test connection")
print seurvalencia_api.test_connection() print(seurvalencia_api.test_connection())
print "Get cities by zip" print("Get cities by zip")
print seurvalencia_api.get_city('08720') print(seurvalencia_api.get_city('08720'))
with Picking(username, password, debug=debug) as picking_api: with Picking(username, password, debug=debug) as picking_api:
print "Send a new shipment" print("Send a new shipment")
data = {} data = {}
#~ data['adn_aduana_destino'] = '' #~ data['adn_aduana_destino'] = ''
@ -101,19 +101,19 @@ with Picking(username, password, debug=debug) as picking_api:
reference, label, error = picking_api.create(data) reference, label, error = picking_api.create(data)
print reference print(reference)
if error: if error:
print error print(error)
file = open("/tmp/seur-valencia.txt", "w") file = open("/tmp/seur-valencia.txt", "w")
file.write(label) file.write(label)
file.close() file.close()
print "Generated label file in /tmp/seur-valencia.txt" print("Generated label file in /tmp/seur-valencia.txt")
print "Picking PDF deliveried" print("Picking PDF deliveried")
pdf = picking_api.info() pdf = picking_api.info()
file = open("/tmp/seur-valencia.pdf", "w") file = open("/tmp/seur-valencia.pdf", "w")
file.write(pdf) file.write(pdf)
file.close() file.close()
print "Generated PDF deliveries in /tmp/seur-valencia.pdf" print("Generated PDF deliveries in /tmp/seur-valencia.pdf")