def test_order(self):
        with open(
                os.path.join(
                    os.path.dirname(__file__), "test_data",
                    "woocommerce_customer.json")) as woocommerce_customer:
            woocommerce_customer = json.load(woocommerce_customer)

        create_customer(woocommerce_customer.get("customer"), [])

        with open(
                os.path.join(os.path.dirname(__file__), "test_data",
                             "woocommerce_item.json")) as woocommerce_item:
            woocommerce_item = json.load(woocommerce_item)

        make_item("_Test Warehouse - _TC", woocommerce_item.get("product"), [])

        with open(
                os.path.join(os.path.dirname(__file__), "test_data",
                             "woocommerce_order.json")) as woocommerce_order:
            woocommerce_order = json.load(woocommerce_order)

        woocommerce_settings = frappe.get_doc("woocommerce Settings",
                                              "woocommerce Settings")

        create_order(woocommerce_order.get("order"), woocommerce_settings,
                     "_Test Company")

        sales_order = frappe.get_doc("Sales Order", {
            "woocommerce_order_id":
            cstr(woocommerce_order.get("order").get("id"))
        })

        self.assertEqual(cstr(woocommerce_order.get("order").get("id")),
                         sales_order.woocommerce_order_id)

        #check for customer
        woocommerce_order_customer_id = cstr(
            woocommerce_order.get("order").get("customer").get("id"))
        sales_order_customer_id = frappe.get_value("Customer",
                                                   sales_order.customer,
                                                   "woocommerce_customer_id")

        self.assertEqual(woocommerce_order_customer_id,
                         sales_order_customer_id)

        #check sales invoice
        sales_invoice = frappe.get_doc(
            "Sales Invoice",
            {"woocommerce_order_id": sales_order.woocommerce_order_id})
        self.assertEqual(sales_invoice.rounded_total,
                         sales_order.rounded_total)

        #check delivery note
        delivery_note_count = frappe.db.sql(
            """select count(*) from `tabDelivery Note`
			where woocommerce_order_id = %s""", sales_order.woocommerce_order_id)[0][0]

        self.assertEqual(
            delivery_note_count,
            len(woocommerce_order.get("order").get("fulfillments")))
    def test_customer(self):
        with open(
                os.path.join(
                    os.path.dirname(__file__), "test_data",
                    "woocommerce_customer.json")) as woocommerce_customer:
            woocommerce_customer = json.load(woocommerce_customer)

        create_customer(woocommerce_customer.get("customer"), [])

        customer = frappe.get_doc(
            "Customer", {
                "woocommerce_customer_id":
                cstr(woocommerce_customer.get("customer").get("id"))
            })

        self.assertEqual(customer.sync_with_woocommerce, 1)

        woocommerce_address = woocommerce_customer.get("customer").get(
            "addresses")[0]
        address = frappe.get_doc("Address", {"customer": customer.name})

        self.assertEqual(cstr(woocommerce_address.get("id")),
                         address.woocommerce_address_id)