• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.get_person_contact函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shuup.core.models.get_person_contact函数的典型用法代码示例。如果您正苦于以下问题:Python get_person_contact函数的具体用法?Python get_person_contact怎么用?Python get_person_contact使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_person_contact函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_view_shared_wishlist_detail

def test_view_shared_wishlist_detail(rf, admin_user, regular_user, is_anonymous):
    shop = get_default_shop()
    admin_person = get_person_contact(admin_user)
    regular_person = get_person_contact(regular_user)
    product = get_default_product()
    shop_product = product.get_shop_instance(shop)

    wishlist = Wishlist.objects.create(shop=shop, customer=admin_person, name='foo', privacy=WishlistPrivacy.SHARED)
    wishlist.products.add(shop_product)
    view_func = WishlistCustomerDetailView.as_view()

    if(is_anonymous):
        request = apply_request_middleware(rf.get("/"))
        assert request.customer.pk is None
        response = view_func(request, pk=wishlist.pk)
        assert response.status_code == 302
        assert response.url.endswith(reverse('shuup:index'))
    else:
        request = apply_request_middleware(rf.get("/"), user=regular_person.user)
        response = view_func(request, pk=wishlist.pk)
        assert response.status_code == 200
        assert 'customer_wishlist' in response.context_data
        assert not response.context_data["is_owner"]
        assert response.context_data['customer_wishlist'].name == wishlist.name
        assert response.context_data['customer_wishlist'].products.count() == 1
开发者ID:shuup,项目名称:shuup-wishlist,代码行数:25,代码来源:test_views.py


示例2: test_company_contact_for_shop_staff

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
开发者ID:ruqaiya,项目名称:shuup,代码行数:32,代码来源:test_utils_users.py


示例3: new

    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)
开发者ID:ruqaiya,项目名称:shuup,代码行数:34,代码来源:basket.py


示例4: test_product_visibility

def test_product_visibility(rf, admin_user, regular_user):
    anon_contact = get_person_contact(AnonymousUser())
    shop_product = get_default_shop_product()
    admin_contact = get_person_contact(admin_user)
    regular_contact = get_person_contact(regular_user)


    with modify(shop_product.product, deleted=True):  # NB: assigning to `product` here works because `get_shop_instance` populates `_product_cache`
        assert error_exists(shop_product.get_visibility_errors(customer=anon_contact), "product_deleted")
        assert error_exists(shop_product.get_visibility_errors(customer=admin_contact), "product_deleted")
        with pytest.raises(ProductNotVisibleProblem):
            shop_product.raise_if_not_visible(anon_contact)
        assert not shop_product.is_list_visible()

    with modify(shop_product, visibility_limit=ProductVisibility.VISIBLE_TO_ALL, visibility=ShopProductVisibility.NOT_VISIBLE):
        assert error_exists(shop_product.get_visibility_errors(customer=anon_contact), "product_not_visible")
        assert error_does_not_exist(shop_product.get_visibility_errors(customer=admin_contact), "product_not_visible")
        assert not shop_product.is_list_visible()

    with modify(shop_product, visibility_limit=ProductVisibility.VISIBLE_TO_LOGGED_IN, visibility=ShopProductVisibility.ALWAYS_VISIBLE):
        assert error_exists(shop_product.get_visibility_errors(customer=anon_contact), "product_not_visible_to_anonymous")
        assert error_does_not_exist(shop_product.get_visibility_errors(customer=admin_contact), "product_not_visible_to_anonymous")

    customer_group = get_default_customer_group()
    grouped_user = get_user_model().objects.create_user(username=printable_gibberish(20))
    grouped_contact = get_person_contact(grouped_user)
    with modify(shop_product, visibility_limit=ProductVisibility.VISIBLE_TO_GROUPS, visibility=ShopProductVisibility.ALWAYS_VISIBLE):
        shop_product.visibility_groups.add(customer_group)
        customer_group.members.add(grouped_contact)
        customer_group.members.remove(get_person_contact(regular_user))
        assert error_does_not_exist(shop_product.get_visibility_errors(customer=grouped_contact), "product_not_visible_to_group")
        assert error_does_not_exist(shop_product.get_visibility_errors(customer=admin_contact), "product_not_visible_to_group")
        assert error_exists(shop_product.get_visibility_errors(customer=regular_contact), "product_not_visible_to_group")
开发者ID:hrayr-artunyan,项目名称:shuup,代码行数:33,代码来源:test_products_in_shops.py


示例5: test_login_as_user_errors

