Exemplo n.º 1
0
def test_order_process():
    @urlmatch(path=r'/services/rest/shipments/v2$')
    def create_shipment_stub(url, request):
        assert request.body == """<?xml version="1.0" encoding="UTF-8"?>
<ShipmentRequest xmlns="https://plazaapi.bol.com/services/xsd/v2/plazaapi.xsd">
    <DateTime>2016-10-01T01:08:17</DateTime>
    <OrderItemId>123</OrderItemId>
    <ShipmentReference>abc</ShipmentReference>
    <Transport>
        <TrackAndTrace>3S123</TrackAndTrace>
        <TransporterCode>GLS</TransporterCode>
    </Transport>
</ShipmentRequest>
"""
        return CREATE_SHIPMENT_RESPONSE

    with HTTMock(create_shipment_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)
        dt = datetime(2016, 10, 1, 1, 8, 17, 0)
        process_status = api.shipments.create(
            order_item_id='123',
            date_time=dt,
            expected_delivery_date=None,
            shipment_reference='abc',
            transporter_code=TransporterCode.GLS,
            track_and_trace='3S123')
        assert process_status.sellerId == 12345678
Exemplo n.º 2
0
def test_order_process():
    @urlmatch(path=r'/services/rest/orders/v1/process$')
    def process_stub(url, request):
        assert request.body == (
            '<?xml version="1.0" encoding="UTF-8"?>'
            '<ProcessOrders xmlns="http://plazaapi.bol.com/services/xsd/plazaapiservice-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://plazaapi.bol.com/services/xsd/plazaapiservice-1.0.xsd">'  # noqa
            '<Shipments>'
            '<Shipment>'
            '<OrderId>123</OrderId>'
            '<DateTime>2015-01-02T12:11:00</DateTime>'
            '<Transporter>'
            '<Code>1234</Code>'
            '<TrackAndTraceCode>DHLFORYOU</TrackAndTraceCode>'
            '</Transporter>'
            '<OrderItems>'
            '<Id>34567</Id>'
            '</OrderItems>'
            '</Shipment>'
            '</Shipments>'
            '</ProcessOrders>')
        return PROCESS_RESPONSE

    with HTTMock(process_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)
        process_id = api.orders.process(order_id='123',
                                        date_time=datetime(
                                            2015, 1, 2, 12, 11, 0),
                                        code='1234',
                                        transporter_code='DHLFORYOU',
                                        order_item_ids=['34567'])
        assert process_id == '123'
Exemplo n.º 3
0
def test_orders():
    with HTTMock(orders_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)
        orders = api.orders.list()
        assert len(orders) == 1

        order = orders[0]
        assert order.OrderId == '123'

        assert order.CustomerDetails.BillingDetails.SalutationCode == 2
        assert order.CustomerDetails.BillingDetails.Firstname == 'Jans'
        assert order.CustomerDetails.BillingDetails.Surname == 'Janssen'
        assert (
            order.CustomerDetails.BillingDetails.Streetname == 'Billingstraat')
        assert order.CustomerDetails.BillingDetails.Housenumber == 1
        assert order.CustomerDetails.BillingDetails.HousenumberExtended == 'a'
        assert (order.CustomerDetails.BillingDetails.AddressSupplement ==
                'Onder de brievenbus')
        assert order.CustomerDetails.BillingDetails.ZipCode == '5000 ZZ'
        assert order.CustomerDetails.BillingDetails.City == 'Amsterdam'
        assert order.CustomerDetails.BillingDetails.CountryCode == 'NL'
        assert order.CustomerDetails.BillingDetails.Email == '*****@*****.**'
        assert (order.CustomerDetails.BillingDetails.DeliveryPhoneNumber ==
                '67890')
        assert order.CustomerDetails.BillingDetails.Company == 'Bol.com'

        assert order.CustomerDetails.ShipmentDetails.SalutationCode == 1
        assert order.CustomerDetails.ShipmentDetails.Firstname == 'Jan'
        assert order.CustomerDetails.ShipmentDetails.Surname == 'Janssen'
        assert (order.CustomerDetails.ShipmentDetails.Streetname ==
                'Shipmentstraat')
        assert order.CustomerDetails.ShipmentDetails.Housenumber == 42
        assert (
            order.CustomerDetails.ShipmentDetails.HousenumberExtended == 'bis')

        assert (order.CustomerDetails.ShipmentDetails.AddressSupplement ==
                '3 hoog achter')
        assert order.CustomerDetails.ShipmentDetails.ZipCode == '1000 AA'
        assert order.CustomerDetails.ShipmentDetails.City == 'Amsterdam'
        assert order.CustomerDetails.ShipmentDetails.CountryCode == 'NL'
        assert (order.CustomerDetails.ShipmentDetails.Email ==
                '*****@*****.**')
        assert (order.CustomerDetails.ShipmentDetails.DeliveryPhoneNumber ==
                '12345')
        assert order.CustomerDetails.ShipmentDetails.Company == 'The Company'

        assert len(order.OrderItems) == 1
        item = order.OrderItems[0]

        assert item.OrderItemId == '123'
        assert item.EAN == '9789062387410'
        assert item.OfferReference == 'PARTNERREF001'
        assert item.Title == 'Regelmaat en Inbakeren'
        assert item.Quantity == 1
        assert item.OfferPrice == Decimal('123.45')
        assert item.PromisedDeliveryDate == 'Binnen 24 uur'
        assert item.TransactionFee == Decimal('19.12')
