コード例 #1
0
ファイル: test_utils_users.py プロジェクト: yashodhank/shuup
def test_forcing_to_person_and_anonymous_contact(rf, admin_user):
    company_contact = get_company_contact(admin_user)
    assert company_contact is None
    shop = factories.get_default_shop()
    company_contact = get_company_contact_for_shop_staff(shop, admin_user)
    assert isinstance(company_contact, CompanyContact)
    assert company_contact == get_company_contact(admin_user)

    person_contact = get_person_contact(admin_user)
    assert person_contact is not None
    assert not person_contact.is_anonymous

    force_person_contact_for_user(admin_user)
    assert get_company_contact(admin_user) is None

    force_anonymous_contact_for_user(admin_user)
    assert get_person_contact(admin_user).is_anonymous

    force_person_contact_for_user(admin_user, False)
    assert get_company_contact(
        admin_user) is None  # Since the person contact is still anonymous
    assert get_person_contact(admin_user).is_anonymous

    force_anonymous_contact_for_user(admin_user, False)
    assert company_contact == get_company_contact(admin_user)
    assert not get_person_contact(admin_user).is_anonymous
コード例 #2
0
ファイル: test_utils_users.py プロジェクト: ruqaiya/shuup
def test_forcing_to_person_and_anonymous_contact(rf, admin_user):
    company_contact = get_company_contact(admin_user)
    assert company_contact is None
    shop = factories.get_default_shop()
    company_contact = get_company_contact_for_shop_staff(shop, admin_user)
    assert isinstance(company_contact, CompanyContact)
    assert company_contact == get_company_contact(admin_user)

    person_contact = get_person_contact(admin_user)
    assert person_contact is not None
    assert not person_contact.is_anonymous

    force_person_contact_for_user(admin_user)
    assert get_company_contact(admin_user) is None

    force_anonymous_contact_for_user(admin_user)
    assert get_person_contact(admin_user).is_anonymous

    force_person_contact_for_user(admin_user, False)
    assert get_company_contact(admin_user) is None  # Since the person contact is still anonymous
    assert get_person_contact(admin_user).is_anonymous

    force_anonymous_contact_for_user(admin_user, False)
    assert company_contact == get_company_contact(admin_user)
    assert not get_person_contact(admin_user).is_anonymous
コード例 #3
0
def test_company_edit_form_links_company(regular_user,
                                         allow_company_registration):
    get_default_shop()
    configuration.set(None, "allow_company_registration",
                      allow_company_registration)
    person = get_person_contact(regular_user)
    assert not get_company_contact(regular_user)

    client = SmartClient()
    client.login(username=REGULAR_USER_USERNAME,
                 password=REGULAR_USER_PASSWORD)

    data = default_company_data()
    data.update(default_address_data("billing"))
    data.update(default_address_data("shipping"))
    company_edit_url = reverse("shuup:company_edit")

    if allow_company_registration:
        soup = client.soup(company_edit_url)
        response, soup = client.response_and_soup(company_edit_url, data,
                                                  "post")
        assert response.status_code == 302
        assert get_company_contact(regular_user)
    else:
        response = client.get(company_edit_url)
        assert reverse("shuup:customer_edit") in response.url
        response = client.post(company_edit_url, data)
        assert reverse("shuup:customer_edit") in response.url
コード例 #4
0
def test_notify_on_company_created(regular_user):
    if "shuup.front.apps.customer_information" not in settings.INSTALLED_APPS:
        pytest.skip(
            "shuup.front.apps.customer_information required in installed apps")
    if "shuup.notify" not in settings.INSTALLED_APPS:
        pytest.skip("shuup.notify required in installed apps")

    step = Step(cond_op=StepConditionOperator.NONE,
                actions=[
                    AddNotification({
                        "message": {
                            "constant": "It Works. {{ customer_email }}"
                        },
                        "message_identifier": {
                            "constant": "company_created"
                        },
                    })
                ],
                next=StepNext.STOP)
    script = Script(event_identifier=CompanyAccountCreated.identifier,
                    name="Test Script",
                    enabled=True)
    script.set_steps([step])
    script.save()

    assert not Notification.objects.filter(
        identifier="company_created").exists()

    get_default_shop()
    assert get_person_contact(regular_user)
    assert not get_company_contact(regular_user)

    client = SmartClient()
    client.login(username=REGULAR_USER_USERNAME,
                 password=REGULAR_USER_PASSWORD)
    company_edit_url = reverse("shuup:company_edit")
    client.soup(company_edit_url)

    data = _default_company_data()
    data.update(_default_address_data("billing"))
    data.update(_default_address_data("shipping"))

    response, soup = client.response_and_soup(company_edit_url, data, "post")

    assert response.status_code == 302
    assert get_company_contact(regular_user)
    assert Notification.objects.filter(
        identifier="company_created").count() == 1
    notification = Notification.objects.filter(
        identifier="company_created").first()
    assert notification
    assert data["contact-email"] in notification.message

    # New save should not add new notifications
    response, soup = client.response_and_soup(company_edit_url, data, "post")
    assert response.status_code == 302
    assert Notification.objects.filter(
        identifier="company_created").count() == 1
    script.delete()
