Esempio n. 1
0
def test_query_sales_with_filter_search(
    sale_filter,
    count,
    staff_api_client,
    query_sales_with_filter,
    permission_manage_discounts,
):
    Sale.objects.bulk_create([
        Sale(name="BigSale", value=123, type="PERCENTAGE"),
        Sale(
            name="Sale2",
            value=123,
            type="FIXED",
            start_date=timezone.now().replace(year=2012, month=1, day=5),
        ),
        Sale(
            name="Sale3",
            value=69,
            type="FIXED",
            start_date=timezone.now().replace(year=2012, month=1, day=5),
        ),
    ])
    variables = {"filter": sale_filter}
    response = staff_api_client.post_graphql(
        query_sales_with_filter,
        variables,
        permissions=[permission_manage_discounts])
    content = get_graphql_content(response)
    data = content["data"]["sales"]["edges"]
    assert len(data) == count
Esempio n. 2
0
def test_query_sales_with_sort(sale_sort, result_order, staff_api_client,
                               permission_manage_discounts):
    Sale.objects.bulk_create([
        Sale(name="BigSale", value=1234, type="PERCENTAGE"),
        Sale(
            name="Sale2",
            value=123,
            type="FIXED",
            start_date=timezone.now().replace(year=2012, month=1, day=5),
            end_date=timezone.now().replace(year=2013, month=1, day=5),
        ),
        Sale(
            name="Sale3",
            value=69,
            type="FIXED",
            start_date=timezone.now().replace(year=2011, month=1, day=5),
            end_date=timezone.now().replace(year=2015, month=12, day=31),
        ),
    ])
    variables = {"sort_by": sale_sort}
    staff_api_client.user.user_permissions.add(permission_manage_discounts)
    response = staff_api_client.post_graphql(QUERY_SALE_WITH_SORT, variables)
    content = get_graphql_content(response)
    sales = content["data"]["sales"]["edges"]

    for order, sale_name in enumerate(result_order):
        assert sales[order]["node"]["name"] == sale_name
Esempio n. 3
0
def sales_for_pagination(db):
    now = timezone.now()
    return Sale.objects.bulk_create([
        Sale(
            name="Sale1",
            start_date=now + timezone.timedelta(hours=4),
            end_date=now + timezone.timedelta(hours=14),
            type=DiscountValueType.PERCENTAGE,
            value=Decimal("1"),
        ),
        Sale(
            name="Sale2",
            end_date=now + timezone.timedelta(hours=1),
            value=Decimal("7"),
        ),
        Sale(
            name="Sale3",
            end_date=now + timezone.timedelta(hours=2),
            type=DiscountValueType.PERCENTAGE,
            value=Decimal("5"),
        ),
        Sale(
            name="Sale4",
            end_date=now + timezone.timedelta(hours=1),
            value=Decimal("5"),
        ),
        Sale(
            name="Sale15",
            start_date=now + timezone.timedelta(hours=1),
            end_date=now + timezone.timedelta(hours=2),
            value=Decimal("25"),
        ),
    ])
Esempio n. 4
0
def test_query_sales_with_filter_started(sale_filter, count, staff_api_client,
                                         query_sales_with_filter,
                                         permission_manage_discounts):
    Sale.objects.bulk_create([
        Sale(name='Sale1', value=123),
        Sale(name='Sale2', value=123, start_date=date(2012, 1, 5))
    ])
    variables = {'filter': sale_filter}
    response = staff_api_client.post_graphql(
        query_sales_with_filter,
        variables,
        permissions=[permission_manage_discounts])
    content = get_graphql_content(response)
    data = content['data']['sales']['edges']
    assert len(data) == count
Esempio n. 5
0
def test_sale_applies_to_correct_products(product_type, category):
    product = Product.objects.create(
        name="Test Product",
        price=Money(10, "USD"),
        description="",
        pk=111,
        product_type=product_type,
        category=category,
    )
    variant = ProductVariant.objects.create(product=product, sku="firstvar")
    product2 = Product.objects.create(
        name="Second product",
        price=Money(15, "USD"),
        description="",
        product_type=product_type,
        category=category,
    )
    sec_variant = ProductVariant.objects.create(product=product2,
                                                sku="secvar",
                                                pk=111)
    sale = Sale(name="Test sale", value=3, type=DiscountValueType.FIXED)
    discount = DiscountInfo(sale=sale,
                            product_ids={product.id},
                            category_ids=set(),
                            collection_ids=set())
    product_discount = get_product_discount_on_sale(variant.product, discount)
    discounted_price = product_discount(product.price)
    assert discounted_price == Money(7, "USD")
    with pytest.raises(NotApplicable):
        get_product_discount_on_sale(sec_variant.product, discount)
Esempio n. 6
0
def test_query_sales_with_filter_discount_type(sale_filter, count, sale_type,
                                               staff_api_client,
                                               query_sales_with_filter,
                                               permission_manage_discounts):
    Sale.objects.bulk_create([
        Sale(name='Sale1', value=123, type=DiscountValueType.FIXED),
        Sale(name='Sale2', value=123, type=sale_type)
    ])
    variables = {'filter': sale_filter}
    response = staff_api_client.post_graphql(
        query_sales_with_filter,
        variables,
        permissions=[permission_manage_discounts])
    content = get_graphql_content(response)
    data = content['data']['sales']['edges']
    assert len(data) == count
Esempio n. 7
0
def test_percentage_discounts(product):
    variant = product.variants.get()
    sale = Sale(type=DiscountValueType.PERCENTAGE, value=50)
    discount = DiscountInfo(
        sale=sale, product_ids={product.id}, category_ids=set(), collection_ids={}
    )
    final_price = variant.get_price(discounts=[discount])
    assert final_price.gross == Money(5, "USD")
Esempio n. 8
0
def test_query_sales_with_filter_started(
    sale_filter,
    count,
    staff_api_client,
    query_sales_with_filter,
    permission_manage_discounts,
):
    Sale.objects.bulk_create([
        Sale(name="Sale1", value=123),
        Sale(name="Sale2", value=123, start_date=date(2012, 1, 5)),
    ])
    variables = {"filter": sale_filter}
    response = staff_api_client.post_graphql(
        query_sales_with_filter,
        variables,
        permissions=[permission_manage_discounts])
    content = get_graphql_content(response)
    data = content["data"]["sales"]["edges"]
    assert len(data) == count
Esempio n. 9
0
def test_variant_discounts(product):
    variant = product.variants.get()
    low_sale = Sale(type=DiscountValueType.FIXED, value=5)
    low_discount = DiscountInfo(
        sale=low_sale,
        product_ids={product.id},
        category_ids=set(),
        collection_ids=set(),
    )
    sale = Sale(type=DiscountValueType.FIXED, value=8)
    discount = DiscountInfo(
        sale=sale, product_ids={product.id}, category_ids=set(), collection_ids=set()
    )
    high_sale = Sale(type=DiscountValueType.FIXED, value=50)
    high_discount = DiscountInfo(
        sale=high_sale,
        product_ids={product.id},
        category_ids=set(),
        collection_ids=set(),
    )
    final_price = variant.get_price(discounts=[low_discount, discount, high_discount])
    assert final_price.gross == Money(0, "USD")
Esempio n. 10
0
def sales_list():
    return list(
        Sale.objects.bulk_create(
            [Sale(name="Sale1", value=15),
             Sale(name="Sale2", value=5)]))