@pytest.mark.django_db
@pytest.mark.parametrize('show_all_categories', [True, False])
def test_category_links_plugin_with_customer(rf, show_all_categories):
 shop = get_default_shop()
 group = get_default_customer_group()
 customer = create_random_person()
 customer.groups.add(group)
 customer.save()
 request = rf.get('/')
 request.shop = get_default_shop()
 apply_request_middleware(request)
 request.customer = customer
 category = get_default_category()
 category.status = CategoryStatus.VISIBLE
 category.visibility = CategoryVisibility.VISIBLE_TO_GROUPS
 category.visibility_groups.add(group)
 category.shops.add(shop)
 category.save()
 vars = {'request': request}
 context = get_jinja_context(**vars)
 plugin = CategoryLinksPlugin({'categories': [category.pk], 'show_all_categories': show_all_categories})
 assert category.is_visible(customer)
 assert (category in plugin.get_context_data(context)['categories'])
 customer_without_groups = create_random_person()
 customer_without_groups.groups.clear()
 assert (not category.is_visible(customer_without_groups))
 request.customer = customer_without_groups
 context = get_jinja_context(**vars)
 assert (category not in plugin.get_context_data(context)['categories'])

@ pytest . mark . django_db @ pytest . mark . parametrize ( 'show_all_categories' , [ True , False ] ) def test_category_links_plugin_with_customer ( rf , show_all_categories ) : shop = get_default_shop ( ) group = get_default_customer_group ( ) customer = create_random_person ( ) customer . groups . add ( group ) customer . save ( ) request = rf . get ( '/' ) request . shop = get_default_shop ( ) apply_request_middleware ( request ) request . customer = customer category = get_default_category ( ) category . status = CategoryStatus . VISIBLE category . visibility = CategoryVisibility . VISIBLE_TO_GROUPS category . visibility_groups . add ( group ) category . shops . add ( shop ) category . save ( ) vars = { 'request' : request } context = get_jinja_context ( ** vars ) plugin = CategoryLinksPlugin ( { 'categories' : [ category . pk ] , 'show_all_categories' : show_all_categories } ) assert category . is_visible ( customer ) assert ( category in plugin . get_context_data ( context ) [ 'categories' ] ) customer_without_groups = create_random_person ( ) customer_without_groups . groups . clear ( ) assert ( not category . is_visible ( customer_without_groups ) ) request . customer = customer_without_groups context = get_jinja_context ( ** vars ) assert ( category not in plugin . get_context_data ( context ) [ 'categories' ] )
test plugin for categories that is visible for certain group .