Example #1
0
    def test_order(self):
        """
        Test that a completed order contains cart items and that
        they're removed from stock.
        """

        # Add to cart.
        self._reset_variations()
        variation = self._product.variations.all()[0]
        self._add_to_cart(variation, TEST_STOCK)
        cart = Cart.objects.from_request(self.client)

        # Post order.
        data = {
            "step": len(CHECKOUT_STEPS),
            "billing_detail_email": "*****@*****.**",
            "discount_code": "",
        }
        for field_name, field in list(OrderForm(None, None).fields.items()):
            value = field.choices[-1][1] if hasattr(field, "choices") else "1"
            data.setdefault(field_name, value)
        self.client.post(reverse("shop_checkout"), data)
        try:
            order = Order.objects.from_request(self.client)
        except Order.DoesNotExist:
            self.fail("Couldn't create an order")
        items = order.items.all()
        variation = self._product.variations.all()[0]

        self.assertEqual(cart.total_quantity(), 0)
        self.assertEqual(len(items), 1)
        self.assertEqual(items[0].sku, variation.sku)
        self.assertEqual(items[0].quantity, TEST_STOCK)
        self.assertEqual(variation.num_in_stock, TEST_STOCK)
        self.assertEqual(order.item_total, TEST_PRICE * TEST_STOCK)
Example #2
0
        django.setup()
    except AttributeError:  # < 1.7
        pass

if sys.argv[-2:] == ["docs", "docs/build"]:
    import cartridge
    from mezzanine.utils import docs
    docs.build_settings_docs(docs_path, prefix="SHOP_")
    docs.build_changelog(docs_path, package_name="cartridge")
    #docs.build_modelgraph(docs_path, package_name="cartridge")

try:
    from cartridge.shop.models import Order
    from cartridge.shop.forms import OrderForm
    fields = {
        "form": OrderForm(None, None).fields.keys(),
        "model": [f.name for f in Order._meta.fields],
    }
    for name, names in fields.items():
        file_name = "order_%s_fields.rst" % name
        with open(os.path.join(docs_path, file_name), "w") as f:
            f.write("  * ``" + "``\n  * ``".join(names) + "``")
except Exception, e:
    print "Error generating docs for fields: %s" % e

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.append(os.path.abspath('.'))

# -- General configuration -----------------------------------------------------