예제 #1
0
def test_category_module_search(rf, admin_user):
    cm = CategoryModule()
    category = CategoryFactory()
    shop = get_default_shop()
    request = apply_request_middleware(rf.get("/"), user=admin_user, shop=shop)
    assert not empty_iterable(cm.get_search_results(request, query=category.identifier))
    assert empty_iterable(cm.get_search_results(request, query="k"))
예제 #2
0
def test_provides():
    IDENTIFIED_OBJECT_SPEC = "%s:IdentifiedObject" % __name__
    category = str(uuid.uuid4())
    with override_provides(
            category,
        [
            IDENTIFIED_OBJECT_SPEC,
            "%s:UnidentifiedObject" % __name__,
            "%s:VeryUnidentifiedObject" % __name__,
        ],
    ):
        objects = get_provide_objects(category)
        assert set(objects) == set(
            (IdentifiedObject, UnidentifiedObject, VeryUnidentifiedObject))
        assert get_identifier_to_object_map(
            category)["identifier"] == IdentifiedObject
        assert get_identifier_to_spec_map(
            category)["identifier"] == IDENTIFIED_OBJECT_SPEC
        assert get_provide_specs_and_objects(
            category)[IDENTIFIED_OBJECT_SPEC] == IdentifiedObject

    # Test the context manager clears things correctly
    assert empty_iterable(get_provide_objects(category))
    assert empty_iterable(get_provide_specs_and_objects(category))
    assert empty_iterable(get_identifier_to_object_map(category))
    assert empty_iterable(get_identifier_to_spec_map(category))
예제 #3
0
def test_category_module_search(rf, admin_user):
    cm = CategoryModule()
    category = CategoryFactory()
    shop = get_default_shop()
    request = apply_request_middleware(rf.get("/"), user=admin_user, shop=shop)
    assert not empty_iterable(cm.get_search_results(request, query=category.identifier))
    assert empty_iterable(cm.get_search_results(request, query="k"))
예제 #4
0
def test_contact_module_search_multishop(rf):
    with override_settings(SHUUP_MANAGE_CONTACTS_PER_SHOP=True,
                           SHUUP_ENABLE_MULTIPLE_SHOPS=True):
        staff_user = create_random_user(is_staff=True)

        shop1 = get_shop(identifier="shop-1", enabled=True)
        shop2 = get_shop(identifier="shop-2", enabled=True)

        shop1.staff_members.add(staff_user)
        shop2.staff_members.add(staff_user)

        cm = ContactModule()
        contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
        contact.add_to_shop(shop2)

        request = apply_request_middleware(rf.get("/"),
                                           user=staff_user,
                                           shop=shop2)

        # find the shop
        assert not empty_iterable(
            cm.get_search_results(request, query=contact.email))
        assert not empty_iterable(
            cm.get_search_results(request, query=contact.first_name))

        # no shop found
        request = apply_request_middleware(rf.get("/"),
                                           user=staff_user,
                                           shop=shop1)
        assert empty_iterable(
            cm.get_search_results(request, query=contact.email))
예제 #5
0
def test_category_module_search(rf):
    cm = CategoryModule()
    category = CategoryFactory()
    request = rf.get("/")
    assert not empty_iterable(
        cm.get_search_results(request, query=category.identifier))
    assert empty_iterable(cm.get_search_results(request, query="k"))
예제 #6
0
def test_contact_module_search(rf):
    cm = ContactModule()
    # This test has a chance to fail if the random person is from a strange locale
    # and the database does not like it. Therefore, use `en_US` here...
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
    request = rf.get("/")
    assert not empty_iterable(cm.get_search_results(request, query=contact.email))
    assert not empty_iterable(cm.get_search_results(request, query=contact.first_name))
    assert empty_iterable(cm.get_search_results(request, query=contact.email[0]))
예제 #7
0
def test_contact_module_search(rf):
    cm = ContactModule()
    # This test has a chance to fail if the random person is from a strange locale
    # and the database does not like it. Therefore, use `en_US` here...
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
    request = rf.get("/")
    assert not empty_iterable(cm.get_search_results(request, query=contact.email))
    assert not empty_iterable(cm.get_search_results(request, query=contact.first_name))
    assert empty_iterable(cm.get_search_results(request, query=contact.email[0]))
예제 #8
0
def test_contact_module_search(rf, admin_user):
    shop = get_default_shop()
    cm = ContactModule()
    # This test has a chance to fail if the random person is from a strange locale
    # and the database does not like it. Therefore, use `en_US` here...
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
    company = create_random_company(shop)
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    assert not empty_iterable(cm.get_search_results(request, query=contact.email))
    assert not empty_iterable(cm.get_search_results(request, query=contact.first_name))
    assert not empty_iterable(cm.get_search_results(request, query=company.name))
    assert empty_iterable(cm.get_search_results(request, query="/"))
예제 #9
0
def test_contact_module_search(rf, admin_user):
    shop = get_default_shop()
    cm = ContactModule()
    # This test has a chance to fail if the random person is from a strange locale
    # and the database does not like it. Therefore, use `en_US` here...
    contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
    company = create_random_company(shop)
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    assert not empty_iterable(cm.get_search_results(request, query=contact.email))
    assert not empty_iterable(cm.get_search_results(request, query=contact.first_name))
    assert not empty_iterable(cm.get_search_results(request, query=company.name))
    assert empty_iterable(cm.get_search_results(request, query="/"))
예제 #10
0
def test_provides():
    IDENTIFIED_OBJECT_SPEC = "%s:IdentifiedObject" % __name__
    category = str(uuid.uuid4())
    with override_provides(category, [
        IDENTIFIED_OBJECT_SPEC,
        "%s:UnidentifiedObject" % __name__,
        "%s:VeryUnidentifiedObject" % __name__,
    ]):
        objects = get_provide_objects(category)
        assert set(objects) == set((IdentifiedObject, UnidentifiedObject, VeryUnidentifiedObject))
        assert get_identifier_to_object_map(category)["identifier"] == IdentifiedObject
        assert get_identifier_to_spec_map(category)["identifier"] == IDENTIFIED_OBJECT_SPEC
        assert get_provide_specs_and_objects(category)[IDENTIFIED_OBJECT_SPEC] == IdentifiedObject

    # Test the context manager clears things correctly
    assert empty_iterable(get_provide_objects(category))
    assert empty_iterable(get_provide_specs_and_objects(category))
    assert empty_iterable(get_identifier_to_object_map(category))
    assert empty_iterable(get_identifier_to_spec_map(category))
예제 #11
0
def test_product_module_search(rf, admin_user):
    get_default_shop()
    request = apply_request_middleware(rf.get("/"), user=admin_user)

    with replace_modules([ProductModule]):
        with admin_only_urls():
            default_product = get_default_product()
            model_url = get_model_url(default_product)
            sku = default_product.sku
            assert any(sr.url == model_url for sr in get_search_results(request, query=sku))  # Queries work
            assert any(sr.is_action for sr in get_search_results(request, query=sku[:5]))  # Actions work
            assert empty_iterable(get_search_results(request, query=sku[:2]))  # Short queries don't
예제 #12
0
def test_product_module_search(rf, admin_user):
    get_default_shop()
    request = apply_request_middleware(rf.get("/"), user=admin_user)

    with replace_modules([ProductModule]):
        with admin_only_urls():
            default_product = get_default_product()
            model_url = get_model_url(default_product)
            sku = default_product.sku
            assert any(sr.url == model_url for sr in get_search_results(request, query=sku))  # Queries work
            assert any(sr.is_action for sr in get_search_results(request, query=sku[:5]))  # Actions work
            assert empty_iterable(get_search_results(request, query=sku[:2]))  # Short queries don't
예제 #13
0
def test_product_module_search(rf, admin_user):
    get_default_shop()
    request = apply_request_middleware(rf.get("/"), user=admin_user)

    with replace_modules([CategoryModule, ImportAdminModule, ProductModule,
                          ProductTypeModule, ManufacturerModule, PaymentMethodModule, ShippingMethodModule]):
        with admin_only_urls():
            default_product = get_default_product()
            model_url = get_model_url(default_product, shop=get_shop(request))
            sku = default_product.sku
            assert any(sr.url == model_url for sr in get_search_results(request, query=sku))  # Queries work
            assert any(sr.is_action for sr in get_search_results(request, query=sku[:5]))  # Actions work
            assert empty_iterable(get_search_results(request, query=sku[:2]))  # Short queries don't
예제 #14
0
def test_product_module_search(rf, admin_user):
    get_default_shop()
    request = apply_request_middleware(rf.get("/"), user=admin_user)

    with replace_modules([CategoryModule, ImportAdminModule, ProductModule, MediaModule,
                          ProductTypeModule, ManufacturerModule, PaymentMethodModule, ShippingMethodModule]):
        with admin_only_urls():
            default_product = get_default_product()
            model_url = get_model_url(default_product, shop=get_shop(request))
            sku = default_product.sku
            assert any(sr.url == model_url for sr in get_search_results(request, query=sku))  # Queries work
            assert any(sr.is_action for sr in get_search_results(request, query=sku[:5]))  # Actions work
            assert empty_iterable(get_search_results(request, query=sku[:2]))  # Short queries don't
예제 #15
0
def test_contact_module_search_multishop(rf):
    with override_settings(SHUUP_MANAGE_CONTACTS_PER_SHOP=True, SHUUP_ENABLE_MULTIPLE_SHOPS=True):
        staff_user = create_random_user(is_staff=True)

        shop1 = get_shop(identifier="shop-1", enabled=True)
        shop2 = get_shop(identifier="shop-2", enabled=True)

        shop1.staff_members.add(staff_user)
        shop2.staff_members.add(staff_user)

        cm = ContactModule()
        contact = create_random_person(locale="en_US", minimum_name_comp_len=5)
        contact.add_to_shop(shop2)

        request = apply_request_middleware(rf.get("/"), user=staff_user, shop=shop2)

        # find the shop
        assert not empty_iterable(cm.get_search_results(request, query=contact.email))
        assert not empty_iterable(cm.get_search_results(request, query=contact.first_name))

        # no shop found
        request = apply_request_middleware(rf.get("/"), user=staff_user, shop=shop1)
        assert empty_iterable(cm.get_search_results(request, query=contact.email))
예제 #16
0
def test_picotable_range_filter(rf, admin_user, regular_user):
    pico = get_pico(rf, admin_user)
    one_day = datetime.timedelta(days=1)
    assert not empty_iterable(
        pico.get_data({
            "perPage": 100,
            "page": 1,
            "filters": {
                "date_joined": {
                    "min": regular_user.date_joined - one_day
                }
            }
        })["items"])
    assert not empty_iterable(
        pico.get_data({
            "perPage": 100,
            "page": 1,
            "filters": {
                "date_joined": {
                    "max": regular_user.date_joined + one_day
                }
            }
        })["items"])
예제 #17
0
def test_admin_module_base(rf, admin_user):
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    am = AdminModule()
    assert empty_iterable(am.get_urls())
    assert empty_iterable(am.get_menu_entries(request))
    assert empty_iterable(am.get_search_results(request, ""))
    assert empty_iterable(am.get_dashboard_blocks(request))
    assert empty_iterable(am.get_notifications(request))
    assert empty_iterable(am.get_activity(request, now()))
예제 #18
0
def test_admin_module_base(rf):
    request = rf.get("/")
    am = AdminModule()
    assert empty_iterable(am.get_urls())
    assert empty_iterable(am.get_menu_entries(request))
    assert empty_iterable(am.get_search_results(request, ""))
    assert empty_iterable(am.get_dashboard_blocks(request))
    assert empty_iterable(am.get_notifications(request))
    assert empty_iterable(am.get_activity(request, now()))
예제 #19
0
def test_model_type_matching():
    assert empty_iterable(Binding("x", type=Model("shuup.Contact")).get_matching_types(ATestEvent.variables))
    assert Binding("x", type=Model("shuup.Order")).get_matching_types(ATestEvent.variables) == {"order"}
예제 #20
0
def test_category_module_search(rf):
    cm = CategoryModule()
    category = CategoryFactory()
    request = rf.get("/")
    assert not empty_iterable(cm.get_search_results(request, query=category.identifier))
    assert empty_iterable(cm.get_search_results(request, query="k"))
예제 #21
0
def test_picotable_range_filter(rf, regular_user):
    pico = get_pico(rf)
    one_day = datetime.timedelta(days=1)
    assert not empty_iterable(pico.get_data({"perPage": 100, "page": 1, "filters": {"date_joined": {"min": regular_user.date_joined - one_day}}})["items"])
    assert not empty_iterable(pico.get_data({"perPage": 100, "page": 1, "filters": {"date_joined": {"max": regular_user.date_joined + one_day}}})["items"])
예제 #22
0
def test_model_type_matching():
    assert empty_iterable(
        Binding("x", type=Model("shuup.Contact")).get_matching_types(
            ATestEvent.variables))
    assert Binding("x", type=Model("shuup.Order")).get_matching_types(
        ATestEvent.variables) == {"order"}