Exemplo n.º 1
0
 def test_add_item_to_submenu(self):
     menu = Menu([Menu.mk_menu("my-menu", u"My Menu", [])])
     menu.add_item(u"My Label", u"http://example.com", menu="my-menu")
     self.assertEqual(menu.items, [
         Menu.mk_menu("my-menu", u"My Menu",
                      [Menu.mk_item(u"My Label", u"http://example.com")])
     ])
Exemplo n.º 2
0
 def test_add_item_to_submenu(self):
     menu = Menu([
         Menu.mk_menu("my-menu", u"My Menu", [])
     ])
     menu.add_item(u"My Label", u"http://example.com", menu="my-menu")
     self.assertEqual(menu.items, [
         Menu.mk_menu("my-menu", u"My Menu", [
             Menu.mk_item(u"My Label", u"http://example.com")
         ])
     ])
Exemplo n.º 3
0
 def test_add_item_to_duplicated_submenus(self):
     menu = Menu([
         Menu.mk_menu("my-menu", u"My Menu 1", []),
         Menu.mk_menu("my-menu", u"My Menu 2", []),
     ])
     with self.assertRaisesMessage(
             MenuError, "Unable to find sub-menu 'my-menu'."):
         menu.add_item(u"My Label", u"http://example.com", menu="my-menu")
     self.assertEqual(menu.items, [
         Menu.mk_menu("my-menu", u"My Menu 1", []),
         Menu.mk_menu("my-menu", u"My Menu 2", []),
     ])
Exemplo n.º 4
0
 def test_add_item_to_duplicated_submenus(self):
     menu = Menu([
         Menu.mk_menu("my-menu", u"My Menu 1", []),
         Menu.mk_menu("my-menu", u"My Menu 2", []),
     ])
     with self.assertRaisesMessage(MenuError,
                                   "Unable to find sub-menu 'my-menu'."):
         menu.add_item(u"My Label", u"http://example.com", menu="my-menu")
     self.assertEqual(menu.items, [
         Menu.mk_menu("my-menu", u"My Menu 1", []),
         Menu.mk_menu("my-menu", u"My Menu 2", []),
     ])
Exemplo n.º 5
0
 def test_add_menu_multiple_exist(self):
     menu = Menu([
         Menu.mk_menu("my-menu", u"My Menu 1", []),
         Menu.mk_menu("my-menu", u"My Menu 2", []),
     ])
     with self.assertRaisesMessage(
             MenuError, "Multiple sub-menus named 'my-menu' exist."):
         menu.add_menu("my-menu", u"My Menu", [
             Menu.mk_item(u"Item 1", u"http://example.com/1"),
         ])
     self.assertEqual(menu.items, [
         Menu.mk_menu("my-menu", u"My Menu 1", []),
         Menu.mk_menu("my-menu", u"My Menu 2", []),
     ])
Exemplo n.º 6
0
 def test_add_menu_multiple_exist(self):
     menu = Menu([
         Menu.mk_menu("my-menu", u"My Menu 1", []),
         Menu.mk_menu("my-menu", u"My Menu 2", []),
     ])
     with self.assertRaisesMessage(
             MenuError, "Multiple sub-menus named 'my-menu' exist."):
         menu.add_menu("my-menu", u"My Menu", [
             Menu.mk_item(u"Item 1", u"http://example.com/1"),
         ])
     self.assertEqual(menu.items, [
         Menu.mk_menu("my-menu", u"My Menu 1", []),
         Menu.mk_menu("my-menu", u"My Menu 2", []),
     ])
Exemplo n.º 7
0
 def test_mk_menu_overrides(self):
     self.assertEqual(Menu.mk_menu("my-menu", u"My Menu", [], sort_key=1), {
         "menu": "my-menu",
         "label": u"My Menu",
         "items": [],
         "sort_key": 1,
     })
Exemplo n.º 8
0
 def test_mk_menu_defaults(self):
     self.assertEqual(
         Menu.mk_menu("my-menu", u"My Menu", []), {
             "menu": "my-menu",
             "label": u"My Menu",
             "items": [],
             "sort_key": None,
         })
Exemplo n.º 9
0
 def test_add_menu_exists(self):
     menu = Menu([])
     menu.add_menu("my-menu", u"My Menu",
                   [Menu.mk_item(u"Item 1", u"http://example.com/1")])
     menu.add_menu("my-menu", u"My Menu",
                   [Menu.mk_item(u"Item 2", u"http://example.com/2")])
     self.assertEqual(menu.items, [
         Menu.mk_menu("my-menu", u"My Menu", [
             Menu.mk_item(u"Item 1", u"http://example.com/1"),
             Menu.mk_item(u"Item 2", u"http://example.com/2"),
         ])
     ])
