def check_toggle_tab_visiblity(self, tab_type, new_is_hidden_setting):
        """Helper method to check changes in tab visibility"""

        # find the tab
        old_tab = CourseTabList.get_tab_by_type(self.course.tabs, tab_type)

        # visibility should be different from new setting
        self.assertNotEqual(old_tab.is_hidden, new_is_hidden_setting)

        # post the request
        resp = self.client.ajax_post(
            self.url,
            data=json.dumps({
                'tab_id_locator': {
                    'tab_id': old_tab.tab_id
                },
                'is_hidden': new_is_hidden_setting,
            }),
        )
        self.assertEqual(resp.status_code, 204)

        # reload the course and verify the new visibility setting
        self.reload_course()
        new_tab = CourseTabList.get_tab_by_type(self.course.tabs, tab_type)
        self.assertEqual(new_tab.is_hidden, new_is_hidden_setting)
Example #2
0
    def check_toggle_tab_visibility(self, tab_type, new_is_hidden_setting):
        """
        Helper method to check changes in tab visibility.
        """
        old_tab = CourseTabList.get_tab_by_type(self.course.tabs, tab_type)
        # visibility should be different from new setting
        assert old_tab.is_hidden != new_is_hidden_setting

        resp = self.make_update_tab_request({"tab_id": old_tab.tab_id}, {"is_hidden": new_is_hidden_setting})
        assert resp.status_code == 204, resp.content
        # reload the course and verify the new visibility setting
        self.reload_course()
        new_tab = CourseTabList.get_tab_by_type(self.course.tabs, tab_type)
        assert new_tab.is_hidden == new_is_hidden_setting
Example #3
0
    def check_toggle_tab_visiblity(self, tab_type, new_is_hidden_setting):
        """Helper method to check changes in tab visibility"""

        # find the tab
        old_tab = CourseTabList.get_tab_by_type(self.course.tabs, tab_type)

        # visibility should be different from new setting
        self.assertNotEqual(old_tab.is_hidden, new_is_hidden_setting)

        # post the request
        resp = self.client.ajax_post(
            self.url,
            data=json.dumps({"tab_id_locator": {"tab_id": old_tab.tab_id}, "is_hidden": new_is_hidden_setting}),
        )
        self.assertEqual(resp.status_code, 204)

        # reload the course and verify the new visibility setting
        self.reload_course()
        new_tab = CourseTabList.get_tab_by_type(self.course.tabs, tab_type)
        self.assertEqual(new_tab.is_hidden, new_is_hidden_setting)
Example #4
0
def get_course_tab_by_type(request, course, tab_type):
    """
    Look for a tab with the specified type.   Returns the first matching tab.

    Note: This looks in the dynamic and non-dynamic tabs.
    """
    tab = CourseTabList.get_tab_by_type(course.tabs, tab_type)
    if tab is None:
        tab = next((tab for tab in _get_dynamic_tabs(course, request.user)
                    if tab.type == tab_type), None)
    return tab
Example #5
0
    def test_toggle_tab_visibility_fail(self):
        """
        Test that it isn't possible to toggle visibility of unsupported tabs
        """

        tab_type = "courseware"

        tab = CourseTabList.get_tab_by_type(self.course.tabs, tab_type)

        assert not tab.is_hideable
        assert not tab.is_hidden

        resp = self.make_update_tab_request({"tab_id": tab.tab_id}, {"is_hidden": True})

        assert resp.status_code == 400
        error = self.check_invalid_response(resp)
        assert error["error"] == f"Tab of type {tab_type} can not be hidden"

        # Make sure the visibility wasn't affected
        self.reload_course()
        updated_tab = CourseTabList.get_tab_by_type(self.course.tabs, tab_type)
        assert not updated_tab.is_hidden