Пример #1
0
def test_sales_ranges_update_after_range_update():
    shop = get_default_shop()
    supplier = get_default_supplier()
    person = create_random_person()
    company = create_random_company()
    create_fully_paid_order(shop, person, supplier, "sku1", 50)
    create_fully_paid_order(shop, company, supplier, "sku2", 100)
    assert get_total_sales(shop, person) == 50
    assert get_total_sales(shop, company) == 100

    sales_range = create_sales_range("gold", shop, 10, 90)
    assert sales_range.group in person.groups.all()
    assert sales_range.group not in company.groups.all()

    sales_range.max_value = None
    sales_range.save()
    assert sales_range.group in person.groups.all()
    assert sales_range.group in company.groups.all()

    # Make sure customers is actually removed when range changes
    sales_range.max_value = 60
    sales_range.save()
    assert sales_range.group in person.groups.all()
    assert sales_range.group not in company.groups.all()

    # Inactive ranges shouldn't update group members
    sales_range.min_value = None
    sales_range.save()
    assert sales_range.group in person.groups.all()
    assert sales_range.group not in company.groups.all()
Пример #2
0
def test_company_contact_creation(rf, admin_user):
    get_initial_order_status()
    contact = create_random_company()
    test_tax_number = "1234567-1"
    contact.tax_number = test_tax_number
    contact.save()
    contact.default_billing_address.tax_number = test_tax_number
    contact.default_billing_address.save()
    state = get_frontend_order_state(contact=contact)
    state["customer"] = {
        "id": None,
        "name": None,
        "billingAddress": encode_address(contact.default_billing_address),
        "shipToBillingAddress": True,
        "saveAddress": True,
        "isCompany": True
    }
    order = get_order_from_state(state, admin_user)
    assert order.lines.count() == 5
    assert order.customer.id != contact.id
    assert order.customer.name == contact.name
    assert order.customer.tax_number == test_tax_number
    assert order.billing_address.tax_number == contact.default_billing_address.tax_number
    assert order.billing_address.street == contact.default_billing_address.street
    assert order.billing_address.street == order.shipping_address.street
Пример #3
0
def test_company_contact_creation(rf, admin_user):
    get_initial_order_status()
    contact = create_random_company()
    test_tax_number = "1234567-1"
    contact.tax_number = test_tax_number
    contact.save()
    contact.default_billing_address.tax_number = test_tax_number
    contact.default_billing_address.save()
    state = get_frontend_order_state(contact=contact)
    state["customer"] = {
        "id": None,
        "name": None,
        "billingAddress": encode_address(contact.default_billing_address),
        "shipToBillingAddress": True,
        "saveAddress": True,
        "isCompany": True
    }
    order = get_order_from_state(state, admin_user)
    assert order.lines.count() == 5
    assert order.customer.id != contact.id
    assert order.customer.name == contact.name
    assert order.customer.tax_number == test_tax_number
    assert order.billing_address.tax_number == contact.default_billing_address.tax_number
    assert order.billing_address.street == contact.default_billing_address.street
    assert order.billing_address.street == order.shipping_address.street
Пример #4
0
def test_sales_ranges_update_after_range_update():
    shop = get_default_shop()
    supplier = get_default_supplier()
    person = create_random_person()
    company = create_random_company()
    create_fully_paid_order(shop, person, supplier, "sku1", 50)
    create_fully_paid_order(shop, company, supplier, "sku2", 100)
    assert get_total_sales(shop, person) == 50
    assert get_total_sales(shop, company) == 100

    sales_range = create_sales_range("gold", shop, 10, 90)
    assert sales_range.group in person.groups.all()
    assert sales_range.group not in company.groups.all()

    sales_range.max_value = None
    sales_range.save()
    assert sales_range.group in person.groups.all()
    assert sales_range.group in company.groups.all()

    # Make sure customers is actually removed when range changes
    sales_range.max_value = 60
    sales_range.save()
    assert sales_range.group in person.groups.all()
    assert sales_range.group not in company.groups.all()

    # Inactive ranges shouldn't update group members
    sales_range.min_value = None
    sales_range.save()
    assert sales_range.group in person.groups.all()
    assert sales_range.group not in company.groups.all()
