def test_by_search(app, create_vendor, args, result): create_vendor("vendor_1", "product1") create_vendor("vendor_2", "product2") with app.test_request_context(): vendors = VendorController.list_items(args) assert sorted([v.name for v in vendors]) == result
def test_list_paginated(app, create_vendor): old = app.config["VENDORS_PER_PAGE"] app.config["VENDORS_PER_PAGE"] = 3 create_vendor("vendor1", "product1") create_vendor("vendor2", "product2") create_vendor("vendor3", "product3") create_vendor("vendor4", "product4") with app.test_request_context(): vendors = VendorController.list_items() assert sorted([v.name for v in vendors]) == ["vendor1", "vendor2", "vendor3"] vendors = VendorController.list_items({"page": 2}) assert sorted([v.name for v in vendors]) == ["vendor4"] app.config["VENDORS_PER_PAGE"] = old
def test_list(app, create_vendor): create_vendor("vendor1", "product1") create_vendor("vendor2", "product2") with app.test_request_context(): vendors = VendorController.list_items() assert len(vendors) == 2 assert sorted([v.name for v in vendors]) == ["vendor1", "vendor2"]
def test_by_letter(app, create_vendor, args, result): create_vendor("foo", "product") create_vendor("bar", "product") create_vendor("baz", "product") with app.test_request_context(): vendors = VendorController.list_items(args) assert sorted([v.name for v in vendors]) == result
def vendors(): vendors, _, pagination = VendorController.list(request.args) return render_template( "vendors.html", vendors=vendors, letters=get_vendors_letters(), pagination=pagination, )
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, )
def build_query(cls, args): vendor = VendorController.get({"name": args.get("vendor")}) query = Product.query.filter_by(vendor=vendor) # Search by term if args.get("search"): search = args.get("search").lower().replace("%", "").replace("_", "") query = query.filter(Product.name.like("%{}%".format(search))) return query, {}
def build_query(cls, args): if "vendor" in args: vendor = VendorController.get({"name": args.get("vendor")}) query = cls.model.query.filter_by(vendor=vendor) else: query = cls.model.query # Search by term if args.get("search"): search = (args.get("search").lower().replace("%", "").replace( "_", "").replace(" ", "_")) query = query.filter(Product.name.like("%{}%".format(search))) return query, {}
def get(cls, filters): vendor = VendorController.get({"name": filters.get("vendor")}) return super(ProductController, cls).get({ "vendor_id": vendor.id, "name": filters.get("product") })
def get(self, name): VendorController.get({"name": name}) return CveController.list_items({**request.args, "vendor": name})
def get(self, name): return VendorController.get({"name": name})
def get(self): return VendorController.list_items(request.args)
def test_metas(app): with app.test_request_context(): _, metas, _ = VendorController.list() assert metas == {}
def test_letter_not_found(app): with app.test_request_context(): with pytest.raises(NotFound): VendorController.list_items({"letter": "$"})