Exemplo n.º 10
0
 def test_add_menu_exists(self):
     menu = Menu([])
     menu.add_menu("my-menu", u"My Menu", [
         Menu.mk_item(u"Item 1", u"http://example.com/1")
     ])
     menu.add_menu("my-menu", u"My Menu", [
         Menu.mk_item(u"Item 2", u"http://example.com/2")
     ])
     self.assertEqual(menu.items, [
         Menu.mk_menu("my-menu", u"My Menu", [
             Menu.mk_item(u"Item 1", u"http://example.com/1"),
             Menu.mk_item(u"Item 2", u"http://example.com/2"),
         ])
     ])
Exemplo n.º 11
0
 def test_cached_menu(self):
     """Test that the default sponsor menu is generated correctly when
        a sponsor is added."""
     sponsor = create_sponsor(u"Awesome Co", [
         (u"Gold", u"*", 500),
     ])
     menu = get_cached_menus()
     self.assertEqual(menu.items, [
         Menu.mk_menu(u"sponsors", u"Sponsors", items=[
             Menu.mk_item(u"» Awesome Co", sponsor.get_absolute_url()),
             Menu.mk_item(u"Our sponsors", reverse('wafer_sponsors')),
             Menu.mk_item(u"Sponsorship packages", reverse(
                 'wafer_sponsorship_packages')),
         ])
     ])
Exemplo n.º 12
0
 def test_simple_nested_menu(self):
     about = Page.objects.create(name='About',
                                 slug='about',
                                 include_in_menu=True)
     contact = Page.objects.create(name='Contact',
                                   slug='contact',
                                   include_in_menu=True,
                                   parent=about)
     menu = Menu([])
     page_menus(menu)
     self.assertEqual(menu.items, [
         Menu.mk_menu(
             "about",
             "About",
             items=[Menu.mk_item("Contact", contact.get_absolute_url())])
     ])
Exemplo n.º 13
0
 def test_cached_menu(self):
     """Test that the default sponsor menu is generated correctly when
        a sponsor is added."""
     sponsor = create_sponsor(u"Awesome Co", [
         (u"Gold", u"*", 500),
     ])
     menu = get_cached_menus()
     self.assertEqual(menu.items, [
         Menu.mk_menu(
             u"sponsors",
             u"Sponsors",
             items=[
                 Menu.mk_item(u"» Awesome Co", sponsor.get_absolute_url()),
                 Menu.mk_item(u"Our sponsors", reverse('wafer_sponsors')),
                 Menu.mk_item(u"Sponsorship packages",
                              reverse('wafer_sponsorship_packages')),
             ])
     ])
Exemplo n.º 14
0
 def test_single_sponsor_multiple_packages(self):
     """Test that a sponsor in multiple packages only gets shown once, but with all the symbols"""
     gold_package = create_package(u"Gold", u"*", 500, 1)
     silver_package = create_package(u"Silver", u"+", 400, 2)
     bronze_package = create_package(u"Bronze", u"-", 300, 3)
     # We create 2 sponsors for each package, interleaving creation order""""
     sponsor1 = create_sponsor_in_existing_packages(
         u"Awesome1 Co", [gold_package, bronze_package])
     sponsor2 = create_sponsor_in_existing_packages(u"Awesome2 Co",
                                                    [bronze_package])
     sponsor3 = create_sponsor_in_existing_packages(
         u"Awesome3 Co", [silver_package, gold_package])
     sponsor4 = create_sponsor_in_existing_packages(u"Awesome4 Co",
                                                    [bronze_package])
     sponsor5 = create_sponsor_in_existing_packages(u"Awesome5 Co",
                                                    [silver_package])
     sponsor6 = create_sponsor_in_existing_packages(u"Awesome6 Co",
                                                    [gold_package])
     # Sponsors in the menu should be sorted by package
     menu = get_cached_menus()
     self.assertEqual(menu.items, [
         Menu.mk_menu(
             u"sponsors",
             u"Sponsors",
             items=[
                 Menu.mk_item(u"» Awesome1 Co *-",
                              sponsor1.get_absolute_url()),
                 Menu.mk_item(u"» Awesome3 Co *+",
                              sponsor3.get_absolute_url()),
                 Menu.mk_item(u"» Awesome6 Co *",
                              sponsor6.get_absolute_url()),
                 Menu.mk_item(u"» Awesome5 Co +",
                              sponsor5.get_absolute_url()),
                 Menu.mk_item(u"» Awesome2 Co -",
                              sponsor2.get_absolute_url()),
                 Menu.mk_item(u"» Awesome4 Co -",
                              sponsor4.get_absolute_url()),
                 Menu.mk_item(u"Our sponsors", reverse('wafer_sponsors')),
                 Menu.mk_item(u"Sponsorship packages",
                              reverse('wafer_sponsorship_packages')),
             ])
     ])
