コード例 #1
0
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
コード例 #2
0
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
コード例 #3
0
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"]
コード例 #4
0
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
コード例 #5
0
ファイル: vendors.py プロジェクト: wfvkvh/opencve
def vendors():
    vendors, _, pagination = VendorController.list(request.args)
    return render_template(
        "vendors.html",
        vendors=vendors,
        letters=get_vendors_letters(),
        pagination=pagination,
    )
コード例 #6
0
ファイル: vendors.py プロジェクト: ChriZzn/opencve
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,
    )
コード例 #7
0
ファイル: products.py プロジェクト: wfvkvh/opencve
    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, {}
コード例 #8
0
ファイル: products.py プロジェクト: bbhunter/opencve
    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, {}
コード例 #9
0
ファイル: products.py プロジェクト: bbhunter/opencve
 def get(cls, filters):
     vendor = VendorController.get({"name": filters.get("vendor")})
     return super(ProductController, cls).get({
         "vendor_id": vendor.id,
         "name": filters.get("product")
     })
コード例 #10
0
 def get(self, name):
     VendorController.get({"name": name})
     return CveController.list_items({**request.args, "vendor": name})
コード例 #11
0
 def get(self, name):
     return VendorController.get({"name": name})
コード例 #12
0
 def get(self):
     return VendorController.list_items(request.args)
コード例 #13
0
def test_metas(app):
    with app.test_request_context():
        _, metas, _ = VendorController.list()
    assert metas == {}
コード例 #14
0
def test_letter_not_found(app):
    with app.test_request_context():
        with pytest.raises(NotFound):
            VendorController.list_items({"letter": "$"})