def test_login_as_user_errors(rf, admin_user, regular_user):
    get_default_shop()
    view_func = LoginAsUserView.as_view()
    request = apply_request_middleware(rf.post("/"), user=regular_user, skip_session=True)

    # log in as self
    with pytest.raises(Problem):
        view_func(request, pk=regular_user.pk)

    user = UserFactory()
    get_person_contact(user)
    # non superuser trying to login as someone else
    with pytest.raises(PermissionDenied):
        view_func(request, pk=user.pk)

    request = apply_request_middleware(rf.post("/"), user=admin_user)
    user.is_superuser = True
    user.save()
    # user is trying to login as another superuser
    with pytest.raises(PermissionDenied):
        view_func(request, pk=user.pk)

    user.is_superuser = False
    user.is_staff = True
    user.save()
    # user is trying to login as a staff user
    with pytest.raises(PermissionDenied):
        view_func(request, pk=user.pk)

    user.is_staff = False
    user.is_active = False
    user.save()
    # user is trying to login as an inactive user
    with pytest.raises(Problem):
        view_func(request, pk=user.pk)
开发者ID:ruqaiya,项目名称:shuup,代码行数:35,代码来源:test_user_module.py


示例6: test_product_query

def test_product_query(admin_user, regular_user):
    anon_contact = AnonymousContact()
    shop_product = get_default_shop_product()
    shop = shop_product.shop
    product = shop_product.product
    regular_contact = get_person_contact(regular_user)
    admin_contact = get_person_contact(admin_user)


    with modify(shop_product, save=True,
                listed=True,
                visible=True,
                visibility_limit=ProductVisibility.VISIBLE_TO_ALL
                ):
        assert Product.objects.list_visible(shop=shop, customer=anon_contact).filter(pk=product.pk).exists()

    with modify(shop_product, save=True,
                listed=False,
                visible=True,
                visibility_limit=ProductVisibility.VISIBLE_TO_ALL
                ):
        assert not Product.objects.list_visible(shop=shop, customer=anon_contact).filter(pk=product.pk).exists()
        assert not Product.objects.list_visible(shop=shop, customer=regular_contact).filter(pk=product.pk).exists()
        assert Product.objects.list_visible(shop=shop, customer=admin_contact).filter(pk=product.pk).exists()

    with modify(shop_product, save=True,
                listed=True,
                visible=True,
                visibility_limit=ProductVisibility.VISIBLE_TO_LOGGED_IN
                ):
        assert not Product.objects.list_visible(shop=shop, customer=anon_contact).filter(pk=product.pk).exists()
        assert Product.objects.list_visible(shop=shop, customer=regular_contact).filter(pk=product.pk).exists()

    product.soft_delete()
    assert not Product.objects.all_except_deleted().filter(pk=product.pk).exists()
开发者ID:ahmadzai,项目名称:shuup,代码行数:35,代码来源:test_products.py


示例7: test_comment_visibility

def test_comment_visibility(admin_user):
    shop = factories.get_default_shop()

    admin_contact = get_person_contact(admin_user)

    staff_user = factories.create_random_user("en", is_staff=True)
    staff_contact = get_person_contact(staff_user)
    shop.staff_members.add(staff_user)

    normal_user = factories.create_random_user("en")
    normal_contact = get_person_contact(normal_user)

    task_type = TaskType.objects.create(name="Request", shop=shop)
    task = create_task(shop, admin_contact, task_type, "my task")

    task.comment(admin_contact, "This is only visibile for super users", TaskCommentVisibility.ADMINS_ONLY)
    task.comment(staff_contact, "This is only visibile for staff only", TaskCommentVisibility.STAFF_ONLY)
    task.comment(normal_contact, "This is visibile for everyone", TaskCommentVisibility.PUBLIC)

    # admin see all comments
    assert task.comments.for_contact(admin_contact).count() == 3
    # staff see all public + staff only
    assert task.comments.for_contact(staff_contact).count() == 2
    # normal contact see all public
    assert task.comments.for_contact(normal_contact).count() == 1
    # anonymous contact see all public
    assert task.comments.for_contact(AnonymousContact()).count() == 1
开发者ID:ruqaiya,项目名称:shuup,代码行数:27,代码来源:test_tasks.py


示例8: test_forcing_to_person_and_anonymous_contact

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
开发者ID:ruqaiya,项目名称:shuup,代码行数:25,代码来源:test_utils_users.py


示例9: test_login_as_user