Пример #5
0
def test_get_company_contact(regular_user):
    person_contact = get_person_contact(regular_user)
    assert person_contact != AnonymousContact()
    assert not get_company_contact(regular_user)

    company_contact = create_random_company()
    company_contact.members.add(person_contact)
    assert get_company_contact(regular_user) == company_contact
Пример #6
0
def test_company_contact_edit_form():
    company = create_random_company()
    contact_base_form = ContactBaseForm(instance=company, data={
        "name": company.name,
    })
    assert not contact_base_form.bind_user
    assert contact_base_form.contact_class == CompanyContact
    assert contact_base_form.is_valid(), contact_base_form.errors
    contact = contact_base_form.save()
    assert isinstance(contact, CompanyContact)
    assert isinstance(contact_base_form.fields["members"], Select2MultipleField)
Пример #7
0
def test_company_contact_edit_form():
    company = create_random_company()
    contact_base_form = ContactBaseForm(instance=company, data={
        "name": company.name,
    })
    assert not contact_base_form.bind_user
    assert contact_base_form.contact_class == CompanyContact
    assert contact_base_form.is_valid(), contact_base_form.errors
    contact = contact_base_form.save()
    assert isinstance(contact, CompanyContact)
    assert isinstance(contact_base_form.fields["members"].widget, Select2Multiple)
Пример #8
0
def test_form_part_for_default_group(rf, admin_user):
    get_default_shop()
    company = create_random_company()
    group = company.get_default_group()
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    initialized_view = ContactGroupEditView(request=request, kwargs={"pk": group.pk})
    initialized_view.object = initialized_view.get_object() # Just for test
    form_def_values = initialized_view.get_form().form_defs.values()
    assert [form_def for form_def in form_def_values if form_def.name == "base"]
    # contact_group_sales_ranges should not be in form defs
    assert not [form_def for form_def in form_def_values if "contact_group_sales_ranges" in form_def.name]
Пример #9
0
def test_form_part_for_default_group(rf, admin_user):
    get_default_shop()
    company = create_random_company()
    group = company.get_default_group()
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    initialized_view = ContactGroupEditView(request=request,
                                            kwargs={"pk": group.pk})
    initialized_view.object = initialized_view.get_object()  # Just for test
    form_def_values = initialized_view.get_form().form_defs.values()
    assert [
        form_def for form_def in form_def_values if form_def.name == "base"
    ]
    # contact_group_sales_ranges should not be in form defs
    assert not [
        form_def for form_def in form_def_values
        if "contact_group_sales_ranges" in form_def.name
    ]
Пример #10
0
def test_customer_company_member(regular_user):
    get_default_shop()  # Create a shop

    mw = ShoopFrontMiddleware()
    request = get_unprocessed_request()
    request.user = regular_user
    person = get_person_contact(regular_user)
    company = create_random_company()
    company.members.add(person)

    assert get_company_contact(regular_user) == company

    mw.process_request(request)

    check_request_attribute_basics(request)

    assert isinstance(request.person, PersonContact)
    assert isinstance(request.customer, CompanyContact)

    company = get_company_contact(request.user)
    assert company and (company == request.customer)
Пример #11
0
def test_customer_company_member(regular_user):
    get_default_shop()  # Create a shop

    mw = ShoopFrontMiddleware()
    request = get_unprocessed_request()
    request.user = regular_user
    person = get_person_contact(regular_user)
    company = create_random_company()
    company.members.add(person)

    assert get_company_contact(regular_user) == company

    mw.process_request(request)

    check_request_attribute_basics(request)

    assert isinstance(request.person, PersonContact)
    assert isinstance(request.customer, CompanyContact)

    company = get_company_contact(request.user)
    assert company and (company == request.customer)
Пример #12
0
 def mock_company(self):
     """ Create a random company """
     return create_random_company()
Пример #13
0
 def mock_company(self):
     """ Create a random company """
     return create_random_company()