Exemple #1
0
    def test_order_payload(self):
        self.maxDiff = None
        order = TestOrderFactory()

        callback_url = "https://example.com/shop/fulfilment/six/{id}/{hash}/".format(
            id=order.id,
            hash=order.verification_hash
        )

        self.assertEqual(json.loads(order_payload(order)), {
            u"api_key": u"",
            u"test": True,
            u"allow_preorder": False,
            u"update_stock": True,

            u"order": {
                u"client_ref": order.id,
                u"po_number": order.id,
                u"date_placed": unicode(order.time_stamp),
                u"callback_url": callback_url,
                u"postage_speed": 2,
                u"postage_cost": float_price(order.shipping_cost),
                u"total_amount": float_price(order.sub_total),
                u"signed_for": False,
                u"tracked": False,
                u"ShippingContact": {
                    u"dear": order.contact.user.first_name,
                    u"name": order.ship_addressee,
                    u"email": order.contact.user.email,
                    u"phone": order.contact.primary_phone or u"",
                    u"address": order.ship_street1,
                    u"address_contd": order.ship_street2,
                    u"city": order.ship_city,
                    u"county": order.ship_state,
                    u"country": unicode(order.ship_country),
                    u"postcode": order.ship_postal_code,
                },
                u"BillingContact": {
                    u"name": order.bill_addressee,
                    u"email": order.contact.user.email,
                    u"phone": order.contact.primary_phone or u"",
                    u"address": order.bill_street1,
                    u"address_contd": order.bill_street2,
                    u"city": order.bill_city,
                    u"county": order.bill_state,
                    u"country": unicode(order.bill_country),
                    u"postcode": order.bill_postal_code,
                },
                u"items": [
                    {
                        u"client_ref": order.orderitem_set.all()[0].product.slug,
                        u"quantity": order.orderitem_set.all()[0].quantity,
                        u"price": float_price(order.orderitem_set.all()[0].unit_price),
                    }
                ]
            }
        })
Exemple #2
0
    def test__web_client(self):
        order = TestOrderFactory()
        data = {
            "type": "despatch",
            "client_ref": str(order.id),
            "date_despatched": str(timezone.now()),
            "client_area_link": "http://subdomain.sixworks.co.uk/order/101",
            "postage_method": "1st Class Packet",
            "postage_cost": str(float_price(order.shipping_cost)),
            "boxed_weight": 645,
            "tracking_number": "GB1010101010A",
            "tracking_link": "http://royalmail.com/track?tracking_number=GB1010101010A",
            "items": [{
                "client_ref": order.orderitem_set.all()[0].product.slug,
                "quantity": order.orderitem_set.all()[0].quantity,
                "batches_used": [
                    {
                        "client_ref": order.orderitem_set.all()[0].product.slug,
                        "batch": "0014",
                        "quantity": order.orderitem_set.all()[0].quantity
                    },
                ]
            }],
        }
        response = self.client.post(reverse("six_despatch", kwargs={
            "order_id": str(order.id),
            "verification_hash": str(order.verification_hash),
        }), data=json.dumps(data), content_type="application/json")
        self.assertEqual(response.content, '{"success": true}')
        order = Order.objects.get(id=order.id)
        self.assertIn(data["date_despatched"], order.notes)
        self.assertIn(data["client_area_link"], order.notes)
        self.assertIn(data["postage_method"], order.notes)
        self.assertIn(data["postage_cost"], order.notes)
        self.assertIn(str(data["boxed_weight"]), order.notes)

        self.assertEqual(order.tracking_number, data["tracking_number"])
        self.assertEqual(order.tracking_url, data["tracking_link"])

        order_status = u"""Thanks for your order!\nYour tracking number is: {tracking_number}\nYou can track your order at {tracking_url}\n"""
        self.assertEqual(order.status.notes, order_status.format(
            tracking_number=order.tracking_number,
            tracking_url=order.tracking_url,
        ))
Exemple #3
0
    def test_order_payload(self):
        self.maxDiff = None
        order = TestOrderFactory()

        callback_url = external_url(
            "{root}/fulfilment/six/{id}/{hash}/".format(
                root=get_satchmo_setting("SHOP_BASE"),
                id=order.id,
                hash=order.verification_hash,
            )
        )

        self.assertEqual(
            json.loads(order_payload(order)),
            {
                "api_key": "",
                "test": True,
                "allow_preorder": False,
                "update_stock": True,
                "order": {
                    "client_ref": order.id,
                    "po_number": order.id,
                    "date_placed": str(order.time_stamp),
                    "callback_url": callback_url,
                    "postage_speed": 2,
                    "postage_cost": float_price(order.shipping_cost),
                    "total_amount": float_price(order.sub_total),
                    "signed_for": False,
                    "tracked": False,
                    "ShippingContact": {
                        "dear": order.contact.user.first_name,
                        "name": order.ship_addressee,
                        "email": order.contact.user.email,
                        "phone": order.contact.primary_phone or "",
                        "address": order.ship_street1,
                        "address_contd": order.ship_street2,
                        "city": order.ship_city,
                        "county": order.ship_state,
                        "country": str(order.ship_country),
                        "postcode": order.ship_postal_code,
                    },
                    "BillingContact": {
                        "name": order.bill_addressee,
                        "email": order.contact.user.email,
                        "phone": order.contact.primary_phone or "",
                        "address": order.bill_street1,
                        "address_contd": order.bill_street2,
                        "city": order.bill_city,
                        "county": order.bill_state,
                        "country": str(order.bill_country),
                        "postcode": order.bill_postal_code,
                    },
                    "items": [
                        {
                            "client_ref": order.orderitem_set.all()[0].product.slug,
                            "quantity": order.orderitem_set.all()[0].quantity,
                            "price": float_price(
                                order.orderitem_set.all()[0].unit_price
                            ),
                        }
                    ],
                },
            },
        )