def test_login_as_user(rf, admin_user, regular_user):
    get_default_shop()
    view_func = LoginAsUserView.as_view()
    request = apply_request_middleware(rf.post("/"), user=admin_user)
    get_person_contact(regular_user)
    response = view_func(request, pk=regular_user.pk)
    assert response["location"] == reverse("shuup:index")
    assert get_user(request) == regular_user
开发者ID:ruqaiya,项目名称:shuup,代码行数:8,代码来源:test_user_module.py


示例10: _set_person

 def _set_person(self, request):
     request.person = get_person_contact(request.user)
     if not request.person.is_active:
         messages.add_message(request, messages.INFO, _("Logged out since this account is inactive."))
         logout(request)
         # Usually logout is connected to the `refresh_on_logout`
         # method via a signal and that already sets request.person
         # to anonymous, but set it explicitly too, just to be sure
         request.person = get_person_contact(None)
开发者ID:ruqaiya,项目名称:shuup,代码行数:9,代码来源:middleware.py


示例11: test_omniscience

def test_omniscience(admin_user, regular_user):
    assert not get_person_contact(admin_user).is_all_seeing
    configuration.set(None, get_all_seeing_key(admin_user), True)
    assert get_person_contact(admin_user).is_all_seeing
    assert not get_person_contact(regular_user).is_all_seeing
    assert not get_person_contact(None).is_all_seeing
    assert not get_person_contact(AnonymousUser()).is_all_seeing
    assert not AnonymousContact().is_all_seeing
    configuration.set(None, get_all_seeing_key(admin_user), False)
开发者ID:suutari,项目名称:shoop,代码行数:9,代码来源:test_contacts.py


