Beispiel #1
0
def test_wishlist_create_with_product(admin_user, rf):
    activate("en")
    shop1 = get_shop(identifier="shop1", domain="shop1", name="shop1")
    shop2 = get_shop(identifier="shop2", domain="shop2", name="shop2")

    person = get_person_contact(admin_user)

    create_product("p1_s1", shop1, get_default_supplier())
    create_product("p1_s2", shop2, get_default_supplier())
    product2_s1 = create_product("p2_s1", shop1, get_default_supplier())
    product2_s2 = create_product("p2_s2", shop2, get_default_supplier())

    shop1_product2 = product2_s1.get_shop_instance(shop1)
    view_func = WishlistCreateView.as_view()
    request = rf.post("/", {
        "name": "foo",
        "privacy": 0,
        "shop_product_id": shop1_product2.id
    },
                      HTTP_HOST=shop1.domain)
    assert_wishlist(request, shop1, person, view_func, 1)

    shop2_product2 = product2_s2.get_shop_instance(shop2)
    request = rf.post("/", {
        "name": "foo",
        "privacy": 0,
        "shop_product_id": shop2_product2.id
    },
                      HTTP_HOST=shop2.domain)
    assert_wishlist(request, shop2, person, view_func, 1)
Beispiel #2
0
def test_wishlist_create_invalid(admin_user, rf):
    shop = get_default_shop()
    person = get_person_contact(admin_user)
    view_func = WishlistCreateView.as_view()
    request = apply_request_middleware(rf.post("/"), shop=shop, user=person.user)
    response = view_func(request)

    assert response.status_code == 400
Beispiel #3
0
def test_wishlist_create_invalid(admin_user, rf):
    shop = get_default_shop()
    person = get_person_contact(admin_user)
    view_func = WishlistCreateView.as_view()
    request = apply_request_middleware(rf.post("/"), shop=shop, user=person.user)
    response = view_func(request)

    assert response.status_code == 400
Beispiel #4
0
def test_wishlist_create_get_context_data(admin_user, rf):
    shop = get_default_shop()
    person = get_person_contact(admin_user)
    view_func = WishlistCreateView.as_view()
    request = apply_request_middleware(rf.get("/?shop_product_id=1"), shop=shop, user=person.user)
    response = view_func(request)

    assert response.status_code == 200
    assert 'shop_product_id' in response.context_data.keys()
    assert response.context_data.get('shop_product_id') == '1'
Beispiel #5
0
def test_wishlist_create_get_context_data(admin_user, rf):
    shop = get_default_shop()
    person = get_person_contact(admin_user)
    view_func = WishlistCreateView.as_view()
    request = apply_request_middleware(rf.get("/?shop_product_id=1"), shop=shop, user=person.user)
    response = view_func(request)

    assert response.status_code == 200
    assert 'shop_product_id' in response.context_data.keys()
    assert response.context_data.get('shop_product_id') == '1'
Beispiel #6
0
def test_wishlist_create_with_deleted_product(admin_user, rf):
    shop = get_default_shop()
    person = get_person_contact(admin_user)
    product = get_default_product()
    product.soft_delete(admin_user)
    shop_product = product.get_shop_instance(shop)
    view_func = WishlistCreateView.as_view()
    request = rf.post("/", {"name": "foo", "privacy": 0, "shop_product_id": shop_product.id})
    request = apply_request_middleware(request, shop=shop, user=person.user)
    response = view_func(request)

    assert response.status_code == 400
Beispiel #7
0
def test_wishlist_create_with_deleted_product(admin_user, rf):
    shop = get_default_shop()
    person = get_person_contact(admin_user)
    product = get_default_product()
    product.soft_delete(admin_user)
    shop_product = product.get_shop_instance(shop)
    view_func = WishlistCreateView.as_view()
    request = rf.post("/", {"name": "foo", "privacy": 0, "shop_product_id": shop_product.id})
    request = apply_request_middleware(request, shop=shop, user=person.user)
    response = view_func(request)

    assert response.status_code == 400
Beispiel #8
0
def test_wishlist_create(admin_user, rf):
    shop = get_default_shop()
    person = get_person_contact(admin_user)
    view_func = WishlistCreateView.as_view()
    request = rf.post("/", {"name": "foo", "privacy": 0})
    request = apply_request_middleware(request, shop=shop, customer=person)
    response = view_func(request)
    data = json.loads(response.content.decode("utf-8"))
    wishlists = Wishlist.objects.filter(shop=shop, customer=person).all()
    wishlist = wishlists.first()

    assert response.status_code == 200
    assert data.get('name', '') == 'foo'
    assert data.get('created', False)
    assert str(wishlist) == wishlist.name
    assert wishlists.count() == 1
    assert wishlist.name == 'foo'
    assert wishlist.privacy == WishlistPrivacy.PUBLIC
    assert wishlist.products.count() == 0
Beispiel #9
0
def test_wishlist_create_with_product(admin_user, rf):
    activate("en")
    shop1 = get_shop(identifier="shop1", domain="shop1", name="shop1")
    shop2 = get_shop(identifier="shop2", domain="shop2", name="shop2")

    person = get_person_contact(admin_user)

    create_product("p1_s1", shop1, get_default_supplier())
    create_product("p1_s2", shop2, get_default_supplier())
    product2_s1 = create_product("p2_s1", shop1, get_default_supplier())
    product2_s2 = create_product("p2_s2", shop2, get_default_supplier())

    shop1_product2 = product2_s1.get_shop_instance(shop1)
    view_func = WishlistCreateView.as_view()
    request = rf.post("/", {"name": "foo", "privacy": 0, "shop_product_id": shop1_product2.id}, HTTP_HOST=shop1.domain)
    assert_wishlist(request, shop1, person, view_func, 1)

    shop2_product2 = product2_s2.get_shop_instance(shop2)
    request = rf.post("/", {"name": "foo", "privacy": 0, "shop_product_id": shop2_product2.id}, HTTP_HOST=shop2.domain)
    assert_wishlist(request, shop2, person, view_func, 1)
Beispiel #10
0
def test_wishlist_create(admin_user, rf):
    shop = get_default_shop()
    person = get_person_contact(admin_user)
    view_func = WishlistCreateView.as_view()
    request = rf.post("/", {"name": "foo", "privacy": 0})
    assert_wishlist(request, shop, person, view_func, 0)
Beispiel #11
0
def test_wishlist_create(admin_user, rf):
    shop = get_default_shop()
    person = get_person_contact(admin_user)
    view_func = WishlistCreateView.as_view()
    request = rf.post("/", {"name": "foo", "privacy": 0})
    assert_wishlist(request, shop, person, view_func, 0)