Esempio n. 1
0
def test_forms(settings):
    shop = get_default_shop()

    # check whether the fields are dynamically added
    manager.clear_installed_samples(shop)
    consolidate_form = ConsolidateObjectsForm(**{"shop":shop})
    assert len(consolidate_form.fields) == 0

    # field categories appears
    categories = [CategoryFactory().pk, CategoryFactory().pk, CategoryFactory().pk]
    manager.save_categories(shop, categories)
    consolidate_form = ConsolidateObjectsForm(**{"shop":shop})
    assert "categories" in consolidate_form.fields

    # field products appears
    products = [ProductFactory().pk, ProductFactory().pk, ProductFactory().pk]
    manager.save_products(shop, products)
    consolidate_form = ConsolidateObjectsForm(**{"shop":shop})
    assert "products" in consolidate_form.fields

    # field carousel appears
    carousel = Carousel.objects.create(name="stuff")
    manager.save_carousel(shop, carousel.pk)
    consolidate_form = ConsolidateObjectsForm(**{"shop":shop})
    assert "carousel" in consolidate_form.fields
Esempio n. 2
0
def test_forms(settings):
    shop = get_default_shop()

    # check whether the fields are dynamically added
    manager.clear_installed_samples(shop)
    consolidate_form = ConsolidateObjectsForm(**{"shop":shop})
    assert len(consolidate_form.fields) == 0

    # field categories appears
    categories = [CategoryFactory().pk, CategoryFactory().pk, CategoryFactory().pk]
    manager.save_categories(shop, categories)
    consolidate_form = ConsolidateObjectsForm(**{"shop":shop})
    assert "categories" in consolidate_form.fields

    # field products appears
    products = [ProductFactory().pk, ProductFactory().pk, ProductFactory().pk]
    manager.save_products(shop, products)
    consolidate_form = ConsolidateObjectsForm(**{"shop":shop})
    assert "products" in consolidate_form.fields

    # field carousel appears
    carousel = Carousel.objects.create(name="stuff")
    manager.save_carousel(shop, carousel.pk)
    consolidate_form = ConsolidateObjectsForm(**{"shop":shop})
    assert "carousel" in consolidate_form.fields
Esempio n. 3
0
 def populate_samples():
     manager.clear_installed_samples(shop)
     categories = [CategoryFactory().pk, CategoryFactory().pk, CategoryFactory().pk]
     products = [ProductFactory().pk, ProductFactory().pk, ProductFactory().pk, ProductFactory().pk]
     carousel = Carousel.objects.create(name="crazy stuff").pk
     manager.save_categories(shop, categories)
     manager.save_products(shop, products)
     manager.save_carousel(shop, carousel)
Esempio n. 4
0
 def populate_samples():
     manager.clear_installed_samples(shop)
     categories = [CategoryFactory().pk, CategoryFactory().pk, CategoryFactory().pk]
     products = [ProductFactory().pk, ProductFactory().pk, ProductFactory().pk, ProductFactory().pk]
     carousel = Carousel.objects.create(name="crazy stuff").pk
     manager.save_categories(shop, categories)
     manager.save_products(shop, products)
     manager.save_carousel(shop, carousel)
Esempio n. 5
0
def test_admin(rf, admin_user):
    shop = get_default_shop()
    configuration.set(shop, "setup_wizard_complete", True)
    # just visit to make sure everything is ok
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 200

    categories = [CategoryFactory().pk, CategoryFactory().pk, CategoryFactory().pk]
    manager.save_categories(shop, categories)
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 200
Esempio n. 6
0
def test_admin(rf, admin_user):
    shop = get_default_shop()
    configuration.set(shop, "setup_wizard_complete", True)
    # just visit to make sure everything is ok
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 200

    categories = [CategoryFactory().pk, CategoryFactory().pk, CategoryFactory().pk]
    manager.save_categories(shop, categories)
    request = apply_request_middleware(rf.get("/"), user=admin_user)
    response = DashboardView.as_view()(request)
    assert response.status_code == 200
Esempio n. 7
0
    def form_valid(self, form):
        current_language = translation.get_language()
        default_language = getattr(settings, "PARLER_DEFAULT_LANGUAGE_CODE",
                                   None)

        # change the language to the PARLER_DEFAULT_LANGUAGE
        # so sample data will have data on fallback languages
        if default_language:
            translation.activate(default_language)

        shop = self.object
        form_data = form["sample"].cleaned_data
        business_segment = form_data["business_segment"]

        current_categories = sample_manager.get_installed_categories(shop)
        current_products = sample_manager.get_installed_products(shop)
        current_carousel = sample_manager.get_installed_carousel(shop)

        # only saves the business segment if there is no data installed
        # otherwise user can't change the segment
        if sample_manager.has_installed_samples(shop):
            business_segment = sample_manager.get_installed_business_segment(
                shop)
        else:
            sample_manager.save_business_segment(shop, business_segment)

        # user wants to install sample categories
        if form_data.get("categories", False) and not current_categories:
            categories = self._create_sample_categories(shop, business_segment)
            if categories:
                sample_manager.save_categories(shop, categories)

        # user wants to install sample products
        if form_data.get("products", False) and not current_products:
            products = self._create_sample_products(shop, business_segment)
            if products:
                sample_manager.save_products(shop, products)

        # user wants a carousel
        if form_data.get("carousel") and not current_carousel:
            carousel = self._create_sample_carousel(shop, business_segment)
            if carousel:
                sample_manager.save_carousel(shop, carousel.pk)

        # back to current language
        translation.activate(current_language)

        # user will no longer see this pane
        configuration.set(None, "sample_data_wizard_completed", True)