コード例 #5
0
ファイル: test_contacts.py プロジェクト: hrayr-artunyan/shuup
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_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
コード例 #7
0
def test_company_tax_number_limitations(regular_user):
    get_default_shop()
    person = get_person_contact(regular_user)
    assert not get_company_contact(regular_user)

    client = SmartClient()
    client.login(username=REGULAR_USER_USERNAME,
                 password=REGULAR_USER_PASSWORD)
    company_edit_url = reverse("shuup:company_edit")
    soup = client.soup(company_edit_url)

    data = default_company_data()
    data.update(default_address_data("billing"))
    data.update(default_address_data("shipping"))

    response, soup = client.response_and_soup(company_edit_url, data, "post")

    assert response.status_code == 302
    assert get_company_contact(regular_user)

    # re-save should work properly
    response, soup = client.response_and_soup(company_edit_url, data, "post")
    assert response.status_code == 302
    client.logout()

    # another company tries to use same tax number
    new_user_password = "******"
    new_user_username = "******"
    user = User.objects.create_user(new_user_username, "*****@*****.**",
                                    new_user_password)
    person = get_person_contact(user=user)
    assert not get_company_contact(user)

    client = SmartClient()
    client.login(username=new_user_username, password=new_user_password)
    company_edit_url = reverse("shuup:company_edit")
    soup = client.soup(company_edit_url)

    data = default_company_data()
    data.update(default_address_data("billing"))
    data.update(default_address_data("shipping"))

    response, soup = client.response_and_soup(company_edit_url, data, "post")
    assert response.status_code == 200  # this time around, nothing was saved.
    assert not get_company_contact(user)  # company contact yet

    # change tax number
    data["contact-tax_number"] = "111111"
    response, soup = client.response_and_soup(company_edit_url, data, "post")
    assert response.status_code == 302  # this time around, nothing was saved.
    assert get_company_contact(user)  # company contact yet

    # go back to normal and try to get tax number approved
    data["contact-tax_number"] = "111110"
    response, soup = client.response_and_soup(company_edit_url, data, "post")
    assert response.status_code == 200  # this time around, nothing was saved.
コード例 #8
0
def test_notify_on_company_created(regular_user, allow_company_registration):
    if "shuup.front.apps.customer_information" not in settings.INSTALLED_APPS:
        pytest.skip("shuup.front.apps.customer_information required in installed apps")
    if "shuup.notify" not in settings.INSTALLED_APPS:
        pytest.skip("shuup.notify required in installed apps")

    configuration.set(None, "allow_company_registration", allow_company_registration)
    step = Step(
        cond_op=StepConditionOperator.NONE,
        actions=[
            AddNotification({
                "message": {"constant": "It Works. {{ customer_email }}"},
                "message_identifier": {"constant": "company_created"},
            })
        ],
        next=StepNext.STOP
    )
    script = Script(
        event_identifier=CompanyAccountCreated.identifier, name="Test Script", enabled=True, shop=get_default_shop())
    script.set_steps([step])
    script.save()

    assert not Notification.objects.filter(identifier="company_created").exists()

    assert get_person_contact(regular_user)
    assert not get_company_contact(regular_user)

    client = SmartClient()
    client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
    company_edit_url = reverse("shuup:company_edit")

    if allow_company_registration:
        client.soup(company_edit_url)

        data = _default_company_data()
        data.update(_default_address_data("billing"))
        data.update(_default_address_data("shipping"))

        response, soup = client.response_and_soup(company_edit_url, data, "post")

        assert response.status_code == 302
        assert get_company_contact(regular_user)
        assert Notification.objects.filter(identifier="company_created").count() == 1
        notification = Notification.objects.filter(identifier="company_created").first()
        assert notification
        assert data["contact-email"] in notification.message

        # New save should not add new notifications
        response, soup = client.response_and_soup(company_edit_url, data, "post")
        assert response.status_code == 302
        assert Notification.objects.filter(identifier="company_created").count() == 1
        script.delete()
    else:
        response = client.get(company_edit_url)
        assert reverse("shuup:customer_edit") in response.url
        assert Notification.objects.filter(identifier="company_created").count() == 0
