Commit 8ebed1e6 authored by Raul Granados's avatar Raul Granados

create address, shipments quotes, shipments purchase, purchase ok and add doc

parent 869121cd
......@@ -12,6 +12,108 @@ NOTE: The Wrapper by default use api base of Mienvio
You can test the mienvio library with nose from the mienvio library root:
## Create addresses
```python
import mienvio
mienvio.api_key = 'api_key'
mienvio.sandbox = True
address_object = {
"object_type": "FROMTO",
"name": "Cirilo",
"street": "Salustio Amezcua #7 int 1",
"street2": "Blvd. Lazaro Cardenas",
"reference ": "Puerta blanca a lado de taller de llaves",
"zipcode": "59514",
"email": "frida@xxx.com",
"phone": "3333333333",
"bookmark": False,
"alias": "Casa de dante",
}
address = mienvio.Addresses.create(address_object)
print(address.object_id)
```
## Create shipment quote
```python
import mienvio
mienvio.api_key = 'api_key'
mienvio.sandbox = True
shipment_quote_object = {
"object_purpose": "QUOTE",
"zipcode_from": 59033,
"zipcode_to": 59514,
"weight": 5,
"length": 3.1,
"height": 5.0,
"width": 3.1,
"description": "Test",
}
shipment = mienvio.Shipments.create(shipment_quote_object)
rates = mienvio.Shipments.rates(shipment.object_id)
print(rates)
```
## Create shipment purchase
```python
import mienvio
mienvio.api_key = 'api_key'
mienvio.sandbox = True
shipment_purchase_object = {
"object_purpose": "PURCHASE",
"address_from": 57608,
"address_to": 57609,
"weight": 5,
"length": 3.1,
"height": 5.0,
"width": 3.1,
"description": "Test",
"rate": 952
}
# create shipment type purchase
shipment = mienvio.Shipments.create(shipment_purchase_object)
purchase_object = {
"shipments": [shipment.object_id]
}
# create purchase
purchase = mienvio.Purchases.create(purchase_object)
```
## Get data
```python
import mienvio
mienvio.api_key = 'api_key'
mienvio.sandbox = True
# get objects list
addresses = mienvio.Addresses.all(params={'limit': 10, 'page': 1})
shipments = mienvio.Shipments.all(params={'limit': 10, 'page': 1})
purchases = mienvio.Purchases.all(params={'limit': 10, 'page': 1})
# Retrieve object
address = mienvio.Addresses.retrieve('object_id_address')
shipment = mienvio.Shipments.retrieve('object_id_shipment')
purchase = mienvio.Purchases.retrieve('object_id_purchase')
```
```sh
$ nosetests
For TestCase
$ nosetests addresses.py
```
......@@ -171,6 +171,10 @@ class Shipments(Mienvio):
"""
first_key = 'shipment'
@classmethod
def rates(cls, shipment_id):
return cls.build_http_request('get', '{}/{}/rates'.format(cls.__name__.lower(), shipment_id))
class Purchases(Mienvio):
"""
......
......@@ -9,14 +9,41 @@ class BaseEndpointTestCase(unittest.TestCase):
client = mienvio
address_object = {
"object_type": "PURCHASE",
"object_type": "FROMTO",
"name": "Cirilo",
"street": "Salustio Amezcua #7 int 1",
"street2": "Blvd. Lazaro Cardenas",
"reference ": "Puerta blanca a lado de taller de llaves",
"zipcode": "59033",
"email": "cirilo@xxx.com",
"zipcode": "59514",
"email": "frida@xxx.com",
"phone": "3333333333",
"bookmark": True,
"alias": "Oficina",
"bookmark": False,
"alias": "Casa de dante",
}
shipment_quote_object = {
"object_purpose": "QUOTE",
"zipcode_from": 59033,
"zipcode_to": 59514,
"weight": 5,
"length": 3.1,
"height": 5.0,
"width": 3.1,
"description": "Test",
}
shipment_purchase_object = {
"object_purpose": "PURCHASE",
"address_from": 57608,
"address_to": 57609,
"weight": 5,
"length": 3.1,
"height": 5.0,
"width": 3.1,
"description": "Test",
"rate": 952
}
purchase_object = {
"shipments": [37021]
}
......@@ -4,13 +4,13 @@ from . import BaseEndpointTestCase
class AddressesEndPintTestCase(BaseEndpointTestCase):
def test_create_address(self):
self.client.api_key = 'set_api_key'
self.client.api_key = 'api_key'
self.client.sandbox = True
address = self.client.Addresses.create(self.address_object)
assert address.object_id
def test_get_all_address(self):
self.client.api_key = 'set_api_key'
self.client.api_key = 'api_key'
self.client.sandbox = True
addresses = self.client.Addresses.all()
assert len(addresses) > 0
from . import BaseEndpointTestCase
class ShipmentsEndPintTestCase(BaseEndpointTestCase):
def test_create_purchase(self):
self.client.api_key = 'api_key'
self.client.sandbox = True
shipment = self.client.Purchases.create(self.purchase_object)
assert shipment.object_id
def test_get_all_purchase(self):
self.client.api_key = 'api_key'
self.client.sandbox = True
shipments = self.client.Purchases.all()
assert len(shipments) > 0
from . import BaseEndpointTestCase
class ShipmentsEndPintTestCase(BaseEndpointTestCase):
def test_create_shipment_quote(self):
self.client.api_key = 'api_key'
self.client.sandbox = True
shipment = self.client.Shipments.create(self.shipment_quote_object)
assert shipment.object_id
def test_create_shipment_purchase(self):
self.client.api_key = 'api_key'
self.client.sandbox = True
shipment = self.client.Shipments.create(self.shipment_purchase_object)
assert shipment.object_id
def test_get_all_shipment_rates(self):
self.client.api_key = 'api_key'
self.client.sandbox = True
rates = self.client.Shipments.rates(37014)
assert len(rates) > 0
def test_get_all_shipment(self):
self.client.api_key = 'api_key'
self.client.sandbox = True
shipments = self.client.Shipments.all()
assert len(shipments) > 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