Esempio n. 8
0
    def form_valid(self, form):
        current_language = translation.get_language()
        default_language = getattr(settings, "PARLER_DEFAULT_LANGUAGE_CODE", None)

        # change the language to the PARLER_DEFAULT_LANGUAGE
        # so sample data will have data on fallback languages
        if default_language:
            translation.activate(default_language)

        shop = self.object
        form_data = form["sample"].cleaned_data
        business_segment = form_data["business_segment"]

        current_categories = sample_manager.get_installed_categories(shop)
        current_products = sample_manager.get_installed_products(shop)
        current_carousel = sample_manager.get_installed_carousel(shop)

        # only saves the business segment if there is no data installed
        # otherwise user can't change the segment
        if sample_manager.has_installed_samples(shop):
            business_segment = sample_manager.get_installed_business_segment(shop)
        else:
            sample_manager.save_business_segment(shop, business_segment)

        # user wants to install sample categories
        if form_data.get("categories", False) and not current_categories:
            categories = self._create_sample_categories(shop, business_segment)
            if categories:
                sample_manager.save_categories(shop, categories)

        # user wants to install sample products
        if form_data.get("products", False) and not current_products:
            products = self._create_sample_products(shop, business_segment)
            if products:
                sample_manager.save_products(shop, products)

        # user wants a carousel
        if form_data.get("carousel") and not current_carousel:
            carousel = self._create_sample_carousel(shop, business_segment)
            if carousel:
                sample_manager.save_carousel(shop, carousel.pk)

        # back to current language
        translation.activate(current_language)

        # user will no longer see this pane
        configuration.set(None, "sample_data_wizard_completed", True)
Esempio n. 9
0
def test_sample_data_manager():
    shop = get_default_shop()
    assert manager.get_installed_business_segment(shop) is None
    assert manager.get_installed_products(shop) == []
    assert manager.get_installed_categories(shop) == []
    assert manager.get_installed_carousel(shop) is None
    assert manager.has_installed_samples(shop) is False

    BUSINESS_SEG = "default"
    PRODUCTS = [1, 2, 3]
    CATEGORIES = [4, 5, 6]
    CAROUSEL = 1

    manager.save_categories(shop, CATEGORIES)
    manager.save_products(shop, PRODUCTS)
    manager.save_carousel(shop, CAROUSEL)
    manager.save_business_segment(shop, BUSINESS_SEG)

    assert manager.get_installed_business_segment(shop) == BUSINESS_SEG
    assert manager.get_installed_products(shop) == PRODUCTS
    assert manager.get_installed_categories(shop) == CATEGORIES
    assert manager.get_installed_carousel(shop) == CAROUSEL
    assert manager.has_installed_samples(shop) is True

    new_shop = Shop.objects.create()
    assert manager.get_installed_business_segment(new_shop) is None
    assert manager.get_installed_products(new_shop) == []
    assert manager.get_installed_categories(new_shop) == []
    assert manager.get_installed_carousel(new_shop) is None
    assert manager.has_installed_samples(new_shop) is False

    manager.clear_installed_samples(shop)
    assert manager.get_installed_business_segment(shop) is None
    assert manager.get_installed_products(shop) == []
    assert manager.get_installed_categories(shop) == []
    assert manager.get_installed_carousel(shop) is None
    assert manager.has_installed_samples(shop) is False
Esempio n. 10
0
def test_sample_data_manager():
    shop = get_default_shop()
    assert manager.get_installed_business_segment(shop) is None
    assert manager.get_installed_products(shop) == []
    assert manager.get_installed_categories(shop) == []
    assert manager.get_installed_carousel(shop) is None
    assert manager.has_installed_samples(shop) is False

    BUSINESS_SEG = "default"
    PRODUCTS = [1, 2, 3]
    CATEGORIES = [4, 5, 6]
    CAROUSEL = 1

    manager.save_categories(shop, CATEGORIES)
    manager.save_products(shop, PRODUCTS)
    manager.save_carousel(shop, CAROUSEL)
    manager.save_business_segment(shop, BUSINESS_SEG)

    assert manager.get_installed_business_segment(shop) == BUSINESS_SEG
    assert manager.get_installed_products(shop) == PRODUCTS
    assert manager.get_installed_categories(shop) == CATEGORIES
    assert manager.get_installed_carousel(shop) == CAROUSEL
    assert manager.has_installed_samples(shop) is True

    new_shop = Shop.objects.create()
    assert manager.get_installed_business_segment(new_shop) is None
    assert manager.get_installed_products(new_shop) == []
    assert manager.get_installed_categories(new_shop) == []
    assert manager.get_installed_carousel(new_shop) is None
    assert manager.has_installed_samples(new_shop) is False

    manager.clear_installed_samples(shop)
    assert manager.get_installed_business_segment(shop) is None
    assert manager.get_installed_products(shop) == []
    assert manager.get_installed_categories(shop) == []
    assert manager.get_installed_carousel(shop) is None
    assert manager.has_installed_samples(shop) is False