コード例 #9
0
def test_company_tax_number_limitations(regular_user):
    get_default_shop()
    person = get_person_contact(regular_user)
    assert not get_company_contact(regular_user)

    client = SmartClient()
    client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
    company_edit_url = reverse("shuup:company_edit")
    soup = client.soup(company_edit_url)

    data = default_company_data()
    data.update(default_address_data("billing"))
    data.update(default_address_data("shipping"))

    response, soup = client.response_and_soup(company_edit_url, data, "post")

    assert response.status_code == 302
    assert get_company_contact(regular_user)

    # re-save should work properly
    response, soup = client.response_and_soup(company_edit_url, data, "post")
    assert response.status_code == 302
    client.logout()

    # another company tries to use same tax number
    new_user_password = "******"
    new_user_username = "******"
    user = User.objects.create_user(new_user_username, "*****@*****.**", new_user_password)
    person = get_person_contact(user=user)
    assert not get_company_contact(user)

    client = SmartClient()
    client.login(username=new_user_username, password=new_user_password)
    company_edit_url = reverse("shuup:company_edit")
    soup = client.soup(company_edit_url)

    data = default_company_data()
    data.update(default_address_data("billing"))
    data.update(default_address_data("shipping"))

    response, soup = client.response_and_soup(company_edit_url, data, "post")
    assert response.status_code == 200  # this time around, nothing was saved.
    assert not get_company_contact(user)  # company contact yet

    # change tax number
    data["contact-tax_number"] = "111111"
    response, soup = client.response_and_soup(company_edit_url, data, "post")
    assert response.status_code == 302  # this time around, nothing was saved.
    assert get_company_contact(user)  # company contact yet

    # go back to normal and try to get tax number approved
    data["contact-tax_number"] = "111110"
    response, soup = client.response_and_soup(company_edit_url, data, "post")
    assert response.status_code == 200  # this time around, nothing was saved.
コード例 #10
0
ファイル: test_utils_users.py プロジェクト: yashodhank/shuup
def test_company_contact_for_shop_staff(rf, admin_user):
    company_contact = get_company_contact(admin_user)
    assert company_contact is None

    shop = factories.get_default_shop()
    # Let's create shop for the shop staff
    company_contact = get_company_contact_for_shop_staff(shop, admin_user)

    company_contact = get_company_contact_for_shop_staff(shop, admin_user)
    assert company_contact is not None

    # Let's create second staff member to make sure all good with
    # creating company contact for shop staff.
    new_staff_user = factories.create_random_user()
    with pytest.raises(AssertionError):
        get_company_contact_for_shop_staff(shop, new_staff_user)

    new_staff_user.is_staff = True
    new_staff_user.save()

    with pytest.raises(AssertionError):
        # Since the new staff is not in shop members. The admin user
        # passed since he is also superuser.
        get_company_contact_for_shop_staff(shop, new_staff_user)

    shop.staff_members.add(new_staff_user)
    assert company_contact == get_company_contact_for_shop_staff(
        shop, new_staff_user)

    # Make sure both user has person contact linked to the company contact
    company_members = company_contact.members.all()
    assert get_person_contact(admin_user) in company_members
    assert get_person_contact(new_staff_user) in company_members
コード例 #11
0
ファイル: test_utils_users.py プロジェクト: yashodhank/shuup
def test_forcing_to_person_contact(rf, admin_user):
    company_contact = get_company_contact(admin_user)
    assert company_contact is None
    shop = factories.get_default_shop()
    company_contact = get_company_contact_for_shop_staff(shop, admin_user)
    assert isinstance(company_contact, CompanyContact)
    assert company_contact == get_company_contact(admin_user)

    person_contact = get_person_contact(admin_user)
    assert person_contact is not None

    force_person_contact_for_user(admin_user)
    assert get_company_contact(admin_user) is None

    force_person_contact_for_user(admin_user, False)
    assert company_contact == get_company_contact(admin_user)
