def testBugMenuItemWithoutLayout(self): # saving a MenuItem without setting a default site Layout failed site = Site.objects.get_current() menu = Menu.objects.get(main_menu=True) menu_item = MenuItem(menu=menu, name="without_layout", active=True) menu_item.save() site_settings = SiteSettings.objects.get(site=site) site_settings.save() response = self.client.get("/")
def setUp(self): site = Site(domain="mydomain.com", name="mydomain") site.save() menu = Menu.objects.create(name="Main menu", main_menu=True) menu_item = MenuItem(menu=menu, name="home", site_home=True, active=True) menu_item.save() layout = Layout(name="default", template='layout_two_columns_left.html') layout.save() site_settings = SiteSettings.objects.create(site=site, theme=DEFAULT_THEME, allow_comments='YES') site_settings.default_layout = layout site_settings.save()
def test_site_map_view(self): site = Site.objects.create(name='site', domain='site') col = Collection.objects.create(name='A collection') cat = Category(name='An instance', collection=col) cat.save() menu = Menu.objects.create(name='menu') content_type = ContentType.objects.get(model='site') MenuItem(name='site map', menu=menu, content_type=content_type, content_view="map").save() res = self.client.get('/site-map') self.assertEqual(res.status_code, 200)
def test_deletion(self): frontend.autodiscover() article = Article.objects.create(name="Article") layout = get_default_layout() region_view = RegionView(layout=layout) article_ct = ContentType.objects.get_for_model(article) region_view = RegionView.objects.create(content_object=article, layout=layout, content_view="detail") menu = Menu.objects.create(name='menu') mi = MenuItem(name='article item', menu=menu, content_object=article, content_view="detail") mi.save() self.assertEqual(RegionView.objects.count(), 1) self.assertEqual(MenuItem.objects.get().content_object, article) article.delete() self.assertEqual(RegionView.objects.count(), 0) self.assertEqual(MenuItem.objects.get().content_object, None)
class MenuItemTestCase(ViewableTestCase): test_model = MenuItem def setUp(self): self.menu = Menu.objects.create(name='menu') self.test_object = MenuItem(name='An instance', menu=self.menu) self.test_object.save() self.article = Article.objects.create(name='An article') frontend.autodiscover() def test_menu_item_without_view(self): self.test_object.content_object = self.article self.test_object.save() self.assertEqual(self.test_object.content_view, frontend.site.get_default_view_name(Article)) def test_menu_item_admin_form(self): # test without custom_url nor view/content self.assertTrue(self.build_admin_form().is_valid()) # test with custom_url self.assertTrue( self.build_admin_form({ 'custom_url': "/foo/" }).is_valid()) article_view = frontend.site.get_default_view_name(Article) article_ct_pk = ContentType.objects.get(model="article").pk # test with content_view data = { 'content_view': article_view, 'content_type': article_ct_pk, 'content_object': "%s-%s" % (article_ct_pk, self.article.pk) } self.assertTrue(self.build_admin_form(data).is_valid()) # test fail: requires content_object data = {'content_view': article_view, 'content_type': article_ct_pk} self.assertFalse(self.build_admin_form(data).is_valid()) # test fail: can't have custom_url and content data = {'custom_url': "/foo/", 'content_type': article_ct_pk} self.assertFalse(self.build_admin_form(data).is_valid()) def test_active_item(self): # home menu and An instance menu items self.assertEqual(len(frontend.site.get_menuitem_urls()), 2) self.test_object.active = False self.test_object.save() self.assertEqual(len(frontend.site.get_menuitem_urls()), 1) def build_admin_form(self, new_data=None): base_data = {'menu': self.menu.pk, 'name': 'test_mi'} base_data.update(new_data or {}) return MenuItemAdminForm(base_data)
def _menu_to_menuitem(self, menu_hash, menu_types): menu_id = self._menu_type_id(menu_types, menu_hash['menutype']) parent_id = self._tree_hierarchy(menu_hash['parent_id']) content_object_type, object_id = self._menu_content_object( menu_hash['link']) menuitem = MenuItem( id=menu_hash['id'], menu_id=menu_id, name=menu_hash['title'], site_home=menu_hash['home'] == 1, url=menu_hash['path'], # alias not unique active=menu_hash['published'] == 1, persistent_layout=False, lft=menu_hash['lft'], rght=menu_hash['rgt'], level=menu_hash['level'], tree_id=menu_hash['id'], # any value, overwritten by tree rebuild content_type_id=content_object_type, object_id=object_id, content_view=self._menu_category_view, view_options=self._menu_category_view_options) return menuitem
def create_demo_objects(self, site, demo): # MAIN MENU menu = Menu(name="Main menu", main_menu=True) menu.save() default_layout = self._get_default_layout() # HOME (MENU ITEM) menu_item = MenuItem(menu=menu, name="Inicio", site_home=True, active=True, layout=default_layout) menu_item.save() if demo: #REGIONS RegionView.objects.create(region='header', layout=default_layout, content_object=menu, weight=1, content_view='menuitems_hierarchy', view_options='{"align": "HORIZONTAL"}') site_content_type = ContentType.objects.get(name='site') RegionView.objects.create(region='right', layout=default_layout, content_type_id=site_content_type.pk, weight=1, content_view='search') # COLLECTION & CATEGORY collection_ctypes = self._get_base_ctypes() collection = Collection.objects.create( name="Contenidos", description= "Agrupa todos los contenidos generados en el sitio por el script de arranque." ) collection.content_types = collection_ctypes collection.save() category = collection.categories.create(name="Noticias") # ARTICLE (welcome) article = Article.objects.create( name="Te damos la bienvenida a CyclopeCMS", text= "Morbi cursus, enim nec mollis condimentum, nisl nisl porta tortor, ut accumsan lorem metus et nunc. Aenean eget accumsan massa. In sodales ligula eu lectus efficitur tincidunt. Nunc non massa vulputate, pellentesque sapien ac, congue erat. Nam in quam lectus. Mauris hendrerit dignissim ex, in sollicitudin ipsum lacinia vitae. Aenean pellentesque diam quis quam mollis, ac mattis ante rutrum. Sed id vulputate ligula." ) Categorization.objects.create(content_object=article, category=category) # Home menu_item.content_object = category menu_item.content_view = "contents" menu_item.view_options = self.DEFAULT_VIEW_OPTIONS menu_item.save() # CONTACT FORM contact = ContactFormSettings.objects.get(subject="Contact mail") contact_menu_item = MenuItem( menu=menu, name="Contacto", custom_url="/contact", ) contact_menu_item.save() # USER GROUPS for g in ("editors", "managers", "translators"): group, created = Group.objects.get_or_create(name=g) if created: #? group.save()
def setUp(self): self.menu = Menu.objects.create(name='menu') self.test_object = MenuItem(name='An instance', menu=self.menu) self.test_object.save() self.article = Article.objects.create(name='An article') frontend.autodiscover()