Exemplo n.º 4
0
def test_get_inventory():
    @urlmatch(path=r'/services/rest/inventory')
    def inventory_stub(url, request):
        return INVENTORY_RESPONSE

    with HTTMock(inventory_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)
        inventory = api.inventory.getInventory(page=1,
                                               quantity="0-250",
                                               state="saleable",
                                               query="0042491966861")

        assert inventory.TotalCount == 144
        offer = inventory.Offers[0]
        assert type(offer.EAN) == str
        assert getattr(offer, "NCK-Stock") == "1"
Exemplo n.º 5
0
def test_payments():
    with HTTMock(payments_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)
        payments = api.payments.list(2015, 1)

        assert len(payments) == 1
        payment = payments[0]
        assert payment.PaymentAmount == Decimal('425.77')
        assert payment.DateTimePayment == datetime(2015, 9, 23, 21, 35, 43)
        assert payment.CreditInvoiceNumber == '123'
        assert len(payment.PaymentShipments) == 1
        shipment = payment.PaymentShipments[0]
        assert shipment.OrderId == '123001'
        assert shipment.ShipmentId == '456'
        assert shipment.PaymentShipmentAmount == Decimal('425.77')
        assert shipment.PaymentStatus == 'FINAL'
Exemplo n.º 6
0
def test_handle_return_items():

    return_no = 0

    @urlmatch(path=r'/services/rest/return-items/v2/65380525/handle$')
    def handle_return_items_stub(url, request):
        return HANDLE_RETURN_ITEMS_RESPONSE[return_no]

    with HTTMock(handle_return_items_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)

        handle_return_item_process = api.return_items.handleReturnItem(
            65380525, 'FAILS_TO_MATCH_RETURN_CONDITIONS', 2)

        assert handle_return_item_process.id, 112748417
        assert handle_return_item_process.eventType == 'HANDLE_RETURN_ITEM'
        assert handle_return_item_process.status == 'PENDING'
Exemplo n.º 7
0
def test_update_transport():
    @urlmatch(path=r'/services/rest/transports/v2/1$')
    def create_transport_stub(url, request):
        assert request.body == """<?xml version="1.0" encoding="UTF-8"?>
<ChangeTransportRequest xmlns=\
"https://plazaapi.bol.com/services/xsd/v2/plazaapi.xsd">
    <TrackAndTrace>3S123</TrackAndTrace>
    <TransporterCode>GLS</TransporterCode>
</ChangeTransportRequest>
"""
        return UPDATE_TRANSPORT_RESPONSE

    with HTTMock(create_transport_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)
        process_status = api.transports.update(
            1, track_and_trace='3S123', transporter_code=TransporterCode.GLS)
        assert process_status.sellerId == 925853
Exemplo n.º 8
0
def test_get_single_inbound():
    @urlmatch(path=r'/services/rest/inbounds/1124284930$')
    def single_inbound_stub(url, request):
        return SINGLE_BOUND_RESPONSE

    with HTTMock(single_inbound_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)
        single_inbound = api.inbounds.getSingleInbound(inbound_id=1124284930)

        assert isinstance(single_inbound.LabellingService, bool)
        product = single_inbound.Products[0]
        assert isinstance(product.AnnouncedQuantity, int)
        assert not isinstance(product.AnnouncedQuantity, str)
        assert not isinstance(product.AnnouncedQuantity, str)
        assert single_inbound.FbbTransporter.Name == "PostNL"
        assert single_inbound.FbbTransporter.Code == "PostNL"
        inboundStat = single_inbound.StateTransitions[0]
        assert inboundStat.State == "ArrivedAtWH"
Exemplo n.º 9
0
def test_get_unhandled_return_items():

    return_no = 0

    @urlmatch(path=r'/services/rest/return-items/v2/unhandled')
    def unhandled_return_items_stub(url, request):
        return UNHANDLED_RETUERN_ITEMS_RESPONSE[return_no]

    with HTTMock(unhandled_return_items_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)

        unhandled_return_items_0 = api.return_items.getUnhandled()

        return_items_0 = unhandled_return_items_0[0]
        assert return_items_0.ReturnNumber, 31234567
        assert return_items_0.OrderId == 4123456789
        assert return_items_0.ShipmentId == 0
        assert return_items_0.EAN == '9781781103524'
        return_items_0_customer = return_items_0.CustomerDetails
        assert return_items_0_customer.FirstName == "Jane"
        assert return_items_0_customer.Surname == "Doe"
        assert return_items_0_customer.ZipCode == "1234 AA"
Exemplo n.º 10
0
def test_shipments():
    with HTTMock(shipments_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)
        shipments = api.shipments.list(1)

        assert len(shipments) == 2
        shipment = shipments[0]
        assert shipment.ShipmentDate == datetime(2016,
                                                 9,
                                                 19,
                                                 18,
                                                 21,
                                                 59,
                                                 324000,
                                                 tzinfo=tzoffset(None, 7200))
        assert shipment.ExpectedDeliveryDate == datetime(2016,
                                                         9,
                                                         19,
                                                         0,
                                                         0,
                                                         tzinfo=tzoffset(
                                                             None, 7200))
Exemplo n.º 11
0
def test_get_delivery_window():
    @urlmatch(path=r'/services/rest/inbounds/delivery-windows$')
    def delivery_window_stub(url, request):
        return DELIVERY_WINDOW_RESPONSE

    with HTTMock(delivery_window_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)

        param_date = '30-01-2017'

        with pytest.raises(TypeError):
            delivery_window = api.inbounds.getDeliveryWindow(
                delivery_date=param_date)

        with pytest.raises(TypeError):
            delivery_window = api.inbounds.getDeliveryWindow(items_to_send=20)

        delivery_window = api.inbounds.getDeliveryWindow(
            delivery_date=param_date, items_to_send=20)

        time_slot_0 = delivery_window[0]
        assert isinstance(time_slot_0.Start, datetime)
        assert isinstance(time_slot_0.End, datetime)
Exemplo n.º 12
0
def test_get_all_inbound():
    @urlmatch(path=r'/services/rest/inbounds$')
    def all_inbound_stub(url, request):
        return ALL_BOUND_RESPONSE

    with HTTMock(all_inbound_stub):
        api = PlazaAPI('api_key', 'api_secret', test=True)
        all_inbound = api.inbounds.getAllInbounds(page=1)

        inbound = all_inbound.AllInbound[0]
        assert isinstance(inbound.Reference, str)
        assert isinstance(inbound.State, str)
        assert inbound.State == "ArrivedAtWH"
        assert inbound.Id == "1124284930"
        assert isinstance(inbound.LabellingService, bool)
        assert not inbound.LabellingService
        assert inbound.AnnouncedBSKUs == 69
        assert inbound.AnnouncedQuantity == 237
        assert inbound.ReceivedBSKUs == 69
        assert inbound.ReceivedQuantity == 240
        assert isinstance(inbound.FbbTransporter.Name, str)
        assert isinstance(inbound.FbbTransporter.Code, str)
        assert inbound.FbbTransporter.Name == "PostNL"
        assert inbound.FbbTransporter.Code == "PostNL"