コード例 #12
0
ファイル: test_utils_users.py プロジェクト: ruqaiya/shuup
def test_forcing_to_person_contact(rf, admin_user):
    company_contact = get_company_contact(admin_user)
    assert company_contact is None
    shop = factories.get_default_shop()
    company_contact = get_company_contact_for_shop_staff(shop, admin_user)
    assert isinstance(company_contact, CompanyContact)
    assert company_contact == get_company_contact(admin_user)
    
    person_contact = get_person_contact(admin_user)
    assert person_contact is not None

    force_person_contact_for_user(admin_user)
    assert get_company_contact(admin_user) is None

    force_person_contact_for_user(admin_user, False)
    assert company_contact == get_company_contact(admin_user)
コード例 #13
0
 def get_form(self, form_class):
     user = self.request.user
     company = get_company_contact(user)
     person = get_person_contact(user)
     form_group = FormGroup(**self.get_form_kwargs())
     form_group.add_form_def("billing",
                             AddressForm,
                             kwargs={
                                 "instance":
                                 _get_default_address_for_contact(
                                     company, "default_billing_address",
                                     person)
                             })
     form_group.add_form_def("shipping",
                             AddressForm,
                             kwargs={
                                 "instance":
                                 _get_default_address_for_contact(
                                     company, "default_shipping_address",
                                     person)
                             })
     form_group.add_form_def("contact",
                             CompanyContactForm,
                             kwargs={"instance": company})
     return form_group
コード例 #14
0
ファイル: views.py プロジェクト: wayhome25/shuup
 def get_form(self, form_class=None):
     user = self.request.user
     company = get_company_contact(user)
     person = get_person_contact(user)
     form_group = FormGroup(**self.get_form_kwargs())
     address_form_class = cached_load("SHUUP_ADDRESS_MODEL_FORM")
     form_group.add_form_def("billing",
                             address_form_class,
                             kwargs={
                                 "instance":
                                 _get_default_address_for_contact(
                                     company, "default_billing_address",
                                     person)
                             })
     form_group.add_form_def("shipping",
                             address_form_class,
                             kwargs={
                                 "instance":
                                 _get_default_address_for_contact(
                                     company, "default_shipping_address",
                                     person)
                             })
     form_group.add_form_def("contact",
                             CompanyContactForm,
                             kwargs={"instance": company})
     return form_group
コード例 #15
0
    def new(self, request, *args, **kwargs):
        """
        Create a brand new basket object
        """
        serializer = NewBasketSerializer(data=request.data)
        serializer.is_valid(True)
        data = serializer.validated_data

        self.process_request(with_basket=False, shop=data.get("shop"))
        basket_class = cached_load("SHUUP_BASKET_CLASS_SPEC")
        basket = basket_class(request._request)

        if "customer" in data:
            customer = data["customer"]
        else:
            customer = get_company_contact(request.user) or get_person_contact(
                request.user)

        orderer = data.get("orderer", get_person_contact(request.user))

        # set the request basket to perform the basket command
        self.request.basket = basket
        self._handle_set_customer(request=self.request._request,
                                  basket=basket,
                                  customer=customer,
                                  orderer=orderer)

        stored_basket = basket.save()
        response_data = {
            "uuid": "%s-%s" % (request.shop.pk, stored_basket.key)
        }
        response_data.update(self.get_serializer(basket).data)
        return Response(data=response_data, status=status.HTTP_201_CREATED)
コード例 #16
0
ファイル: test_utils_users.py プロジェクト: ruqaiya/shuup
def test_company_contact_for_shop_staff(rf, admin_user):
    company_contact = get_company_contact(admin_user)
    assert company_contact is None

    shop = factories.get_default_shop()
    # Let's create shop for the shop staff
    company_contact = get_company_contact_for_shop_staff(shop, admin_user)

    company_contact = get_company_contact_for_shop_staff(shop, admin_user)
    assert company_contact is not None

    # Let's create second staff member to make sure all good with
    # creating company contact for shop staff.
    new_staff_user = factories.create_random_user()
    with pytest.raises(AssertionError):
        get_company_contact_for_shop_staff(shop, new_staff_user)

    new_staff_user.is_staff = True
    new_staff_user.save()
    
    with pytest.raises(AssertionError):
        # Since the new staff is not in shop members. The admin user
        # passed since he is also superuser.
        get_company_contact_for_shop_staff(shop, new_staff_user)

    shop.staff_members.add(new_staff_user)
    assert company_contact == get_company_contact_for_shop_staff(shop, new_staff_user)

    # Make sure both user has person contact linked to the company contact
    company_members = company_contact.members.all()
    assert get_person_contact(admin_user) in company_members
    assert get_person_contact(new_staff_user) in company_members
