示例#1
0
def test_product_leaf_category(authorized_client, product_in_stock,
                               default_category: Category):

    root_category = Category.objects.create(name='root', slug='root')
    default_category.parent = root_category
    default_category.save()

    def _get_products(_category):
        _url = reverse('product:category',
                       kwargs={
                           'path': _category.get_full_path(),
                           'category_id': _category.pk
                       })
        _resp = authorized_client.get(_url)

        assert _resp.status_code == 200
        return _resp

    # non-leaf category (no products must be returned)
    response = _get_products(root_category)
    assert 'filter_set' not in response.context

    # leaf category (products must be returned)
    products = models.Product.objects.all().filter(
        category__name=default_category).order_by('-price')
    response = _get_products(default_category)
    assert list(products) == list(response.context['filter_set'].qs)
示例#2
0
def test_category_formatter(db):
    main_category = Category(name="Main", slug="main")
    main_category.save()
    main_category_item = Mock(product=Mock(category=main_category))
    sub_category = Category(name="Sub", slug="sub", parent=main_category)
    sub_category.save()
    sub_category_item = Mock(product=Mock(category=sub_category))
    assert item_google_product_category(main_category_item, {}) == "Main"
    assert item_google_product_category(sub_category_item, {}) == "Main > Sub"
示例#3
0
def test_category_formatter(db):
    main_category = Category(name="Main", slug="main")
    main_category.save()
    main_category_item = Mock(product=Mock(category=main_category))
    sub_category = Category(name="Sub", slug="sub", parent=main_category)
    sub_category.save()
    sub_category_item = Mock(product=Mock(category=sub_category))
    assert item_google_product_category(main_category_item, {}) == "Main"
    assert item_google_product_category(sub_category_item, {}) == "Main > Sub"
示例#4
0
def test_category_formatter(db):
    main_category = Category(name='Main', slug='main')
    main_category.save()
    main_category_item = Mock(product=Mock(category=main_category))
    sub_category = Category(name='Sub', slug='sub', parent=main_category)
    sub_category.save()
    sub_category_item = Mock(product=Mock(category=sub_category))
    assert item_google_product_category(main_category_item, {}) == 'Main'
    assert item_google_product_category(sub_category_item, {}) == 'Main > Sub'
示例#5
0
def test_category_formatter(db):
    main_category = Category(name='Main', slug='main')
    main_category.save()
    main_category_item = Mock(product=Mock(category=main_category))
    sub_category = Category(name='Sub', slug='sub', parent=main_category)
    sub_category.save()
    sub_category_item = Mock(product=Mock(category=sub_category))
    assert item_google_product_category(main_category_item, {}) == 'Main'
    assert item_google_product_category(sub_category_item, {}) == 'Main > Sub'