Exemple #4
0
 def test_float_price__none(self):
     self.assertEqual(0.0, float_price(None))
Exemple #5
0
 def test_float_price__zero(self):
     self.assertEqual(0.0, float_price(Decimal("0.00")))
Exemple #6
0
 def test_float_price(self):
     self.assertEqual(15.25, float_price(Decimal("15.25")))
Exemple #7
0
    def test__web_client(self):
        order = TestOrderFactory()
        data = {
            "type":
            "despatch",
            "client_ref":
            str(order.id),
            "date_despatched":
            str(timezone.now()),
            "client_area_link":
            "http://subdomain.sixworks.co.uk/order/101",
            "postage_method":
            "1st Class Packet",
            "postage_cost":
            str(float_price(order.shipping_cost)),
            "boxed_weight":
            645,
            "tracking_number":
            "GB1010101010A",
            "tracking_link":
            "http://royalmail.com/track?tracking_number=GB1010101010A",
            "items": [{
                "client_ref":
                order.orderitem_set.all()[0].product.slug,
                "quantity":
                order.orderitem_set.all()[0].quantity,
                "batches_used": [{
                    "client_ref":
                    order.orderitem_set.all()[0].product.slug,
                    "batch":
                    "0014",
                    "quantity":
                    order.orderitem_set.all()[0].quantity,
                }],
            }],
        }
        response = self.client.post(
            reverse(
                "six_despatch",
                kwargs={
                    "order_id": str(order.id),
                    "verification_hash": str(order.verification_hash),
                },
            ),
            data=json.dumps(data),
            content_type="application/json",
        )
        self.assertEqual(response.content, '{"success": true}'.encode("utf-8"))
        order = Order.objects.get(id=order.id)
        self.assertIn(data["date_despatched"], order.notes)
        self.assertIn(data["client_area_link"], order.notes)
        self.assertIn(data["postage_method"], order.notes)
        self.assertIn(data["postage_cost"], order.notes)
        self.assertIn(str(data["boxed_weight"]), order.notes)

        self.assertEqual(order.tracking_number, data["tracking_number"])
        self.assertEqual(order.tracking_url, data["tracking_link"])

        order_status = (
            """Thanks for your order!\nYou can track your order at {tracking_url}\n"""
        )
        self.assertEqual(
            order.status.notes,
            order_status.format(tracking_number=order.tracking_number,
                                tracking_url=order.tracking_url),
        )
Exemple #8
0
    def test_order_payload(self):
        self.maxDiff = None
        order = TestOrderFactory()

        callback_url = "https://example.com/shop/fulfilment/six/{id}/{hash}/".format(
            id=order.id, hash=order.verification_hash)

        self.assertEqual(
            json.loads(order_payload(order)), {
                u"api_key": u"",
                u"test": True,
                u"allow_preorder": False,
                u"update_stock": True,
                u"order": {
                    u"client_ref":
                    order.id,
                    u"po_number":
                    order.id,
                    u"date_placed":
                    unicode(order.time_stamp),
                    u"callback_url":
                    callback_url,
                    u"postage_speed":
                    2,
                    u"postage_cost":
                    float_price(order.shipping_cost),
                    u"total_amount":
                    float_price(order.sub_total),
                    u"signed_for":
                    False,
                    u"tracked":
                    False,
                    u"ShippingContact": {
                        u"dear": order.contact.user.first_name,
                        u"name": order.ship_addressee,
                        u"email": order.contact.user.email,
                        u"phone": order.contact.primary_phone or u"",
                        u"address": order.ship_street1,
                        u"address_contd": order.ship_street2,
                        u"city": order.ship_city,
                        u"county": order.ship_state,
                        u"country": unicode(order.ship_country),
                        u"postcode": order.ship_postal_code,
                    },
                    u"BillingContact": {
                        u"name": order.bill_addressee,
                        u"email": order.contact.user.email,
                        u"phone": order.contact.primary_phone or u"",
                        u"address": order.bill_street1,
                        u"address_contd": order.bill_street2,
                        u"city": order.bill_city,
                        u"county": order.bill_state,
                        u"country": unicode(order.bill_country),
                        u"postcode": order.bill_postal_code,
                    },
                    u"items": [{
                        u"client_ref":
                        order.orderitem_set.all()[0].product.slug,
                        u"quantity":
                        order.orderitem_set.all()[0].quantity,
                        u"price":
                        float_price(order.orderitem_set.all()[0].unit_price),
                    }]
                }
            })