コード例 #17
0
def test_force_views_only_for_staff(rf):
    shop = factories.get_default_shop()
    user = factories.create_random_user(is_staff=True)
    person_contact = get_person_contact(user)

    # Start forcing. There shouldn't be any changes to
    # request customer due calling the force functions since
    # those just do the redirect in case the current is user
    # is not shop staff.
    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact

    _call_force_view(request, force_anonymous_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact

    _call_force_view(request, force_person_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact

    _call_force_view(request, force_company_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact

    assert get_company_contact(user) is None
コード例 #18
0
def test_force_views_only_for_staff(rf):
    shop = factories.get_default_shop()
    user = factories.create_random_user(is_staff=True)
    person_contact = get_person_contact(user)

    # Start forcing. There shouldn't be any changes to
    # request customer due calling the force functions since
    # those just do the redirect in case the current is user
    # is not shop staff.
    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact

    _call_force_view(request, force_anonymous_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact

    _call_force_view(request, force_person_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact

    _call_force_view(request, force_company_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact

    assert get_company_contact(user) is None
コード例 #19
0
ファイル: basket.py プロジェクト: ruqaiya/shuup
    def new(self, request, *args, **kwargs):
        """
        Create a brand new basket object
        """
        serializer = NewBasketSerializer(data=request.data)
        serializer.is_valid(True)
        data = serializer.validated_data

        self.process_request(with_basket=False, shop=data.get("shop"))
        basket_class = cached_load("SHUUP_BASKET_CLASS_SPEC")
        basket = basket_class(request._request)

        if "customer" in data:
            customer = data["customer"]
        else:
            customer = get_company_contact(request.user) or get_person_contact(request.user)

        orderer = data.get("orderer", get_person_contact(request.user))

        # set the request basket to perform the basket command
        self.request.basket = basket
        self._handle_set_customer(
            request=self.request._request,
            basket=basket,
            customer=customer,
            orderer=orderer
        )

        stored_basket = basket.save()
        response_data = {
            "uuid": "%s-%s" % (request.shop.pk, stored_basket.key)
        }
        response_data.update(self.get_serializer(basket).data)
        return Response(data=response_data, status=status.HTTP_201_CREATED)
コード例 #20
0
def test_force_contact_views(rf):
    shop = factories.get_default_shop()
    user = factories.create_random_user(is_staff=True)
    shop.staff_members.add(user)
    person_contact = get_person_contact(user)
    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact

    # Force contact to anonymous contact
    _call_force_view(request, force_anonymous_contact)

    # Re-process middlewares so we check the force contact
    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer.is_anonymous
    assert get_person_contact(user).is_anonymous
    assert_all_good_with_random_user()

    # Force contact to person contact
    _call_force_view(request, force_person_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact
    assert get_person_contact(user) == person_contact
    assert_all_good_with_random_user()

    # Force contact to company contact. This also ensures
    # company contact for staff user if does not exists.
    _call_force_view(request, force_company_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert get_company_contact(user) == request.customer
    assert person_contact in request.customer.members.all()
    assert request.person == person_contact
    assert_all_good_with_random_user()

    # Finally force back to person contact. Now without
    # forcing the request would have company contact
    # since company contact for shop staff was created
    # while forcing company.
    _call_force_view(request, force_person_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact
    assert get_person_contact(user) == person_contact
    assert get_company_contact(user) is None
    assert_all_good_with_random_user()
コード例 #21
0
def test_force_contact_views(rf):
    shop = factories.get_default_shop()
    user = factories.create_random_user(is_staff=True)
    shop.staff_members.add(user)
    person_contact = get_person_contact(user)
    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact

    # Force contact to anonymous contact
    _call_force_view(request, force_anonymous_contact)

    # Re-process middlewares so we check the force contact
    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer.is_anonymous
    assert get_person_contact(user).is_anonymous
    assert_all_good_with_random_user()

    # Force contact to person contact
    _call_force_view(request, force_person_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact
    assert get_person_contact(user) == person_contact
    assert_all_good_with_random_user()

    # Force contact to company contact. This also ensures
    # company contact for staff user if does not exists.
    _call_force_view(request, force_company_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert get_company_contact(user) == request.customer
    assert person_contact in request.customer.members.all()
    assert request.person == person_contact
    assert_all_good_with_random_user()

    # Finally force back to person contact. Now without
    # forcing the request would have company contact
    # since company contact for shop staff was created
    # while forcing company.
    _call_force_view(request, force_person_contact)

    request = apply_request_middleware(rf.get("/"), user=user)
    assert request.customer == person_contact
    assert get_person_contact(user) == person_contact
    assert get_company_contact(user) is None
    assert_all_good_with_random_user()
コード例 #22
0
def test_company_edit_form_links_company(regular_user, rf):
    get_default_shop()
    person = get_person_contact(regular_user)
    assert not get_company_contact(regular_user)

    client = SmartClient()
    client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
    company_edit_url = reverse("shuup:company_edit")
    soup = client.soup(company_edit_url)

    data = default_company_data()
    data.update(default_address_data("billing"))
    data.update(default_address_data("shipping"))

    response, soup = client.response_and_soup(company_edit_url, data, "post")

    assert response.status_code == 302
    assert get_company_contact(regular_user)
コード例 #23
0
def test_company_edit_form_links_company(regular_user, rf):
    get_default_shop()
    person = get_person_contact(regular_user)
    assert not get_company_contact(regular_user)

    client = SmartClient()
    client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
    company_edit_url = reverse("shuup:company_edit")
    soup = client.soup(company_edit_url)

    data = default_company_data()
    data.update(default_address_data("billing"))
    data.update(default_address_data("shipping"))

    response, soup = client.response_and_soup(company_edit_url, data, "post")

    assert response.status_code == 302
    assert get_company_contact(regular_user)
コード例 #24
0
    def _set_customer(self, request):
        if not request.person or should_force_person_contact(request.user):
            company = None
        else:
            company = get_company_contact(request.user)

        request.customer = (company or request.person)
        request.is_company_member = bool(company)
        request.customer_groups = (company or request.person).groups.all()
コード例 #25
0
ファイル: test_addressbook.py プロジェクト: kafura0/OranKids
def initialize_test(regular_user, person=True):
    client = SmartClient()
    get_default_shop()
    if person:
        contact = get_person_contact(regular_user)
    else:
        contact = get_company_contact(regular_user)

    client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
    return client, contact
コード例 #26
0
ファイル: views.py プロジェクト: ahmadzai/shuup
 def get_form(self, form_class):
     contact = get_company_contact(self.request.user)
     form_group = FormGroup(**self.get_form_kwargs())
     form_group.add_form_def(
         "billing", AddressForm, kwargs={"instance": contact.default_billing_address if contact else None}
     )
     form_group.add_form_def(
         "shipping", AddressForm, kwargs={"instance": contact.default_shipping_address if contact else None}
     )
     form_group.add_form_def("contact", CompanyContactForm, kwargs={"instance": contact})
     return form_group
コード例 #27
0
 def process_request(self, with_basket=True, shop=None):
     """
     Add context to request that's expected by basket
     """
     request = self.request._request
     user = self.request.user
     request.shop = shop or self.get_basket_shop()
     request.person = get_person_contact(user)
     company = get_company_contact(user)
     request.customer = (company or request.person)
     if with_basket:
         request.basket = self.get_object()
コード例 #28
0
ファイル: test_middleware.py プロジェクト: suutari/shoop
def test_customer_company_member(regular_user):
    get_default_shop()  # Create a shop

    mw = ShuupFrontMiddleware()
    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)
コード例 #29
0
ファイル: basket.py プロジェクト: suutari-ai/shuup
 def process_request(self, with_basket=True):
     """
     Add context to request that's expected by basket
     """
     request = self.request._request
     user = self.request.user
     request.shop = self.get_basket_shop()
     request.person = get_person_contact(user)
     company = get_company_contact(user)
     request.customer = (company or request.person)
     if with_basket:
         request.basket = self.get_object()
コード例 #30
0
ファイル: 53415_test_middleware.py プロジェクト: wanuop/shuup
def test_customer_company_member(regular_user):
    get_default_shop()  # Create a shop

    mw = ShuupFrontMiddleware()
    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)
コード例 #31
0
ファイル: test_utils_users.py プロジェクト: ruqaiya/shuup
def test_forcing_to_anonymous_contact(rf, admin_user):
    person_contact = get_person_contact(admin_user)
    assert person_contact is not None
    assert not get_person_contact(admin_user).is_anonymous

    company_contact = get_company_contact(admin_user)
    assert company_contact is None

    force_anonymous_contact_for_user(admin_user)
    assert get_person_contact(admin_user).is_anonymous

    force_anonymous_contact_for_user(admin_user, False)
    assert not get_person_contact(admin_user).is_anonymous
    assert get_person_contact(admin_user).user.id == admin_user.id
コード例 #32
0
def test_company_still_linked_if_customer_contact_edited(regular_user):
    get_default_shop()
    person = get_person_contact(regular_user)
    assert not get_company_contact(regular_user)

    company = CompanyContact()
    company.save()
    company.members.add(person)
    assert get_company_contact(regular_user)

    client = SmartClient()
    client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
    customer_edit_url = reverse("shuup:customer_edit")
    soup = client.soup(customer_edit_url)

    data = default_customer_data()
    data.update(default_address_data("billing"))
    data.update(default_address_data("shipping"))

    response, soup = client.response_and_soup(customer_edit_url, data, "post")

    assert response.status_code == 302
    assert get_company_contact(regular_user)
コード例 #33
0
def test_company_still_linked_if_customer_contact_edited(regular_user):
    get_default_shop()
    person = get_person_contact(regular_user)
    assert not get_company_contact(regular_user)

    company = CompanyContact()
    company.save()
    company.members.add(person)
    assert get_company_contact(regular_user)

    client = SmartClient()
    client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)
    customer_edit_url = reverse("shuup:customer_edit")
    soup = client.soup(customer_edit_url)

    data = default_customer_data()
    data.update(default_address_data("billing"))
    data.update(default_address_data("shipping"))

    response, soup = client.response_and_soup(customer_edit_url, data, "post")

    assert response.status_code == 302
    assert get_company_contact(regular_user)
コード例 #34
0
ファイル: test_utils_users.py プロジェクト: yashodhank/shuup
def test_forcing_to_anonymous_contact(rf, admin_user):
    person_contact = get_person_contact(admin_user)
    assert person_contact is not None
    assert not get_person_contact(admin_user).is_anonymous

    company_contact = get_company_contact(admin_user)
    assert company_contact is None

    force_anonymous_contact_for_user(admin_user)
    assert get_person_contact(admin_user).is_anonymous

    force_anonymous_contact_for_user(admin_user, False)
    assert not get_person_contact(admin_user).is_anonymous
    assert get_person_contact(admin_user).user.id == admin_user.id
コード例 #35
0
def test_company_edit_form_links_company(regular_user, allow_company_registration):
    get_default_shop()
    configuration.set(None, "allow_company_registration", allow_company_registration)
    person = get_person_contact(regular_user)
    assert not get_company_contact(regular_user)

    client = SmartClient()
    client.login(username=REGULAR_USER_USERNAME, password=REGULAR_USER_PASSWORD)

    data = default_company_data()
    data.update(default_address_data("billing"))
    data.update(default_address_data("shipping"))
    company_edit_url = reverse("shuup:company_edit")

    if allow_company_registration:
        soup = client.soup(company_edit_url)
        response, soup = client.response_and_soup(company_edit_url, data, "post")
        assert response.status_code == 302
        assert get_company_contact(regular_user)
    else:
        response = client.get(company_edit_url)
        assert response.status_code == 404
        response = client.post(company_edit_url, data)
        assert response.status_code == 404
コード例 #36
0
    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop("request")
        super(CompanyInformationFormGroup, self).__init__(*args, **kwargs)

        user = self.request.user
        company = get_company_contact(user)
        person = get_person_contact(user)
        address_form_class = cached_load("SHUUP_ADDRESS_MODEL_FORM")

        for form_name in self.address_forms:
            self.add_form_def(
                form_name,
                address_form_class,
                kwargs={
                    "instance": _get_default_address_for_contact(company, "default_%s_address" % form_name, person)
                }
            )
        self.add_form_def("contact", CompanyContactForm, kwargs={"instance": company})
コード例 #37
0
ファイル: views.py プロジェクト: gurch101/shuup
    def form_valid(self, form):
        contact = form["contact"].save()
        user = contact.user
        billing_address = form["billing"].save()
        shipping_address = form["shipping"].save()
        if billing_address.pk != contact.default_billing_address_id:  # Identity changed due to immutability
            contact.default_billing_address = billing_address
        if shipping_address.pk != contact.default_shipping_address_id:  # Identity changed due to immutability
            contact.default_shipping_address = shipping_address

        if not bool(get_company_contact(self.request.user)):  # Only update user details for non-company members
            user.email = contact.email
            user.first_name = contact.first_name
            user.last_name = contact.last_name
            user.save()

        contact.save()
        messages.success(self.request, _("Account information saved successfully."))
        return redirect("shuup:customer_edit")
コード例 #38
0
    def form_valid(self, form):
        contact = form["contact"].save()
        user = contact.user
        billing_address = form["billing"].save()
        shipping_address = form["shipping"].save()
        if billing_address.pk != contact.default_billing_address_id:  # Identity changed due to immutability
            contact.default_billing_address = billing_address
        if shipping_address.pk != contact.default_shipping_address_id:  # Identity changed due to immutability
            contact.default_shipping_address = shipping_address

        if not bool(get_company_contact(self.request.user)):  # Only update user details for non-company members
            user.email = contact.email
            user.first_name = contact.first_name
            user.last_name = contact.last_name
            user.save()

        contact.save()
        messages.success(self.request, _("Account information saved successfully."))
        return redirect("shuup:customer_edit")
コード例 #39
0
ファイル: views.py プロジェクト: dragonsg/shuup-1
 def get_form(self, form_class):
     contact = get_company_contact(self.request.user)
     form_group = FormGroup(**self.get_form_kwargs())
     form_group.add_form_def(
         "billing",
         AddressForm,
         kwargs={
             "instance":
             contact.default_billing_address if contact else None
         })
     form_group.add_form_def(
         "shipping",
         AddressForm,
         kwargs={
             "instance":
             contact.default_shipping_address if contact else None
         })
     form_group.add_form_def("contact",
                             CompanyContactForm,
                             kwargs={"instance": contact})
     return form_group
コード例 #40
0
ファイル: views.py プロジェクト: hrayr-artunyan/shuup
 def get_form(self, form_class):
     user = self.request.user
     company = get_company_contact(user)
     person = get_person_contact(user)
     form_group = FormGroup(**self.get_form_kwargs())
     form_group.add_form_def(
         "billing",
         AddressForm,
         kwargs={
             "instance": _get_default_address_for_contact(company, "default_billing_address", person)
         }
     )
     form_group.add_form_def(
         "shipping",
         AddressForm,
         kwargs={
             "instance": _get_default_address_for_contact(company, "default_shipping_address", person)
         }
     )
     form_group.add_form_def("contact", CompanyContactForm, kwargs={"instance": company})
     return form_group
コード例 #41
0
    def save(self):
        contact = self.forms["contact"].save()
        user = contact.user

        if "billing" in self.forms:
            billing_address = self.forms["billing"].save()
            if billing_address.pk != contact.default_billing_address_id:  # Identity changed due to immutability
                contact.default_billing_address = billing_address

        if "shipping" in self.forms:
            shipping_address = self.forms["shipping"].save()
            if shipping_address.pk != contact.default_shipping_address_id:  # Identity changed due to immutability
                contact.default_shipping_address = shipping_address

        if not bool(get_company_contact(self.request.user)):  # Only update user details for non-company members
            user.email = contact.email
            user.first_name = contact.first_name
            user.last_name = contact.last_name
            user.save()

        contact.save()
        return contact
コード例 #42
0
    def register(self, form):
        user = super(CompanyRegistrationView, self).register(form)

        if settings.SHUUP_ENABLE_MULTIPLE_SHOPS and settings.SHUUP_MANAGE_CONTACTS_PER_SHOP:
            company = get_company_contact(user)
            company.shops.add(self.request.shop)
コード例 #43
0
ファイル: views.py プロジェクト: yurkobb/shuup
 def dispatch(self, request, *args, **kwargs):
     if not (bool(get_company_contact(self.request.user))
             or allow_company_registration(self.request.shop)):
         return redirect("shuup:customer_edit")
     return super(CompanyEditView, self).dispatch(request, *args, **kwargs)
コード例 #44
0
ファイル: views.py プロジェクト: ruqaiya/shuup
 def dispatch(self, request, *args, **kwargs):
     if not (bool(get_company_contact(self.request.user)) or allow_company_registration(self.request.shop)):
         return redirect("shuup:customer_edit")
     return super(CompanyEditView, self).dispatch(request, *args, **kwargs)
コード例 #45
0
ファイル: middleware.py プロジェクト: ruqaiya/shuup
 def _set_customer(self, request):
     company = get_company_contact(request.user)
     request.customer = (company or request.person)
     request.is_company_member = bool(company)
     request.customer_groups = (company or request.person).groups.all()
コード例 #46
0
ファイル: middleware.py プロジェクト: rogasp/shuup
 def _set_customer(self, request):
     company = get_company_contact(request.user)
     request.customer = (company or request.person)
     request.is_company_member = bool(company)
     request.customer_groups = (company or request.person).groups.all()
コード例 #47
0
ファイル: views.py プロジェクト: ruqaiya/shuup
    def register(self, form):
        user = super(CompanyRegistrationView, self).register(form)

        if settings.SHUUP_ENABLE_MULTIPLE_SHOPS and settings.SHUUP_MANAGE_CONTACTS_PER_SHOP:
            company = get_company_contact(user)
            company.add_to_shop(self.request.shop)