def test_update_menu(mock_json_menu, menu): mock_json_menu.return_value = 'Return value' update_menu(menu) mock_json_menu.assert_called_once_with(menu) menu.refresh_from_db() assert menu.json_content == 'Return value'
def menu_with_items(menu, category, collection): menu.items.create(name="Link 1", url="http://example.com/") menu_item = menu.items.create(name="Link 2", url="http://example.com/") menu.items.create(name=category.name, category=category, parent=menu_item) menu.items.create(name=collection.name, collection=collection, parent=menu_item) update_menu(menu) return menu
def menu_with_items(menu, category, collection): menu.items.create(name='Link 1', url='http://example.com/') menu_item = menu.items.create(name='Link 2', url='http://example.com/') menu.items.create(name=category.name, category=category, parent=menu_item) menu.items.create( name=collection.name, collection=collection, parent=menu_item) update_menu(menu) return menu
def menu_with_items(menu, default_category, collection): menu.items.create(name='Link 1', url='http://example.com/') menu_item = menu.items.create(name='Link 2', url='http://example.com/') menu.items.create(name=default_category.name, category=default_category, parent=menu_item) menu.items.create(name=collection.name, collection=collection, parent=menu_item) update_menu(menu) return menu
def test_render_home_page_with_translated_menu_items( client, product, menu_with_items, site_settings, settings): settings.LANGUAGE_CODE = 'fr' site_settings.top_menu = menu_with_items site_settings.save() for item in menu_with_items.items.all(): MenuItemTranslation.objects.create( menu_item=item, language_code='fr', name='Translated name in French') update_menu(menu_with_items) response = client.get(reverse('home')) assert response.status_code == 200 assert 'Translated name in French' in str(response.content)
def site_settings(db, settings): """Create a site and matching site settings. This fixture is autouse because django.contrib.sites.models.Site and saleor.site.models.SiteSettings have a one-to-one relationship and a site should never exist without a matching settings object. """ site = Site.objects.get_or_create(name="mirumee.com", domain="mirumee.com")[0] obj = SiteSettings.objects.get_or_create(site=site)[0] settings.SITE_ID = site.pk main_menu = Menu.objects.get_or_create( name=settings.DEFAULT_MENUS['top_menu_name'])[0] update_menu(main_menu) secondary_menu = Menu.objects.get_or_create( name=settings.DEFAULT_MENUS['bottom_menu_name'])[0] update_menu(secondary_menu) obj.top_menu = main_menu obj.bottom_menu = secondary_menu obj.save() return obj
def site_settings(db, settings): """Create a site and matching site settings. This fixture is autouse because django.contrib.sites.models.Site and saleor.site.models.SiteSettings have a one-to-one relationship and a site should never exist without a matching settings object. """ site = Site.objects.get_or_create( name="mirumee.com", domain="mirumee.com")[0] obj = SiteSettings.objects.get_or_create(site=site)[0] settings.SITE_ID = site.pk main_menu = Menu.objects.get_or_create( name=settings.DEFAULT_MENUS['top_menu_name'])[0] update_menu(main_menu) secondary_menu = Menu.objects.get_or_create( name=settings.DEFAULT_MENUS['bottom_menu_name'])[0] update_menu(secondary_menu) obj.top_menu = main_menu obj.bottom_menu = secondary_menu obj.save() return obj