Exemplo n.º 15
0
    def test_multiple_packages(self):
        """Test that multiple sponsors get ordered correctly."""
        gold_package = create_package(u"Gold", u"*", 500, 1)
        silver_package = create_package(u"Silver", u"+", 400, 2)
        bronze_package = create_package(u"Bronze", u"-", 300, 3)
        # We create 2 sponsors for each package, interleaving creation order""""
        sponsor1 = create_sponsor_in_existing_packages(u"Awesome1 Co",
                                                       [gold_package])
        sponsor2 = create_sponsor_in_existing_packages(u"Awesome2 Co",
                                                       [bronze_package])
        sponsor3 = create_sponsor_in_existing_packages(u"Awesome3 Co",
                                                       [silver_package])
        sponsor4 = create_sponsor_in_existing_packages(u"Awesome4 Co",
                                                       [bronze_package])
        sponsor5 = create_sponsor_in_existing_packages(u"Awesome5 Co",
                                                       [silver_package])
        sponsor6 = create_sponsor_in_existing_packages(u"Awesome6 Co",
                                                       [gold_package])
        # Sponsors in the menu should be sorted by package
        menu = get_cached_menus()
        self.assertEqual(menu.items, [
            Menu.mk_menu(
                u"sponsors",
                u"Sponsors",
                items=[
                    Menu.mk_item(u"» Awesome1 Co *",
                                 sponsor1.get_absolute_url()),
                    Menu.mk_item(u"» Awesome6 Co *",
                                 sponsor6.get_absolute_url()),
                    Menu.mk_item(u"» Awesome3 Co +",
                                 sponsor3.get_absolute_url()),
                    Menu.mk_item(u"» Awesome5 Co +",
                                 sponsor5.get_absolute_url()),
                    Menu.mk_item(u"» Awesome2 Co -",
                                 sponsor2.get_absolute_url()),
                    Menu.mk_item(u"» Awesome4 Co -",
                                 sponsor4.get_absolute_url()),
                    Menu.mk_item(u"Our sponsors", reverse('wafer_sponsors')),
                    Menu.mk_item(u"Sponsorship packages",
                                 reverse('wafer_sponsorship_packages')),
                ])
        ])

        # Test that changing the order field changes the ordering within the package
        sponsor1.order = 2
        sponsor3.order = 2
        # Ensure menus are regenerated
        sponsor1.save()
        sponsor3.save()

        menu = get_cached_menus()
        self.assertEqual(menu.items, [
            Menu.mk_menu(
                u"sponsors",
                u"Sponsors",
                items=[
                    Menu.mk_item(u"» Awesome6 Co *",
                                 sponsor6.get_absolute_url()),
                    Menu.mk_item(u"» Awesome1 Co *",
                                 sponsor1.get_absolute_url()),
                    Menu.mk_item(u"» Awesome5 Co +",
                                 sponsor5.get_absolute_url()),
                    Menu.mk_item(u"» Awesome3 Co +",
                                 sponsor3.get_absolute_url()),
                    Menu.mk_item(u"» Awesome2 Co -",
                                 sponsor2.get_absolute_url()),
                    Menu.mk_item(u"» Awesome4 Co -",
                                 sponsor4.get_absolute_url()),
                    Menu.mk_item(u"Our sponsors", reverse('wafer_sponsors')),
                    Menu.mk_item(u"Sponsorship packages",
                                 reverse('wafer_sponsorship_packages')),
                ])
        ])
Exemplo n.º 16
0
 def test_add_menu(self):
     menu = Menu([])
     menu.add_menu("my-menu", u"My Menu", [])
     self.assertEqual(menu.items, [Menu.mk_menu("my-menu", u"My Menu", [])])
Exemplo n.º 17
0
 def test_add_menu(self):
     menu = Menu([])
     menu.add_menu("my-menu", u"My Menu", [])
     self.assertEqual(menu.items, [
         Menu.mk_menu("my-menu", u"My Menu", [])
     ])
Exemplo n.º 18
0
 def test_mk_menu_defaults(self):
     self.assertEqual(Menu.mk_menu("my-menu", u"My Menu", []), {
         "menu": "my-menu", "label": u"My Menu",
         "items": [], "sort_key": None,
     })
Exemplo n.º 19
0
 def test_mk_menu_overrides(self):
     self.assertEqual(Menu.mk_menu("my-menu", u"My Menu", [], sort_key=1), {
         "menu": "my-menu", "label": u"My Menu",
         "items": [], "sort_key": 1,
     })