Exemple #1
0
def test_multishops_middleware(rf, host):
    with override_provides("xtheme", [
            "shuup_tests.xtheme.utils:FauxTheme",
            "shuup_tests.xtheme.utils:FauxTheme2"
    ]):
        shop1 = Shop.objects.create(identifier="shop1", domain="shop-1")
        shop2 = Shop.objects.create(identifier="shop2", domain="shop-test-2")

        theme_settings_shop1 = ThemeSettings.objects.create(
            theme_identifier=FauxTheme.identifier, shop=shop1)
        theme_settings_shop2 = ThemeSettings.objects.create(
            theme_identifier=FauxTheme2.identifier, shop=shop2)

        request = rf.get("/")
        request.META["HTTP_HOST"] = host

        # should apply the correct shop and the template
        apply_request_middleware(request)

        if host == "shop-1.somedomain.com":
            assert request.shop.id == shop1.id
            assert get_middleware_current_theme(
            ).identifier == FauxTheme.identifier
            assert get_middleware_current_theme(
            ).settings_obj.id == theme_settings_shop1.id
        else:
            assert request.shop.id == shop2.id
            assert get_middleware_current_theme(
            ).identifier == FauxTheme2.identifier
            assert get_middleware_current_theme(
            ).settings_obj.id == theme_settings_shop2.id
Exemple #2
0
def test_multishops_middleware(rf, host):
    with override_provides("xtheme", [
        "shuup_tests.xtheme.utils:FauxTheme",
        "shuup_tests.xtheme.utils:FauxTheme2"
    ]):
        shop1 = Shop.objects.create(identifier="shop1", domain="shop-1")
        shop2 = Shop.objects.create(identifier="shop2", domain="shop-test-2")

        theme_settings_shop1 = ThemeSettings.objects.create(theme_identifier=FauxTheme.identifier, shop=shop1)
        theme_settings_shop2 = ThemeSettings.objects.create(theme_identifier=FauxTheme2.identifier, shop=shop2)

        request = rf.get("/")
        request.META["HTTP_HOST"] = host

        # should apply the correct shop and the template
        apply_request_middleware(request)

        if host == "shop-1.somedomain.com":
            assert request.shop.id == shop1.id
            assert get_middleware_current_theme().identifier == FauxTheme.identifier
            assert get_middleware_current_theme().settings_obj.id == theme_settings_shop1.id
        else:
            assert request.shop.id == shop2.id
            assert get_middleware_current_theme().identifier == FauxTheme2.identifier
            assert get_middleware_current_theme().settings_obj.id == theme_settings_shop2.id
Exemple #3
0
def test_set_get_middleware_theme(rf):
    request = rf.get("/")

    default_shop = get_default_shop()
    shop1 = Shop.objects.create(identifier="shop1", domain="shop-1")
    shop2 = Shop.objects.create(identifier="shop2", domain="shop-test-2")

    # theme settings should be for the default shop and ClassicGray (conftest.py)
    request.shop = default_shop
    XthemeMiddleware().process_request(request)
    assert get_middleware_current_theme(
    ).identifier == ClassicGrayTheme.identifier
    assert get_middleware_current_theme(
    ).settings_obj.shop.id == default_shop.id

    # theme settings should be none, as there is no Active theme for this shop
    request.shop = shop1
    XthemeMiddleware().process_request(request)
    assert get_middleware_current_theme() is None

    # theme settings should be none, as there is no Active theme for this shop
    request.shop = shop2
    XthemeMiddleware().process_request(request)
    assert get_middleware_current_theme() is None

    # manually set the theme
    theme_settings_shop2 = ThemeSettings.objects.create(
        theme_identifier=FauxTheme2.identifier, shop=shop2)
    set_middleware_current_theme(FauxTheme2(theme_settings_shop2))
    assert get_middleware_current_theme().identifier == FauxTheme2.identifier
    assert get_middleware_current_theme().settings_obj.shop.id == shop2.id
Exemple #4
0
def test_set_get_middleware_theme(rf):
    request = rf.get("/")

    default_shop = get_default_shop()
    shop1 = Shop.objects.create(identifier="shop1", domain="shop-1")
    shop2 = Shop.objects.create(identifier="shop2", domain="shop-test-2")

    # theme settings should be for the default shop and ClassicGray (conftest.py)
    request.shop = default_shop
    XthemeMiddleware().process_request(request)
    assert get_middleware_current_theme().identifier == ClassicGrayTheme.identifier
    assert get_middleware_current_theme().settings_obj.shop.id == default_shop.id

    # theme settings should be none, as there is no Active theme for this shop
    request.shop = shop1
    XthemeMiddleware().process_request(request)
    assert get_middleware_current_theme() is None

    # theme settings should be none, as there is no Active theme for this shop
    request.shop = shop2
    XthemeMiddleware().process_request(request)
    assert get_middleware_current_theme() is None

    # manually set the theme
    theme_settings_shop2 = ThemeSettings.objects.create(theme_identifier=FauxTheme2.identifier, shop=shop2)
    set_middleware_current_theme(FauxTheme2(theme_settings_shop2))
    assert get_middleware_current_theme().identifier == FauxTheme2.identifier
    assert get_middleware_current_theme().settings_obj.shop.id == shop2.id
Exemple #5
0
def test_singleshop_middleware(rf):
    default_shop = get_default_shop()
    shop1 = Shop.objects.create(identifier="shop1", domain="shop-1")
    shop2 = Shop.objects.create(identifier="shop2", domain="shop-test-2")

    ThemeSettings.objects.create(theme_identifier=FauxTheme.identifier, shop=shop1)
    ThemeSettings.objects.create(theme_identifier=FauxTheme2.identifier, shop=shop2)

    request = rf.get("/")
    request.META["HTTP_HOST"] = "unknown.anonymous.net"

    # should apply the first shop (the default shop)
    apply_request_middleware(request)

    assert request.shop.id == default_shop.id
    # using the overrided theme (in conftest.py)
    assert get_middleware_current_theme().identifier == ClassicGrayTheme.identifier
Exemple #6
0
def test_singleshop_middleware(rf):
    default_shop = get_default_shop()
    shop1 = Shop.objects.create(identifier="shop1", domain="shop-1")
    shop2 = Shop.objects.create(identifier="shop2", domain="shop-test-2")

    ThemeSettings.objects.create(theme_identifier=FauxTheme.identifier,
                                 shop=shop1)
    ThemeSettings.objects.create(theme_identifier=FauxTheme2.identifier,
                                 shop=shop2)

    request = rf.get("/")
    request.META["HTTP_HOST"] = "unknown.anonymous.net"

    # should apply the first shop (the default shop)
    apply_request_middleware(request)

    assert request.shop.id == default_shop.id
    # using the overrided theme (in conftest.py)
    assert get_middleware_current_theme(
    ).identifier == ClassicGrayTheme.identifier