示例12: test_company_tax_number_limitations

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 = "derpy"
    new_user_username = "derpy"
    user = User.objects.create_user(new_user_username, "[email protected]", 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.
开发者ID:shawnadelic,项目名称:shuup,代码行数:54,代码来源:test_customer_information.py


示例13: test_create_order

def test_create_order(admin_user, settings, target_customer):
    configure(settings)
    shop = factories.get_default_shop()
    basket = factories.get_basket()
    factories.create_default_order_statuses()
    shop_product = factories.get_default_shop_product()
    shop_product.default_price = TaxfulPrice(1, shop.currency)
    shop_product.save()
    client = _get_client(admin_user)
    # add shop product
    payload = {
        'shop_product': shop_product.id
    }

    if target_customer == "other":
        target = factories.create_random_person()
        payload["customer_id"] = target.pk
    else:
        target = get_person_contact(admin_user)


    response = client.post('/api/shuup/basket/{}-{}/add/'.format(shop.pk, basket.key), payload)
    assert response.status_code == status.HTTP_200_OK

    response_data = json.loads(response.content.decode("utf-8"))
    assert len(response_data["items"]) == 1
    response = client.post('/api/shuup/basket/{}-{}/create_order/'.format(shop.pk, basket.key), payload)
    assert response.status_code == status.HTTP_400_BAD_REQUEST
    response_data = json.loads(response.content.decode("utf-8"))
    assert "errors" in response_data

    factories.get_default_payment_method()
    factories.get_default_shipping_method()
    response = client.post('/api/shuup/basket/{}-{}/create_order/'.format(shop.pk, basket.key), payload)
    assert response.status_code == status.HTTP_201_CREATED
    response_data = json.loads(response.content.decode("utf-8"))
    basket.refresh_from_db()
    assert basket.finished
    order = Order.objects.get(reference_number=response_data["reference_number"])
    assert order.status == OrderStatus.objects.get_default_initial()
    assert order.payment_status == PaymentStatus.NOT_PAID
    assert order.shipping_status == ShippingStatus.NOT_SHIPPED
    assert not order.payment_method
    assert not order.shipping_method
    assert float(order.taxful_total_price_value) == 1
    assert order.customer == target
    assert order.orderer == get_person_contact(admin_user)
    assert order.creator == admin_user
    assert not order.billing_address
    assert not order.shipping_address
开发者ID:suutari-ai,项目名称:shuup,代码行数:50,代码来源:test_basket_api.py


示例14: test_forcing_to_anonymous_contact

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
开发者ID:ruqaiya,项目名称:shuup,代码行数:14,代码来源:test_utils_users.py


示例15: test_address_ownership

def test_address_ownership(admin_user):
    address = get_address()
    address.save()
    saved = SavedAddress(address=address)
    saved.owner = get_person_contact(admin_user)
    assert saved.get_title(), u"get_title does what it should even if there is no explicit title"
    saved.title = u"My favorite address"
    assert saved.get_title() == saved.title, u"get_title does what it should when there is an explicit title"
    assert six.text_type(saved) == saved.get_title(), u"str() is an alias for .get_title()"
    saved.full_clean()
    saved.save()
    assert SavedAddress.objects.for_owner(get_person_contact(admin_user)).filter(address=address).exists(), \
        "contacts can save addresses"
    assert SavedAddress.objects.for_owner(None).count() == 0, "Ownerless saved addresses aren't a real thing"
开发者ID:NamiStudio,项目名称:shuup,代码行数:14,代码来源:test_addresses.py


示例16: test_view_private_wishlist_detail

def test_view_private_wishlist_detail(rf, admin_user, regular_user):
    shop = get_default_shop()
    admin_person = get_person_contact(admin_user)
    regular_person = get_person_contact(regular_user)
    product = get_default_product()
    shop_product = product.get_shop_instance(shop)

    wishlist = Wishlist.objects.create(shop=shop, customer=admin_person, name='foo', privacy=WishlistPrivacy.PRIVATE)
    wishlist.products.add(shop_product)

    view_func = WishlistCustomerDetailView.as_view()
    request = apply_request_middleware(rf.get("/"), user=regular_person.user)

    with pytest.raises(Http404):
        view_func(request, pk=wishlist.pk)
开发者ID:shuup,项目名称:shuup-wishlist,代码行数:15,代码来源:test_views.py


示例17: test_delete_other_persons_wishlist

def test_delete_other_persons_wishlist(rf, admin_user, regular_user):
    shop = get_default_shop()
    admin_person = get_person_contact(admin_user)
    person = get_person_contact(regular_user)
    product = get_default_product()
    shop_product = product.get_shop_instance(shop)

    wishlist = Wishlist.objects.create(shop=shop, customer=admin_person, name='foo', privacy=WishlistPrivacy.PUBLIC)
    wishlist.products.add(shop_product)

    view_func = WishlistDeleteView.as_view()
    request = apply_request_middleware(rf.post("/"), user=person.user)
    with pytest.raises(Http404):
        view_func(request, pk=wishlist.pk)
    assert Wishlist.objects.filter(pk=wishlist.pk).exists()
开发者ID:shuup,项目名称:shuup-wishlist,代码行数:15,代码来源:test_views.py


示例18: test_category_deletion

def test_category_deletion(admin_user):
    admin = get_person_contact(admin_user)
    category = get_default_category()
    category.children.create(identifier="foo")
    shop_product = get_default_shop_product()
    shop_product.categories.add(category)
    shop_product.primary_category = category
    shop_product.save()

    configuration.set(None, get_all_seeing_key(admin), True)

    assert category.status == CategoryStatus.VISIBLE
    assert category.children.count() == 1

    with pytest.raises(NotImplementedError):
        category.delete()

    category.soft_delete()
    shop_product.refresh_from_db()
    shop_product.product.refresh_from_db()

    assert shop_product.categories.count() == 0
    assert shop_product.primary_category is None
    assert category.status == CategoryStatus.DELETED
    assert category.children.count() == 0
    # the child category still exists
    assert Category.objects.all_visible(customer=admin).count() == 1
    assert Category.objects.all_except_deleted().count() == 1
    configuration.set(None, get_all_seeing_key(admin), False)
开发者ID:gurch101,项目名称:shuup,代码行数:29,代码来源:test_categories.py


示例19: seed_source

def seed_source(user, shop):
    source = BasketishOrderSource(shop)
    source.status = get_initial_order_status()
    source.customer = get_person_contact(user)
    source.payment_method = get_default_payment_method()
    source.shipping_method = get_default_shipping_method()
    return source
开发者ID:gurch101,项目名称:shuup,代码行数:7,代码来源:test_order_source.py


示例20: test_product_unsupplied

def test_product_unsupplied(admin_user):
    shop_product = get_default_shop_product()
    fake_supplier = Supplier.objects.create(identifier="fake")
    admin_contact = get_person_contact(admin_user)

    with modify(shop_product, visibility_limit=ProductVisibility.VISIBLE_TO_ALL, orderable=True):
        assert any(ve.code == "invalid_supplier" for ve in shop_product.get_orderability_errors(supplier=fake_supplier, customer=admin_contact, quantity=1))
开发者ID:hrayr-artunyan,项目名称:shuup,代码行数:7,代码来源:test_products_in_shops.py



注:本文中的shuup.core.models.get_person_contact函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.OrderLine类代码示例发布时间:2022-05-27
下一篇:
Python cache.clear函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap