Exemplo n.º 1
0
def test_discount_for_logged_in_contacts(rf):
    default_price = 10
    request, product = _init_test_for_product(rf, default_price)
    assert request.customer == AnonymousContact()

    product_discount_amount = 2
    Discount.objects.create(
        shop=request.shop,
        active=True,
        contact_group=PersonContact.get_default_group(),
        discount_amount_value=product_discount_amount,
    )
    Discount.objects.create(
        shop=request.shop,
        active=True,
        contact_group=CompanyContact.get_default_group(),
        discount_amount_value=product_discount_amount,
    )
    assert product.get_price_info(request).price == request.shop.create_price(
        default_price)

    # setting customer to request should apply the discount
    request.customer = factories.create_random_person()
    assert product.get_price_info(request).price == request.shop.create_price(
        default_price - product_discount_amount)

    # Company as customer should work too
    request.customer = factories.create_random_company()
    assert product.get_price_info(request).price == request.shop.create_price(
        default_price - product_discount_amount)
Exemplo n.º 2
0
def test_discount_for_companies(rf):
    default_price = 10
    request, product = _init_test_for_product(rf, default_price)
    assert request.customer == AnonymousContact()

    product_discount_amount = 2
    Discount.objects.create(
        shop=request.shop,
        active=True,
        contact_group=CompanyContact.get_default_group(),
        discount_amount_value=product_discount_amount,
    )
    assert product.get_price_info(request).price == request.shop.create_price(
        default_price)

    # Setting customer to request activates the discount
    request.customer = factories.create_random_company()
    assert product.get_price_info(request).price == request.shop.create_price(
        default_price - product_discount_amount)

    # Using person contact as customer means no discount
    request.customer = factories.create_random_person()
    assert product.get_price_info(request).price == request.shop.create_price(
        default_price)
Exemplo n.º 3
0
def test_default_company_contact_group_repr_and_str():
    cdg = CompanyContact.get_default_group()
    assert repr(cdg) == '<ContactGroup:%d-default_company_group>' % cdg.pk
    assert str(cdg) == 'Company Contacts'
Exemplo n.º 4
0
def test_default_company_contact_group_repr_and_str():
    cdg = CompanyContact.get_default_group()
    assert repr(cdg) == '<ContactGroup:%d-default_company_group>' % cdg.pk
    assert str(cdg) == 'Company Contacts'