Ejemplo n.º 1
0
def test_by_search(app, create_vendor, args, result):
    create_vendor("vendor1", "product_1")
    create_vendor("vendor1", "product_2")

    with app.test_request_context():
        products = ProductController.list_items({"vendor": "vendor1", **args})
    assert sorted([p.name for p in products]) == result
Ejemplo n.º 2
0
 def get(self, vendor):
     return ProductController.list_items(
         {
             **request.args,
             "vendor": vendor,
             "product_page": request.args.get("page", 1),
         }
     )
Ejemplo n.º 3
0
def test_list(app, create_vendor):
    create_vendor("vendor1", "product1")
    create_vendor("vendor1", "product2")

    with app.test_request_context():
        products = ProductController.list_items({"vendor": "vendor1"})
    assert len(products) == 2
    assert sorted([p.name for p in products]) == ["product1", "product2"]
Ejemplo n.º 4
0
def products(vendor):
    products, _, pagination = ProductController.list({**request.args, "vendor": vendor})

    return render_template(
        "products.html",
        products=products,
        vendor=vendor,
        pagination=pagination,
    )
Ejemplo n.º 5
0
def vendors():
    vendors, _, pagination_v = VendorController.list(request.args)
    products, _, pagination_p = ProductController.list(request.args)

    return render_template(
        "vendors.html",
        vendors=vendors,
        products=products,
        pagination_v=pagination_v,
        pagination_p=pagination_p,
    )
Ejemplo n.º 6
0
def test_list_paginated(app, create_vendor):
    old = app.config["PRODUCTS_PER_PAGE"]
    app.config["PRODUCTS_PER_PAGE"] = 3

    create_vendor("vendor1", "product1")
    create_vendor("vendor1", "product2")
    create_vendor("vendor1", "product3")
    create_vendor("vendor1", "product4")

    with app.test_request_context():
        products = ProductController.list_items({"vendor": "vendor1"})
        assert sorted([p.name for p in products]) == [
            "product1",
            "product2",
            "product3",
        ]
        products = ProductController.list_items({
            "vendor": "vendor1",
            "product_page": 2
        })
        assert sorted([p.name for p in products]) == ["product4"]

    app.config["PRODUCTS_PER_PAGE"] = old
Ejemplo n.º 7
0
def test_metas(app, create_vendor):
    create_vendor("vendor1", "product1")

    with app.test_request_context():
        _, metas, _ = ProductController.list({"vendor": "vendor1"})
    assert metas == {}
Ejemplo n.º 8
0
def test_list_vendor_notfound(app):
    with app.test_request_context():
        with pytest.raises(NotFound):
            ProductController.list({"vendor": "notfound"})
Ejemplo n.º 9
0
 def get(self):
     return ProductController.list_items(
         {**request.args, "product_page": request.args.get("page", 1)}
     )
Ejemplo n.º 10
0
 def get(self, vendor, product):
     ProductController.get({"vendor": vendor, "product": product})
     return CveController.list_items(
         {**request.args, "vendor": vendor, "product": product}
     )
Ejemplo n.º 11
0
 def get(self, vendor, product):
     return ProductController.get({"vendor": vendor, "product": product})
Ejemplo n.º 12
0
 def get(self, vendor):
     return ProductController.list_items({**request.args, "vendor": vendor})