Example #1
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"),
         ])
     ])
Example #2
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')),
         ])
     ])
Example #3
0
 def test_menu_ordering(self):
     schedule = Page.objects.create(name='Schedule',
                                    slug='schedule',
                                    include_in_menu=True,
                                    menu_order=20)
     about = Page.objects.create(name='About',
                                 slug='about',
                                 include_in_menu=True,
                                 menu_order=10)
     menu = Menu([])
     page_menus(menu)
     self.assertEqual(menu.items, [
         Menu.mk_item("About", about.get_absolute_url()),
         Menu.mk_item("Schedule", schedule.get_absolute_url()),
     ])
Example #4
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())])
     ])
Example #5
0
 def test_mk_item_defaults(self):
     self.assertEqual(Menu.mk_item(
         u"My Label", u"http://example.com"
     ), {
         "label": u"My Label", "url": u"http://example.com",
         "sort_key": None, "image": None,
     })
Example #6
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,
     })
Example #7
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,
         })
Example #8
0
 def test_mk_item_overrides(self):
     self.assertEqual(Menu.mk_item(
         u"My Label", u"http://example.com",
         sort_key=1, image="/static/img/twitter.png"
     ), {
         "label": u"My Label", "url": u"http://example.com",
         "sort_key": 1, "image": "/static/img/twitter.png",
     })
Example #9
0
 def test_mk_item_defaults(self):
     self.assertEqual(
         Menu.mk_item(u"My Label", u"http://example.com"), {
             "label": u"My Label",
             "url": u"http://example.com",
             "sort_key": None,
             "image": None,
         })
Example #10
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")])
     ])
Example #11
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", []),
     ])
Example #12
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')),
             ])
     ])
Example #13
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", []),
     ])
Example #14
0
 def test_mk_item_overrides(self):
     self.assertEqual(
         Menu.mk_item(u"My Label",
                      u"http://example.com",
                      sort_key=1,
                      image="/static/img/twitter.png"), {
                          "label": u"My Label",
                          "url": u"http://example.com",
                          "sort_key": 1,
                          "image": "/static/img/twitter.png",
                      })
Example #15
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", []),
     ])
Example #16
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", []),
     ])
Example #17
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')),
             ])
     ])
Example #18
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")
         ])
     ])
Example #19
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", [])
     ])
Example #20
0
 def test_add_item_to_nonexistent_submenu(self):
     menu = Menu([])
     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, [])
Example #21
0
 def test_add_item_to_root(self):
     menu = Menu([])
     menu.add_item(u"My Label", u"http://example.com")
     self.assertEqual(menu.items, [
         Menu.mk_item(u"My Label", u"http://example.com")
     ])
Example #22
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"),
         ])
     ])
Example #23
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,
     })
Example #24
0
 def test_add_item_to_root(self):
     menu = Menu([])
     menu.add_item(u"My Label", u"http://example.com")
     self.assertEqual(menu.items,
                      [Menu.mk_item(u"My Label", u"http://example.com")])
Example #25
0
 def test_add_item_to_nonexistent_submenu(self):
     menu = Menu([])
     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, [])
Example #26
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')),
                ])
        ])
Example #27
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,
     })
Example #28
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", [])])