예제 #1
0
 def get_render_ready_menu_instance(self, parent_context=None):
     menu = MainMenu.objects.get(pk=1)
     ctx_vals = utils.make_contextualvals_instance(
         parent_context=parent_context)
     opt_vals = utils.make_optionvals_instance()
     menu.prepare_to_render(ctx_vals.request, ctx_vals, opt_vals)
     return menu
예제 #2
0
    def test_site_specific_templates_not_returned_by_default(self):
        menu = self.get_test_menu_instance()
        site = self.get_test_site_instance()

        menu._contextual_vals = utils.make_contextualvals_instance(
            url='/', current_site=site)
        result = menu.get_template_names()
        self.assertEqual(len(result), self.expected_default_result_length)
        for val in result:
            self.assertFalse(site.hostname in val)
예제 #3
0
    def test_site_specific_templates_returned_if_setting_is_true_and_current_site_is_in_contextual_vals(
            self):
        menu = self.get_test_menu_instance()
        site = self.get_test_site_instance()

        menu._contextual_vals = utils.make_contextualvals_instance(
            url='/', current_site=site)
        result = menu.get_template_names()
        self.assertGreater(len(result), self.expected_default_result_length)
        for val in result[:2]:
            self.assertTrue(site.hostname in val)
예제 #4
0
    def test_specific_templates_not_returned_if_current_site_not_in_contextual_vals(
            self):
        menu = self.get_test_menu_instance()
        site = self.get_test_site_instance()

        menu._contextual_vals = utils.make_contextualvals_instance(
            current_site=None)
        result = menu.get_sub_menu_template_names()
        self.assertEqual(len(result), self.expected_default_result_length)
        for val in result:
            self.assertTrue(site.hostname not in val)
예제 #5
0
    def test_warns_when_custom_menuitem_relative_url_does_not_accept_request(
            self):
        menu = self.get_test_menu_instance()
        menu._option_vals = utils.make_optionvals_instance()
        menu._contextual_vals = utils.make_contextualvals_instance(url='/test')
        menu.request = menu._contextual_vals.request

        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            menu.get_menu_items_for_rendering()
        self.assertEqual(
            str(w[0].message),
            "The relative_url() method on custom MenuItem classes must accept "
            "a 'request' keyword argument. Please update the method signature "
            "on your MainMenuItem class. It will be mandatory in Wagtail 2.13."
        )