Beispiel #1
0
    def _compare_line_for_addition(self, current_line_data, product, supplier, shop, extra):
        """
        Compare raw line data for coalescing.

        That is, figure out whether the given raw line data is similar enough to product_id
        and extra to coalesce quantity additions.

        This is nice to override in a project-specific basket class.

        :type current_line_data: dict
        :type product: int
        :type extra: dict
        :return:
        """
        if current_line_data.get("product_id") != product.id:
            return False
        if current_line_data.get("supplier_id") != supplier.id:
            return False
        if current_line_data.get("shop_id") != shop.id:
            return False

        if isinstance(extra, dict):  # We have extra data, so compare it to that in this line
            if not compare_partial_dicts(extra, current_line_data):  # Extra data not similar? Okay then. :(
                return False
        return True
Beispiel #2
0
    def _compare_line_for_addition(self, current_line_data, product, supplier,
                                   shop, extra):
        """
        Compare raw line data for coalescing.

        That is, figure out whether the given raw line data is similar enough to product_id
        and extra to coalesce quantity additions.

        This is nice to override in a project-specific basket class.

        :type current_line_data: dict
        :type product: int
        :type extra: dict
        :return:
        """
        if current_line_data.get("product_id") != product.id:
            return False
        if current_line_data.get("supplier_id") != supplier.id:
            return False
        if current_line_data.get("shop_id") != shop.id:
            return False

        if isinstance(
                extra, dict
        ):  # We have extra data, so compare it to that in this line
            if not compare_partial_dicts(
                    extra, current_line_data
            ):  # Extra data not similar? Okay then. :(
                return False
        return True
def test_product_attributes_form():
    # Come up with a decent product...
    product = create_product("TestProduct", shop=get_default_shop())
    assert product.type.attributes.count()
    product.set_attribute_value("bogomips", 6400)
    product.set_attribute_value("genre", "Kauhu", "fi")
    product.set_attribute_value("genre", "Horror", "en")
    product.set_attribute_value("time_to_finish", 12.05)
    product.set_attribute_value("release_date", VOGONY_DATE)
    assert product.get_attribute_value("bogomips") == 6400

    # English is missing on purpose from the languages list; it'll still be available
    # for `genre` as it has an extant value.
    paf = ProductAttributesForm(product=product, languages=("fi", "sv"))
    assert compare_partial_dicts(
        paf.initial,
        {  # Check that things get loaded.
            "bogomips": 6400,
            "genre__fi": "Kauhu",
            "genre__en": "Horror",
            "release_date": VOGONY_DATE,
            "time_to_finish": Decimal("12.05")
        })
    form_data = get_form_data(paf)
    form_data.update({  # Change, clear and add fields
        "genre__sv":
        "Skräck",
        "genre__en":
        "Terror",
        "bogomips":
        "",
        "release_date":
        "",
        "awesome":
        "True",
        "important_datetime":
        make_aware(datetime.datetime(2000, 1, 1, 1, 2, 3), utc)
    })
    paf = ProductAttributesForm(product=product,
                                languages=("fi", "sv"),
                                data=form_data)
    paf.full_clean()
    assert not paf.errors
    paf.save()

    for identifier in ("bogomips", "release_date"):
        # Value should be gone
        assert not product.get_attribute_value(identifier)
        # ... and so should the actual product attribute object
        assert not ProductAttribute.objects.filter(
            attribute__identifier=identifier, product=product).exists()

    # Those other values got updated, right?
    assert product.get_attribute_value("genre", "en") == form_data["genre__en"]
    assert product.get_attribute_value("genre", "sv") == form_data["genre__sv"]
    assert product.get_attribute_value("awesome") is True
    assert str(product.get_attribute_value(
        "important_datetime")) == "2000-01-01 01:02:03+00:00"
def test_product_attributes_form():
    # Come up with a decent product...
    product = create_product("TestProduct", shop=get_default_shop())
    assert product.type.attributes.count()
    product.set_attribute_value("bogomips", 6400)
    product.set_attribute_value("genre", "Kauhu", "fi")
    product.set_attribute_value("genre", "Horror", "en")
    product.set_attribute_value("time_to_finish", 12.05)
    product.set_attribute_value("release_date", VOGONY_DATE)
    assert product.get_attribute_value("bogomips") == 6400

    # English is missing on purpose from the languages list; it'll still be available
    # for `genre` as it has an extant value.
    paf = ProductAttributesForm(product=product, languages=("fi", "sv"))
    assert compare_partial_dicts(paf.initial, {  # Check that things get loaded.
        "bogomips": 6400,
        "genre__fi": "Kauhu",
        "genre__en": "Horror",
        "release_date": VOGONY_DATE,
        "time_to_finish": Decimal("12.05")
    })
    form_data = get_form_data(paf)
    form_data.update({  # Change, clear and add fields
        "genre__sv": "Skräck",
        "genre__en": "Terror",
        "bogomips": "",
        "release_date": "",
        "awesome": "True",
        "important_datetime": make_aware(datetime.datetime(2000, 1, 1, 1, 2, 3), utc)
    })
    paf = ProductAttributesForm(product=product, languages=("fi", "sv"), data=form_data)
    paf.full_clean()
    assert not paf.errors
    paf.save()

    for identifier in ("bogomips", "release_date"):
        # Value should be gone
        assert not product.get_attribute_value(identifier)
        # ... and so should the actual product attribute object
        assert not ProductAttribute.objects.filter(attribute__identifier=identifier, product=product).exists()

    # Those other values got updated, right?
    assert product.get_attribute_value("genre", "en") == form_data["genre__en"]
    assert product.get_attribute_value("genre", "sv") == form_data["genre__sv"]
    assert product.get_attribute_value("awesome") is True
    assert str(product.get_attribute_value("important_datetime")) == "2000-01-01 01:02:03+00:00"