Пример #1
0
class ProductJsonModelWithComplexVariantItems(ed.ItemModel):
    data_processors = [
        ed.DataVariantsProcessor(
            query=ed.jp("variants"),
            key_parser=ed.Text(ed.jp("color")),
            new_source="color_data",
        )
    ]

    item_name = ed.Text(ed.jp("title"))

    item_color = ed.Text(ed.jp("color"), source="color_data")

    item_images = ed.UrlList(
        ed.jp("images.{color}[].assetId"),
        query_params={"color": ed.Data(ed.jp("color"), source="color_data")},
        domain="https://demo.com/is/image/easydata/",
    )

    item_sizes = ed.Dict(
        source="color_data_variants",
        key_parser=ed.Text(ed.jp("size")),
        val_parser=ed.Bool(
            ed.jp("stock_data[?id==`{stock_id}`] | [0].stock"),
            query_params={"stock_id": ed.Int(ed.jp("stock_id"))},
            source="main",
        ),
    )
Пример #2
0
class ProductHtmlModelWithItems(ed.ItemModel):
    data_processors = [
        ed.DataVariantsProcessor(
            query=ed.pq("#color-variants .color::items"), new_source="color_data"
        )
    ]

    item_name = ed.Text(ed.pq(".name::text"))

    item_color = ed.Text(ed.pq(".color-name::text"), source="color_data")
Пример #3
0
class ProductModel(ed.ItemModel):
    item_language = "en"

    item_tags = ["phones", "ecommerce"]

    _item_brand = ed.Text(ed.jp("brand"), source="json_data")

    item_designer = ed.Text(from_item="brand")

    item_name = ed.Text(ed.pq(".name::text"))

    def item_stock(self, data):
        return data["json_data"]["info"]["stock"]
Пример #4
0
class ProductJsonModelWithVariantDropItems(ed.ItemModel):
    data_processors = [
        ed.DataJsonToDictProcessor(),
        ed.DataFromQueryProcessor(ed.jp("data")),
        ed.DataVariantsProcessor(
            query=ed.jp("variants"),
            key_parser=ed.Text(ed.jp("color")),
            new_source="color_data",
        ),
    ]

    _item_drop_color = ed.DropContains(from_item="color", contains=["black"])

    item_color = ed.Text(ed.jp("color"), source="color_data")
Пример #5
0
class ProductHtmlModelWithVariantItems(ed.ItemModel):
    data_processors = [
        ed.DataVariantsProcessor(
            query=ed.pq("#color-variants .color::items"),
            key_parser=ed.Text(ed.pq(".color-name::text")),
            new_source="color_data",
        )
    ]

    item_name = ed.Text(ed.pq(".name::text"))

    item_color = ed.Text(ed.pq(".color-name::text"), source="color_data")

    item_key = ed.Text(source="color_data_key", uppercase=True)
Пример #6
0
class ProductJsonModel(ed.ItemModel):
    item_currency = "USD"

    item_tags = ["notebook", "ecommerce"]

    item_name = ed.Text(ed.jp("title"))

    item_price = ed.PriceFloat(ed.jp("price"))

    item_sale_price = ed.PriceFloat(ed.jp("sale_price"))
Пример #7
0
class ProductSimpleWithProcessDataModel(ed.ItemModel):
    data_processors = [ed.DataJsonToDictProcessor()]

    item_brand = ed.Text(ed.jp("brand"))

    item_brand_type = ed.Text(source="brand_type")

    def preprocess_data(self, data):
        data["main"] = data["main"] + "}"

        return data

    def process_data(self, data):
        if "easydata" in data["main"]["brand"].lower():
            data["brand_type"] = "local"
        else:
            data["brand_type"] = "other"

        return data
Пример #8
0
class ProductJsonModelWithVariantItems(ed.ItemModel):
    data_processors = [
        ed.DataJsonToDictProcessor(),
        ed.DataFromQueryProcessor(ed.jp("data")),
        ed.DataVariantsProcessor(
            query=ed.jp("variants"),
            key_parser=ed.Text(ed.jp("color")),
            new_source="color_data",
        ),
    ]

    item_name = ed.Text(ed.jp("title"))

    item_color = ed.Text(ed.jp("color"), source="color_data")

    item_key = ed.Text(source="color_data_key", uppercase=True)

    item_screen_sizes = ed.BoolDict(
        key_parser=ed.Text(ed.jp("size")),
        val_query=ed.key("stock"),
        source="color_data_variants",
    )
Пример #9
0
        },
    ]

    test_data = data_dict.multi_items
    assert list(product_model.parse_items(test_data)) == result_variants


@pytest.mark.parametrize(
    "test_data, stacked_model, result",
    [
        (
            data_dict.item_with_options,
            ed.StackedModel(
                ed.ItemDiscountProcessor(),
                ED_PRICE_DECIMALS=1,
                name=ed.Text(ed.jp("title")),
                price=ed.PriceFloat(ed.jp("price")),
                _sale_price=ed.PriceFloat(ed.jp("sale_price")),
            ),
            [{
                "discount": 50.0,
                "name": "EasyBook pro 15",
                "price": 100.0
            }],
        ),
        (
            data_dict.variants_data_multi,
            ed.StackedModel(
                ed.DataFromQueryProcessor(ed.jp("data")),
                ed.DataVariantsProcessor(
                    query=ed.jp("variants"),