Example #1
0
def test_ajax_select_view_with_products(rf):
    activate("en")
    view = MultiselectAjaxView.as_view()
    results = _get_search_results(rf, view, "shuup.Product", "some str")
    assert len(results) == 0

    product_name_en = "The Product"
    product = create_product("the product", **{"name": product_name_en})

    product_name_fi = "product"
    product.set_current_language("fi")
    # Making sure we are not getting duplicates from translations
    product.name = "product"  # It seems that finnish translation overlaps with english name
    product.save()

    view = MultiselectAjaxView.as_view()
    results = _get_search_results(rf, view, "shuup.Product", "some str")
    assert len(results) == 0

    results = _get_search_results(rf, view, "shuup.Product", "product")
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_en

    activate("fi")
    results = _get_search_results(rf, view, "shuup.Product", "product")
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_fi
Example #2
0
def test_ajax_select_view_with_products(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    # No products, no results
    results = _get_search_results(rf, view, "shuup.Product", "some str", admin_user)
    assert len(results) == 0

    product_name_en = "The Product"
    product = create_product("the product", shop=shop, **{"name": product_name_en})
    shop_product = product.get_shop_instance(shop)

    product_name_fi = "tuote"
    product.set_current_language("fi")
    # Making sure we are not getting duplicates from translations
    product.name = product_name_fi  # It seems that finnish translation overlaps with english name
    product.save()

    view = MultiselectAjaxView.as_view()

    results = _get_search_results(rf, view, "shuup.Product", "some str", admin_user)
    assert len(results) == 0

    results = _get_search_results(rf, view, "shuup.Product", None, admin_user)
    assert len(results) == 0

    results = _get_search_results(rf, view, "shuup.Product", "product", admin_user)
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_en

    results = _get_search_results(rf, view, "shuup.ShopProduct", "product", admin_user)
    assert len(results) == 1
    assert results[0].get("id") == shop_product.id
    assert results[0].get("name") == product_name_en

    activate("fi")
    results = _get_search_results(rf, view, "shuup.Product", "product", admin_user)
    assert get_language() == 'fi'
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_fi

    results = _get_search_results(rf, view, "shuup.Product", "  product  ", admin_user)
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_fi

    product.soft_delete()
    results = _get_search_results(rf, view, "shuup.Product", "product", admin_user)
    assert len(results) == 0
Example #3
0
def test_multiselect_inactive_users_and_contacts(rf, regular_user):
    """
    Make sure inactive users and contacts are filtered from search results.
    """
    view = MultiselectAjaxView.as_view()
    assert "joe" in regular_user.username

    results = _get_search_results(rf, view, "auth.User", "joe")
    assert len(results) == 1
    assert results[0].get("id") == regular_user.id
    assert results[0].get("name") == regular_user.username

    contact = PersonContact.objects.create(first_name="Joe", last_name="Somebody")

    results = _get_search_results(rf, view, "shuup.PersonContact", "joe")

    assert len(results) == 1
    assert results[0].get("id") == contact.id
    assert results[0].get("name") == contact.name

    contact.is_active = False
    contact.save()

    results = _get_search_results(rf, view, "shuup.PersonContact", "joe")

    assert len(results) == 0
Example #4
0
def test_ajax_select_view_with_contacts(rf, contact_cls, admin_user):
    shop = get_default_shop()
    view = MultiselectAjaxView.as_view()

    results = _get_search_results(rf, view, "", "some str", admin_user)
    assert len(results) == 0

    model_name = "shuup.%s" % contact_cls._meta.model_name
    results = _get_search_results(rf, view, model_name, "some str", admin_user)
    assert len(results) == 0

    # customer doesn't belong to shop
    customer = contact_cls.objects.create(name="Michael Jackson", email="*****@*****.**")
    results = _get_search_results(rf, view, model_name, "michael", admin_user)
    assert len(results) == 0

    customer.add_to_shop(shop)
    results = _get_search_results(rf, view, model_name, "michael", admin_user)
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(rf, view, model_name, "jacks", admin_user)
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(rf, view, model_name, "el@ex", admin_user)
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(rf, view, model_name, "random", admin_user)  # Shouldn't find anything with this
    assert len(results) == 0
def test_coupon_with_supplier_filter(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    superuser1 = create_random_user(is_superuser=True, is_staff=True)
    supplier1 = Supplier.objects.create(identifier=superuser1.username)
    superuser2 = create_random_user(is_superuser=True, is_staff=True)
    supplier2 = Supplier.objects.create(identifier=superuser2.username)

    supplier_provider = "shuup.testing.supplier_provider.UsernameSupplierProvider"
    with override_settings(
            SHUUP_ADMIN_SUPPLIER_PROVIDER_SPEC=supplier_provider):
        code = Coupon.objects.create(code="LEAFS",
                                     active=True,
                                     shop=shop,
                                     supplier=supplier1)
        results = _get_search_results(rf, view, "campaigns.Coupon", "LEAFS",
                                      superuser1)
        assert len(results) == 1
        assert results[0].get("id") == code.id
        assert results[0].get("name") == code.code

        results = _get_search_results(rf, view, "campaigns.Coupon", "LEAFS",
                                      superuser2)
        assert len(results) == 0
Example #6
0
def get_urls():
    urls = []
    urls.extend(get_module_urls())

    urls.extend([
        admin_url(r'^$', DashboardView.as_view(), name='dashboard', permissions=()),
        admin_url(r'^home/$', HomeView.as_view(), name='home', permissions=()),
        admin_url(r'^wizard/$', WizardView.as_view(), name='wizard', permissions=()),
        admin_url(r'^tour/$', TourView.as_view(), name='tour', permissions=()),
        admin_url(r'^search/$', SearchView.as_view(), name='search', permissions=()),
        admin_url(r'^select/$', MultiselectAjaxView.as_view(), name='select', permissions=()),
        admin_url(r'^edit/$', EditObjectView.as_view(), name='edit', permissions=()),
        admin_url(r'^menu/$', MenuView.as_view(), name='menu', permissions=()),
        admin_url(r'^toggle-menu/$', MenuToggleView.as_view(), name='menu_toggle', permissions=()),
        admin_url(
            r'^login/$',
            login,
            kwargs={"template_name": "shuup/admin/auth/login.jinja"},
            name='login',
            require_authentication=False,
            permissions=()
        ),
        admin_url(
            r'^logout/$',
            auth_views.logout,
            kwargs={"template_name": "shuup/admin/auth/logout.jinja"},
            name='logout',
            require_authentication=False,
            permissions=()
        ),
        admin_url(
            r'^recover-password/(?P<uidb64>.+)/(?P<token>.+)/$',
            ResetPasswordView,
            name='recover_password',
            require_authentication=False,
            permissions=()
        ),
        admin_url(
            r'^request-password/$',
            RequestPasswordView,
            name='request_password',
            require_authentication=False,
            permissions=()
        ),
        admin_url(
            r'^set-language/$',
            csrf_exempt(set_language),
            name="set-language",
            permissions=()
        ),
    ])

    for u in urls:  # pragma: no cover
        if not isinstance(u, AdminRegexURLPattern):
            warnings.warn("Admin URL %r is not an AdminRegexURLPattern" % u)

    # Add Django javascript catalog url
    urls.append(url(r'^i18n.js$', javascript_catalog_all, name='js-catalog'))

    return tuple(urls)
Example #7
0
def test_multi_select_with_product_sales_unit(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    gram = SalesUnit.objects.create(symbol="g", name="Grams")
    create_product("gram", shop=shop, **{"name": "Gram Product", "sales_unit": gram})

    pieces = SalesUnit.objects.create(symbol="pcs", name="Pieces")
    create_product("pcs", shop=shop, **{"name": "Pieces Product", "sales_unit": pieces})

    kg = SalesUnit.objects.create(symbol="kg", name="Kilograms")
    create_product("kg", shop=shop, **{"name": "Kilogram Product", "sales_unit": kg})

    oz = SalesUnit.objects.create(symbol="oz", name="Ounce")
    create_product("oz", shop=shop, **{"name": "Ounce Product", "sales_unit": oz})


    view = MultiselectAjaxView.as_view()

    results = _get_search_results(rf, view, "shuup.Product", "Product", admin_user)
    assert len(results) == 4

    assert len(_get_search_results(rf, view, "shuup.Product", "Product", admin_user, sales_units="g")) == 1
    assert len(_get_search_results(rf, view, "shuup.Product", "Product", admin_user, sales_units="pcs")) == 1
    assert len(_get_search_results(rf, view, "shuup.Product", "Product", admin_user, sales_units="kg")) == 1
    assert len(_get_search_results(rf, view, "shuup.Product", "Product", admin_user, sales_units="oz")) == 1

    assert len(_get_search_results(rf, view, "shuup.Product", "Product", admin_user, sales_units="g,oz")) == 2
    assert len(_get_search_results(rf, view, "shuup.Product", "Product", admin_user, sales_units="g,kg,pcs")) == 3
    assert len(_get_search_results(rf, view, "shuup.Product", "Product", admin_user, sales_units="oz,pcs,g,kg")) == 4
Example #8
0
def test_ajax_select_view_with_categories(rf, admin_user):
    activate("en")
    shop = get_default_shop()
    view = MultiselectAjaxView.as_view()

    # No categories, no results
    results = _get_search_results(rf, view, "shuup.Category", "some str", admin_user)
    assert len(results) == 0

    category = Category.objects.create(
        parent=None,
        identifier="test",
        name="test",
    )
    category.shops.add(shop)

    results = _get_search_results(rf, view, "shuup.Category", "some str", admin_user)
    assert len(results) == 0

    results = _get_search_results(rf, view, "shuup.Category", category.name, admin_user)
    assert len(results) == 1

    category.soft_delete()
    results = _get_search_results(rf, view, "shuup.Category", category.name, admin_user)
    assert len(results) == 0
Example #9
0
def test_multi_select_with_main_products(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    var1 = "size"
    var2 = "color"
    parent = create_product("test", shop=shop, **{"name": "test"})
    for a in range(4):
        for b in range(3):
            product_name = "test-%s-%s" % (a, b)
            child = create_product(product_name, shop=shop, **{"name": product_name})
            child.link_to_parent(parent, variables={var1: a, var2: b})
            assert child.mode == ProductMode.VARIATION_CHILD

    assert parent.variation_children.count() == 4 * 3
    assert Product.objects.count() == 4*3 + 1

    results = _get_search_results(rf, view, "shuup.Product", "test", admin_user)
    assert len(results) == Product.objects.count()

    results = _get_search_results(rf, view, "shuup.Product", "test", admin_user, "main")
    assert len(results) == 1

    create_product("test1", shop=shop, **{"name": "test 123"})
    results = _get_search_results(rf, view, "shuup.Product", "test", admin_user, "main")
    assert len(results) == 2

    create_product("2", shop=shop, **{"name": "something that doesn not match with the search term"})
    results = _get_search_results(rf, view, "shuup.Product", "test", admin_user, "main")
    assert len(results) == 2
Example #10
0
def get_urls():
    urls = []
    urls.extend(get_module_urls())

    urls.extend([
        admin_url(r'^$', DashboardView.as_view(), name='dashboard'),
        admin_url(r'^home/$', HomeView.as_view(), name='home'),
        admin_url(r'^wizard/$', WizardView.as_view(), name='wizard'),
        admin_url(r'^tour/$', TourView.as_view(), name='tour'),
        admin_url(r'^search/$', SearchView.as_view(), name='search'),
        admin_url(r'^select/$', MultiselectAjaxView.as_view(), name='select'),
        admin_url(r'^edit/$', EditObjectView.as_view(), name='edit'),
        admin_url(r'^menu/$', MenuView.as_view(), name='menu'),
        admin_url(r'^toggle-menu/$', MenuToggleView.as_view(), name='menu_toggle'),
        admin_url(
            r'^login/$',
            login,
            kwargs={"template_name": "shuup/admin/auth/login.jinja"},
            name='login',
            require_authentication=False
        ),
        admin_url(
            r'^logout/$',
            auth_views.logout,
            kwargs={"template_name": "shuup/admin/auth/logout.jinja"},
            name='logout',
            require_authentication=False
        ),
        admin_url(
            r'^recover-password/(?P<uidb64>.+)/(?P<token>.+)/$',
            ResetPasswordView,
            name='recover_password',
            require_authentication=False
        ),
        admin_url(
            r'^request-password/$',
            RequestPasswordView,
            name='request_password',
            require_authentication=False
        ),
        admin_url(
            r'^set-language/$',
            csrf_exempt(set_language),
            name="set-language"
        ),
    ])

    for u in urls:  # pragma: no cover
        if not isinstance(u, AdminRegexURLPattern):
            warnings.warn("Admin URL %r is not an AdminRegexURLPattern" % u)

    # Add Django javascript catalog url
    urls.append(url(r'^i18n.js$', javascript_catalog_all, name='js-catalog'))

    return tuple(urls)
Example #11
0
def test_multi_select_with_sellable_only_products(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    var1 = "size"
    var2 = "color"
    parent = create_product("test", shop=shop, **{"name": "test"})
    for a in range(4):
        for b in range(3):
            product_name = "test-%s-%s" % (a, b)
            child = create_product(product_name,
                                   shop=shop,
                                   **{"name": product_name})
            child.link_to_parent(parent, variables={var1: a, var2: b})
            assert child.mode == ProductMode.VARIATION_CHILD

    assert parent.variation_children.count() == 4 * 3
    assert Product.objects.count() == 4 * 3 + 1

    results = _get_search_results(rf, view, "shuup.Product", "test",
                                  admin_user)
    assert len(results) == Product.objects.count()

    results = _get_search_results(rf, view, "shuup.Product", "test",
                                  admin_user, "sellable_mode_only")
    assert len(results) == Product.objects.count() - 1

    create_product("test1", shop=shop, **{"name": "test 123"})
    results = _get_search_results(rf, view, "shuup.Product", "test",
                                  admin_user, "sellable_mode_only")
    assert len(results) == Product.objects.count(
    ) - 1  # Still only the parent is excluded
    assert Product.objects.count() == 4 * 3 + 2

    # hide all shop products
    ShopProduct.objects.all().update(
        visibility=ShopProductVisibility.NOT_VISIBLE)
    results = _get_search_results(rf, view, "shuup.Product", "test",
                                  admin_user, "sellable_mode_only")
    assert len(results) == 0

    # show them again
    ShopProduct.objects.all().update(
        visibility=ShopProductVisibility.ALWAYS_VISIBLE)
    results = _get_search_results(rf, view, "shuup.Product", "test",
                                  admin_user, "sellable_mode_only")
    assert len(results) == Product.objects.count() - 1

    # delete all products
    [product.soft_delete() for product in Product.objects.all()]
    results = _get_search_results(rf, view, "shuup.Product", "test",
                                  admin_user, "sellable_mode_only")
    assert len(results) == 0
Example #12
0
def test_ajax_select_view_with_products(rf):
    activate("en")
    view = MultiselectAjaxView.as_view()
    results = _get_search_results(rf, view, "shuup.Product", "some str")
    assert len(results) == 0

    product_name_en = "The Product"
    product = create_product("the product", **{"name": product_name_en})

    product_name_fi = "product"
    product.set_current_language("fi")
    # Making sure we are not getting duplicates from translations
    product.name = "product"  # It seems that finnish translation overlaps with english name
    product.save()

    view = MultiselectAjaxView.as_view()
    results = _get_search_results(rf, view, "shuup.Product", "some str")
    assert len(results) == 0

    results = _get_search_results(rf, view, "shuup.Product", None)
    assert len(results) == 0

    results = _get_search_results(rf, view, "shuup.Product", "product")
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_en

    activate("fi")
    results = _get_search_results(rf, view, "shuup.Product", "product")
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_fi

    results = _get_search_results(rf, view, "shuup.Product", "  product  ")
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_fi

    product.soft_delete()
    results = _get_search_results(rf, view, "shuup.Product", "product")
    assert len(results) == 0
Example #13
0
def test_ajax_select_view_with_categories(rf):
    activate("en")
    view = MultiselectAjaxView.as_view()
    results = _get_search_results(rf, view, "shuup.Category", "some str")
    assert len(results) == 0

    category = get_default_category()
    results = _get_search_results(rf, view, "shuup.Category", category.name)
    assert len(results) == 1

    category.soft_delete()
    results = _get_search_results(rf, view, "shuup.Category", category.name)
    assert len(results) == 0
Example #14
0
def test_ajax_select_view_with_categories(rf):
    activate("en")
    view = MultiselectAjaxView.as_view()
    results = _get_search_results(rf, view, "shuup.Category", "some str")
    assert len(results) == 0

    category = get_default_category()
    results = _get_search_results(rf, view, "shuup.Category", category.name)
    assert len(results) == 1

    category.soft_delete()
    results = _get_search_results(rf, view, "shuup.Category", category.name)
    assert len(results) == 0
Example #15
0
def test_select_categpru(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    category1 = Category.objects.create(name="category", status=CategoryStatus.VISIBLE)
    category2 = Category.objects.create(name="category", status=CategoryStatus.INVISIBLE)
    Category.objects.create(name="category")
    category1.shops.add(shop)
    category2.shops.add(shop)

    results = _get_search_results(rf, view, "shuup.Category", "category", admin_user)
    assert len(results) == 2

    # only visible
    results = _get_search_results(rf, view, "shuup.Category", "category", admin_user, search_mode="visible")
    assert len(results) == 1
Example #16
0
def test_select_category(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    category1 = Category.objects.create(name="category", status=CategoryStatus.VISIBLE)
    category2 = Category.objects.create(name="category", status=CategoryStatus.INVISIBLE)
    Category.objects.create(name="category")
    category1.shops.add(shop)
    category2.shops.add(shop)

    results = _get_search_results(rf, view, "shuup.Category", "category", admin_user)
    assert len(results) == 2

    # only visible
    results = _get_search_results(rf, view, "shuup.Category", "category", admin_user, search_mode="visible")
    assert len(results) == 1
Example #17
0
def test_select_supplier(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    supplier1 = Supplier.objects.create(name="supplier1", enabled=True)
    supplier2 = Supplier.objects.create(name="supplier2", enabled=False)
    Supplier.objects.create(name="supplier3", enabled=True)

    supplier1.shops.add(shop)
    supplier2.shops.add(shop)

    results = _get_search_results(rf, view, "shuup.supplier", "supplier", admin_user)
    assert len(results) == 2

    # only enabled
    results = _get_search_results(rf, view, "shuup.supplier", "supplier", admin_user, search_mode="enabled")
    assert len(results) == 1
Example #18
0
def test_ajax_select_view_with_contacts_multipleshop(rf, contact_cls):
    shop1 = get_default_shop()
    shop2 = get_shop(identifier="shop2")
    staff = create_random_user(is_staff=True)
    shop1.staff_members.add(staff)
    shop2.staff_members.add(staff)

    view = MultiselectAjaxView.as_view()
    model_name = "shuup.%s" % contact_cls._meta.model_name

    customer = contact_cls.objects.create(name="Michael Jackson", email="*****@*****.**")
    customer_shop1 = contact_cls.objects.create(name="Roberto", email="*****@*****.**")
    customer_shop2 = contact_cls.objects.create(name="Maria", email="*****@*****.**")

    results = _get_search_results(rf, view, model_name, "michael", staff)
    assert len(results) == 0

    customer.add_to_shop(shop1)
    customer.add_to_shop(shop2)
    customer_shop1.add_to_shop(shop1)
    customer_shop2.add_to_shop(shop2)

    for shop in [shop1, shop2]:
        results = _get_search_results(rf, view, model_name, "michael", staff, shop=shop)
        assert len(results) == 1
        assert results[0].get("id") == customer.id
        assert results[0].get("name") == customer.name

        results = _get_search_results(rf, view, model_name, "roberto", staff, shop=shop)
        if shop == shop1:
            assert len(results) == 1
            assert results[0].get("id") == customer_shop1.id
            assert results[0].get("name") == customer_shop1.name
        else:
            assert len(results) == 0

        results = _get_search_results(rf, view, model_name, "maria", staff, shop=shop)
        if shop == shop2:
            assert len(results) == 1
            assert results[0].get("id") == customer_shop2.id
            assert results[0].get("name") == customer_shop2.name
        else:
            assert len(results) == 0
Example #19
0
def test_multi_select_with_sellable_only_products(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    var1 = "size"
    var2 = "color"
    parent = create_product("test", shop=shop, **{"name": "test"})
    for a in range(4):
        for b in range(3):
            product_name = "test-%s-%s" % (a, b)
            child = create_product(product_name, shop=shop, **{"name": product_name})
            child.link_to_parent(parent, variables={var1: a, var2: b})
            assert child.mode == ProductMode.VARIATION_CHILD

    assert parent.variation_children.count() == 4 * 3
    assert Product.objects.count() == 4 * 3 + 1

    results = _get_search_results(rf, view, "shuup.Product", "test", admin_user)
    assert len(results) == Product.objects.count()

    results = _get_search_results(rf, view, "shuup.Product", "test", admin_user, "sellable_mode_only")
    assert len(results) ==  Product.objects.count() - 1

    create_product("test1", shop=shop, **{"name": "test 123"})
    results = _get_search_results(rf, view, "shuup.Product", "test", admin_user, "sellable_mode_only")
    assert len(results) == Product.objects.count() - 1  # Still only the parent is excluded
    assert Product.objects.count() == 4 * 3 + 2

    # hide all shop products
    ShopProduct.objects.all().update(visibility=ShopProductVisibility.NOT_VISIBLE)
    results = _get_search_results(rf, view, "shuup.Product", "test", admin_user, "sellable_mode_only")
    assert len(results) == 0

    # show them again
    ShopProduct.objects.all().update(visibility=ShopProductVisibility.ALWAYS_VISIBLE)
    results = _get_search_results(rf, view, "shuup.Product", "test", admin_user, "sellable_mode_only")
    assert len(results) == Product.objects.count() - 1

    # delete all products
    [product.soft_delete() for product in Product.objects.all()]
    results = _get_search_results(rf, view, "shuup.Product", "test", admin_user, "sellable_mode_only")
    assert len(results) == 0
Example #20
0
def test_ajax_select_view_with_contacts_multipleshop(rf, contact_cls):
    shop1 = get_default_shop()
    shop2 = get_shop(identifier="shop2")
    staff = create_random_user(is_staff=True)
    shop1.staff_members.add(staff)
    shop2.staff_members.add(staff)

    view = MultiselectAjaxView.as_view()
    model_name = "shuup.%s" % contact_cls._meta.model_name

    customer = contact_cls.objects.create(name="Michael Jackson", email="*****@*****.**")
    customer_shop1 = contact_cls.objects.create(name="Roberto", email="*****@*****.**")
    customer_shop2 = contact_cls.objects.create(name="Maria", email="*****@*****.**")

    results = _get_search_results(rf, view, model_name, "michael", staff)
    assert len(results) == 0

    customer.add_to_shop(shop1)
    customer.add_to_shop(shop2)
    customer_shop1.add_to_shop(shop1)
    customer_shop2.add_to_shop(shop2)

    for shop in [shop1, shop2]:
        results = _get_search_results(rf, view, model_name, "michael", staff, shop=shop)
        assert len(results) == 1
        assert results[0].get("id") == customer.id
        assert results[0].get("name") == customer.name

        results = _get_search_results(rf, view, model_name, "roberto", staff, shop=shop)
        if shop == shop1:
            assert len(results) == 1
            assert results[0].get("id") == customer_shop1.id
            assert results[0].get("name") == customer_shop1.name
        else:
            assert len(results) == 0

        results = _get_search_results(rf, view, model_name, "maria", staff, shop=shop)
        if shop == shop2:
            assert len(results) == 1
            assert results[0].get("id") == customer_shop2.id
            assert results[0].get("name") == customer_shop2.name
        else:
            assert len(results) == 0
def test_coupon_with_supplier_filter(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    superuser1 = create_random_user(is_superuser=True, is_staff=True)
    supplier1 = Supplier.objects.create(identifier=superuser1.username)
    superuser2 = create_random_user(is_superuser=True, is_staff=True)
    supplier2 = Supplier.objects.create(identifier=superuser2.username)

    supplier_provider = "shuup.testing.supplier_provider.UsernameSupplierProvider"
    with override_settings(SHUUP_ADMIN_SUPPLIER_PROVIDER_SPEC=supplier_provider):
        code = Coupon.objects.create(code="LEAFS", active=True, shop=shop, supplier=supplier1)
        results = _get_search_results(rf, view, "campaigns.Coupon", "LEAFS", superuser1)
        assert len(results) == 1
        assert results[0].get("id") == code.id
        assert results[0].get("name") == code.code

        results = _get_search_results(rf, view, "campaigns.Coupon", "LEAFS", superuser2)
        assert len(results) == 0
Example #22
0
def get_urls():
    urls = []
    urls.extend(get_module_urls())

    urls.extend([
        admin_url(r'^$', DashboardView.as_view(), name='dashboard'),
        admin_url(r'^home/$', HomeView.as_view(), name='home'),
        admin_url(r'^wizard/$', WizardView.as_view(), name='wizard'),
        admin_url(r'^tour/$', TourView.as_view(), name='tour'),
        admin_url(r'^search/$', SearchView.as_view(), name='search'),
        admin_url(r'^select/$', MultiselectAjaxView.as_view(), name='select'),
        admin_url(r'^menu/$', MenuView.as_view(), name='menu'),
        admin_url(
            r'^login/$',
            login,
            kwargs={"template_name": "shuup/admin/auth/login.jinja"},
            name='login',
            require_authentication=False
        ),
        admin_url(
            r'^logout/$',
            auth_views.logout,
            kwargs={"template_name": "shuup/admin/auth/logout.jinja"},
            name='logout',
            require_authentication=False
        ),
        admin_url(
            r'^set-language/$',
            csrf_exempt(set_language),
            name="set-language"
        ),
    ])

    for u in urls:  # pragma: no cover
        if not isinstance(u, AdminRegexURLPattern):
            warnings.warn("Admin URL %r is not an AdminRegexURLPattern" % u)

    # Add Django javascript catalog url
    urls.append(url(r'^i18n.js$', javascript_catalog_all, name='js-catalog'))

    return tuple(urls)
Example #23
0
def test_multi_select_with_main_products(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    var1 = "size"
    var2 = "color"
    parent = create_product("test", shop=shop, **{"name": "test"})
    for a in range(4):
        for b in range(3):
            product_name = "test-%s-%s" % (a, b)
            child = create_product(product_name,
                                   shop=shop,
                                   **{"name": product_name})
            child.link_to_parent(parent, variables={var1: a, var2: b})
            assert child.mode == ProductMode.VARIATION_CHILD

    assert parent.variation_children.count() == 4 * 3
    assert Product.objects.count() == 4 * 3 + 1

    results = _get_search_results(rf, view, "shuup.Product", "test",
                                  admin_user)
    assert len(results) == Product.objects.count()

    results = _get_search_results(rf, view, "shuup.Product", "test",
                                  admin_user, "main")
    assert len(results) == 1

    create_product("test1", shop=shop, **{"name": "test 123"})
    results = _get_search_results(rf, view, "shuup.Product", "test",
                                  admin_user, "main")
    assert len(results) == 2

    create_product(
        "2",
        shop=shop,
        **{"name": "something that doesn not match with the search term"})
    results = _get_search_results(rf, view, "shuup.Product", "test",
                                  admin_user, "main")
    assert len(results) == 2
Example #24
0
def get_urls():
    urls = []
    urls.extend(get_module_urls())

    urls.extend(
        [
            admin_url(r"^$", DashboardView.as_view(), name="dashboard"),
            admin_url(r"^home/$", HomeView.as_view(), name="home"),
            admin_url(r"^wizard/$", WizardView.as_view(), name="wizard"),
            admin_url(r"^tour/$", TourView.as_view(), name="tour"),
            admin_url(r"^search/$", SearchView.as_view(), name="search"),
            admin_url(r"^select/$", MultiselectAjaxView.as_view(), name="select"),
            admin_url(r"^menu/$", MenuView.as_view(), name="menu"),
            admin_url(
                r"^login/$",
                login,
                kwargs={"template_name": "shuup/admin/auth/login.jinja"},
                name="login",
                require_authentication=False,
            ),
            admin_url(
                r"^logout/$",
                auth_views.logout,
                kwargs={"template_name": "shuup/admin/auth/logout.jinja"},
                name="logout",
                require_authentication=False,
            ),
            admin_url(r"^set-language/$", csrf_exempt(set_language), name="set-language"),
        ]
    )

    for u in urls:  # pragma: no cover
        if not isinstance(u, AdminRegexURLPattern):
            warnings.warn("Admin URL %r is not an AdminRegexURLPattern" % u)

    # Add Django javascript catalog url
    urls.append(url(r"^i18n.js$", javascript_catalog_all, name="js-catalog"))

    return tuple(urls)
Example #25
0
def test_shop_products_with_supplier_filter(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    superuser1 = create_random_user(is_superuser=True, is_staff=True)
    supplier1 = Supplier.objects.create(identifier=superuser1.username)
    superuser2 = create_random_user(is_superuser=True, is_staff=True)
    supplier2 = Supplier.objects.create(identifier=superuser2.username)

    product_name_en = "ok"
    product = create_product("test1", shop=shop, supplier=supplier1, **{"name": product_name_en})
    shop_product = product.get_shop_instance(shop)
    assert shop_product.suppliers.filter(pk=supplier1.pk).exists()
    supplier_provider = "shuup.testing.supplier_provider.UsernameSupplierProvider"
    with override_settings(SHUUP_ADMIN_SUPPLIER_PROVIDER_SPEC=supplier_provider):
        results = _get_search_results(rf, view, "shuup.ShopProduct", "ok", superuser1)
        assert len(results) == 1
        assert results[0].get("id") == shop_product.id
        assert results[0].get("name") == product_name_en

        results = _get_search_results(rf, view, "shuup.ShopProduct", "ok", superuser2)
        assert len(results) == 0
Example #26
0
def test_ajax_select_view_with_contacts(rf, contact_cls, admin_user):
    shop = get_default_shop()
    view = MultiselectAjaxView.as_view()

    results = _get_search_results(rf, view, "", "some str", admin_user)
    assert len(results) == 0

    model_name = "shuup.%s" % contact_cls._meta.model_name
    results = _get_search_results(rf, view, model_name, "some str", admin_user)
    assert len(results) == 0

    # customer doesn't belong to shop
    customer = contact_cls.objects.create(name="Michael Jackson",
                                          email="*****@*****.**")
    results = _get_search_results(rf, view, model_name, "michael", admin_user)
    assert len(results) == 0

    customer.add_to_shop(shop)
    results = _get_search_results(rf, view, model_name, "michael", admin_user)
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(rf, view, model_name, "jacks", admin_user)
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(rf, view, model_name, "el@ex", admin_user)
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(
        rf, view, model_name, "random",
        admin_user)  # Shouldn't find anything with this
    assert len(results) == 0
Example #27
0
def test_select_supplier(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    supplier1 = Supplier.objects.create(name="supplier1", enabled=True)
    supplier2 = Supplier.objects.create(name="supplier2", enabled=False)
    Supplier.objects.create(name="supplier3", enabled=True)

    supplier1.shops.add(shop)
    supplier2.shops.add(shop)

    results = _get_search_results(rf, view, "shuup.supplier", "supplier",
                                  admin_user)
    assert len(results) == 2

    # only enabled
    results = _get_search_results(rf,
                                  view,
                                  "shuup.supplier",
                                  "supplier",
                                  admin_user,
                                  search_mode="enabled")
    assert len(results) == 1
Example #28
0
def test_multiselect_inactive_users_and_contacts(rf, regular_user, admin_user):
    """
    Make sure inactive users and contacts are filtered from search results.
    """
    shop = get_default_shop()
    view = MultiselectAjaxView.as_view()
    assert "joe" in regular_user.username

    results = _get_search_results(rf, view, "auth.User", "joe", admin_user)
    assert len(results) == 1
    assert results[0].get("id") == regular_user.id
    assert results[0].get("name") == regular_user.username

    contact = PersonContact.objects.create(first_name="Joe",
                                           last_name="Somebody")

    # contact not in shop
    results = _get_search_results(rf, view, "shuup.PersonContact", "joe",
                                  admin_user)
    assert len(results) == 0

    contact.add_to_shop(shop)
    results = _get_search_results(rf, view, "shuup.PersonContact", "joe",
                                  admin_user)
    assert len(results) == 1

    assert results[0].get("id") == contact.id
    assert results[0].get("name") == contact.name

    contact.is_active = False
    contact.save()

    results = _get_search_results(rf, view, "shuup.PersonContact", "joe",
                                  admin_user)

    assert len(results) == 0
Example #29
0
def test_ajax_select_view_with_contacts(rf, contact_cls):
    view = MultiselectAjaxView.as_view()
    model_name = "shuup.%s" % contact_cls._meta.model_name
    results = _get_search_results(rf, view, model_name, "some str")
    assert len(results) == 0

    customer = contact_cls.objects.create(name="Michael Jackson", email="*****@*****.**")
    results = _get_search_results(rf, view, model_name, "michael")
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(rf, view, model_name, "jacks")
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(rf, view, model_name, "el@ex")
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(rf, view, model_name, "random")  # Shouldn't find anything with this
    assert len(results) == 0
Example #30
0
def test_ajax_select_view_with_contacts(rf, contact_cls):
    view = MultiselectAjaxView.as_view()
    model_name = "shuup.%s" % contact_cls._meta.model_name
    results = _get_search_results(rf, view, model_name, "some str")
    assert len(results) == 0

    customer = contact_cls.objects.create(name="Michael Jackson", email="*****@*****.**")
    results = _get_search_results(rf, view, model_name, "michael")
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(rf, view, model_name, "jacks")
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(rf, view, model_name, "el@ex")
    assert len(results) == 1
    assert results[0].get("id") == customer.id
    assert results[0].get("name") == customer.name

    results = _get_search_results(rf, view, model_name, "random")  # Shouldn't find anything with this
    assert len(results) == 0
Example #31
0
def test_ajax_select_view_with_products(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    # No products, no results
    results = _get_search_results(rf, view, "shuup.Product", "some str",
                                  admin_user)
    assert len(results) == 0

    product_name_en = "The Product"
    product = create_product("the product",
                             shop=shop,
                             **{"name": product_name_en})
    shop_product = product.get_shop_instance(shop)

    product_name_fi = "tuote"
    product.set_current_language("fi")
    # Making sure we are not getting duplicates from translations
    product.name = product_name_fi  # It seems that finnish translation overlaps with english name
    product.save()

    view = MultiselectAjaxView.as_view()

    results = _get_search_results(rf, view, "shuup.Product", "some str",
                                  admin_user)
    assert len(results) == 0

    results = _get_search_results(rf, view, "shuup.Product", None, admin_user)
    assert len(results) == 0

    results = _get_search_results(rf, view, "shuup.Product", "product",
                                  admin_user)
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_en

    results = _get_search_results(rf, view, "shuup.ShopProduct", "product",
                                  admin_user)
    assert len(results) == 1
    assert results[0].get("id") == shop_product.id
    assert results[0].get("name") == product_name_en

    activate("fi")
    results = _get_search_results(rf, view, "shuup.Product", "product",
                                  admin_user)
    assert get_language() == 'fi'
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_fi

    results = _get_search_results(rf, view, "shuup.Product", "  product  ",
                                  admin_user)
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_fi

    product.soft_delete()
    results = _get_search_results(rf, view, "shuup.Product", "product",
                                  admin_user)
    assert len(results) == 0
    supplier1 = Supplier.objects.create(name="supplier1", enabled=True)
    supplier1.shops.add(shop)
    product = create_product("test-product",
                             shop,
                             default_price="200",
                             supplier=supplier1,
                             mode=ProductMode.SIMPLE_VARIATION_PARENT)
    results = _get_search_results(rf, view, "shuup.Product", "  product  ",
                                  admin_user, "parent_product")
    assert len(results) == 1

    shop2 = get_shop(identifier="shop2")
    supplier2 = Supplier.objects.create(name="supplier2", enabled=False)
    supplier2.shops.add(shop2)
    product2 = create_product("test-product-two",
                              shop2,
                              default_price="200",
                              supplier=supplier2,
                              mode=ProductMode.SIMPLE_VARIATION_PARENT)
    results = _get_search_results(rf, view, "shuup.Product", "  product  ",
                                  admin_user, "parent_product")
    assert len(results) == 1
Example #32
0
def test_multi_select_with_product_sales_unit(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    gram = SalesUnit.objects.create(symbol="g", name="Grams")
    create_product("gram",
                   shop=shop,
                   **{
                       "name": "Gram Product",
                       "sales_unit": gram
                   })

    pieces = SalesUnit.objects.create(symbol="pcs", name="Pieces")
    create_product("pcs",
                   shop=shop,
                   **{
                       "name": "Pieces Product",
                       "sales_unit": pieces
                   })

    kg = SalesUnit.objects.create(symbol="kg", name="Kilograms")
    create_product("kg",
                   shop=shop,
                   **{
                       "name": "Kilogram Product",
                       "sales_unit": kg
                   })

    oz = SalesUnit.objects.create(symbol="oz", name="Ounce")
    create_product("oz",
                   shop=shop,
                   **{
                       "name": "Ounce Product",
                       "sales_unit": oz
                   })

    view = MultiselectAjaxView.as_view()

    results = _get_search_results(rf, view, "shuup.Product", "Product",
                                  admin_user)
    assert len(results) == 4

    assert len(
        _get_search_results(rf,
                            view,
                            "shuup.Product",
                            "Product",
                            admin_user,
                            sales_units="g")) == 1
    assert len(
        _get_search_results(rf,
                            view,
                            "shuup.Product",
                            "Product",
                            admin_user,
                            sales_units="pcs")) == 1
    assert len(
        _get_search_results(rf,
                            view,
                            "shuup.Product",
                            "Product",
                            admin_user,
                            sales_units="kg")) == 1
    assert len(
        _get_search_results(rf,
                            view,
                            "shuup.Product",
                            "Product",
                            admin_user,
                            sales_units="oz")) == 1

    assert len(
        _get_search_results(rf,
                            view,
                            "shuup.Product",
                            "Product",
                            admin_user,
                            sales_units="g,oz")) == 2
    assert len(
        _get_search_results(rf,
                            view,
                            "shuup.Product",
                            "Product",
                            admin_user,
                            sales_units="g,kg,pcs")) == 3
    assert len(
        _get_search_results(rf,
                            view,
                            "shuup.Product",
                            "Product",
                            admin_user,
                            sales_units="oz,pcs,g,kg")) == 4
Example #33
0
def get_urls():
    urls = []
    urls.extend(get_module_urls())

    urls.extend([
        admin_url(r"^$",
                  DashboardView.as_view(),
                  name="dashboard",
                  permissions=()),
        admin_url(r"^home/$", HomeView.as_view(), name="home", permissions=()),
        admin_url(r"^wizard/$",
                  WizardView.as_view(),
                  name="wizard",
                  permissions=()),
        admin_url(r"^tour/$", TourView.as_view(), name="tour", permissions=()),
        admin_url(r"^search/$",
                  SearchView.as_view(),
                  name="search",
                  permissions=()),
        admin_url(r"^select/$",
                  MultiselectAjaxView.as_view(),
                  name="select",
                  permissions=()),
        admin_url(r"^edit/$",
                  EditObjectView.as_view(),
                  name="edit",
                  permissions=()),
        admin_url(r"^menu/$", MenuView.as_view(), name="menu", permissions=()),
        admin_url(r"^toggle-menu/$",
                  MenuToggleView.as_view(),
                  name="menu_toggle",
                  permissions=()),
        admin_url(
            r"^stop-impersonating-staff/$",
            stop_impersonating_staff,
            name="stop-impersonating-staff",
            permissions=(),
        ),
        admin_url(
            r"^login/$",
            login,
            kwargs={"template_name": "shuup/admin/auth/login.jinja"},
            name="login",
            require_authentication=False,
            permissions=(),
        ),
        admin_url(r"^logout/$",
                  LogoutView,
                  name="logout",
                  require_authentication=False,
                  permissions=()),
        admin_url(
            r"^recover-password/(?P<uidb64>.+)/(?P<token>.+)/$",
            ResetPasswordView,
            name="recover_password",
            require_authentication=False,
            permissions=(),
        ),
        admin_url(
            r"^request-password/$",
            RequestPasswordView,
            name="request_password",
            require_authentication=False,
            permissions=(),
        ),
        admin_url(r"^set-language/$",
                  csrf_exempt(set_language),
                  name="set-language",
                  permissions=()),
    ])

    for u in urls:  # pragma: no cover
        if not isinstance(u, AdminRegexURLPattern):
            warnings.warn(
                "Warning! Admin URL %r is not an `AdminRegexURLPattern`." % u)

    # Add Django javascript catalog url
    urls.append(url(r"^i18n.js$", javascript_catalog_all, name="js-catalog"))

    return tuple(urls)
def test_ajax_select_view_with_products(rf, admin_user):
    shop = get_default_shop()
    activate("en")
    view = MultiselectAjaxView.as_view()

    # No products, no results
    results = _get_search_results(rf, view, "shuup.Product", "some str",
                                  admin_user)
    assert len(results) == 0

    product_name_en = "The Product"
    product = create_product("the product",
                             shop=shop,
                             **{"name": product_name_en})
    shop_product = product.get_shop_instance(shop)

    product_name_fi = "tuote"
    product.set_current_language("fi")
    # Making sure we are not getting duplicates from translations
    product.name = product_name_fi  # It seems that finnish translation overlaps with english name
    product.save()

    view = MultiselectAjaxView.as_view()

    results = _get_search_results(rf, view, "shuup.Product", "some str",
                                  admin_user)
    assert len(results) == 0

    results = _get_search_results(rf, view, "shuup.Product", None, admin_user)
    assert len(results) == 0

    results = _get_search_results(rf, view, "shuup.Product", "product",
                                  admin_user)
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_en

    results = _get_search_results(rf, view, "shuup.ShopProduct", "product",
                                  admin_user)
    assert len(results) == 1
    assert results[0].get("id") == shop_product.id
    assert results[0].get("name") == product_name_en

    activate("fi")
    results = _get_search_results(rf, view, "shuup.Product", "product",
                                  admin_user)
    assert get_language() == 'fi'
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_fi

    results = _get_search_results(rf, view, "shuup.Product", "  product  ",
                                  admin_user)
    assert len(results) == 1
    assert results[0].get("id") == product.id
    assert results[0].get("name") == product_name_fi

    product.soft_delete()
    results = _get_search_results(rf, view, "shuup.Product", "product",
                                  admin_user)
    assert len(results) == 0