Commit 52354ef2 authored by Raul Granados's avatar Raul Granados

fix build headers

parent a608643a
......@@ -16,13 +16,6 @@ sandbox = False
api_key = None
API_BASE = 'https://app.mienvio.mx/api/'
HEADERS = {
'Authorization': 'Bearer %s' % api_key,
'content-type': 'application/json'
}
class MienvioError(Exception):
def __init__(self, error_json):
......@@ -70,9 +63,18 @@ class Mienvio:
:return:
"""
api_base = 'http://pruebas.mienvio.mx/api/' if sandbox else 'https://app.mienvio.mx/api/'
print(api_base)
headers = {
'Authorization': 'Bearer {}'.format(api_key),
'content-type': 'application/json'
}
try:
body = request(
method, '{}{}'.format(API_BASE, path), data=json.dumps(payload), params=params, headers=HEADERS
method, '{}{}'.format(api_base, path), data=json.dumps(payload), params=params, headers=headers
)
except Exception:
raise ApiError({'error': 'Service not available'})
......@@ -82,6 +84,7 @@ class Mienvio:
if body.status_code == 400:
raise MalformedRequestError(body.json())
elif body.status_code == 401:
print(body.text)
raise AuthenticationError(body.json())
elif body.status_code == 402:
raise ProcessingError(body.json())
......
......@@ -19,4 +19,4 @@ class BaseEndpointTestCase(unittest.TestCase):
"phone": "3333333333",
"bookmark": True,
"alias": "Oficina",
}
\ No newline at end of file
}
from . import BaseEndpointTestCase
class AddressesEndPintTestCase(BaseEndpointTestCase):
def test_create_address(self):
self.client.api_key = 'set_api_key'
self.client.sandbox = True
address = self.client.Addresses.create(self.address_object)
assert address.address['object_id']
def test_get_all_address(self):
self.client.api_key = 'set_api_key'
self.client.sandbox = True
addresses = self.client.Addresses.all()
assert len(addresses) > 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment