base_studio_test.py 4.7 KB
Newer Older
1 2 3 4
"""
Base classes used by studio tests.
"""
from bok_choy.web_app_test import WebAppTest
5 6
from ...pages.studio.auto_auth import AutoAuthPage
from ...fixtures.course import CourseFixture
7
from ...fixtures.library import LibraryFixture
8 9 10
from ..helpers import UniqueCourseTest
from ...pages.studio.overview import CourseOutlinePage
from ...pages.studio.utils import verify_ordering
11

12

13 14 15 16 17
class StudioCourseTest(UniqueCourseTest):
    """
    Base class for all Studio course tests.
    """

18
    def setUp(self, is_staff=False):
19 20 21 22 23 24 25 26 27 28 29 30 31
        """
        Install a course with no content using a fixture.
        """
        super(StudioCourseTest, self).setUp()
        self.course_fixture = CourseFixture(
            self.course_info['org'],
            self.course_info['number'],
            self.course_info['run'],
            self.course_info['display_name']
        )
        self.populate_course_fixture(self.course_fixture)
        self.course_fixture.install()
        self.user = self.course_fixture.user
32
        self.log_in(self.user, is_staff)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

    def populate_course_fixture(self, course_fixture):
        """
        Populate the children of the test course fixture.
        """
        pass

    def log_in(self, user, is_staff=False):
        """
        Log in as the user that created the course. The user will be given instructor access
        to the course and enrolled in it. By default the user will not have staff access unless
        is_staff is passed as True.
        """
        self.auth_page = AutoAuthPage(
            self.browser,
            staff=is_staff,
            username=user.get('username'),
            email=user.get('email'),
            password=user.get('password')
        )
        self.auth_page.visit()
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100


class ContainerBase(StudioCourseTest):
    """
    Base class for tests that do operations on the container page.
    """

    def setUp(self):
        """
        Create a unique identifier for the course used in this test.
        """
        # Ensure that the superclass sets up
        super(ContainerBase, self).setUp()

        self.outline = CourseOutlinePage(
            self.browser,
            self.course_info['org'],
            self.course_info['number'],
            self.course_info['run']
        )

    def go_to_nested_container_page(self):
        """
        Go to the nested container page.
        """
        unit = self.go_to_unit_page()
        # The 0th entry is the unit page itself.
        container = unit.xblocks[1].go_to_container()
        return container

    def go_to_unit_page(self, section_name='Test Section', subsection_name='Test Subsection', unit_name='Test Unit'):
        """
        Go to the test unit page.

        If make_draft is true, the unit page will be put into draft mode.
        """
        self.outline.visit()
        subsection = self.outline.section(section_name).subsection(subsection_name)
        return subsection.toggle_expand().unit(unit_name).go_to()

    def do_action_and_verify(self, action, expected_ordering):
        """
        Perform the supplied action and then verify the resulting ordering.
        """
        container = self.go_to_nested_container_page()
        action(container)

101
        verify_ordering(self, container, expected_ordering)
102 103 104

        # Reload the page to see that the change was persisted.
        container = self.go_to_nested_container_page()
105
        verify_ordering(self, container, expected_ordering)
106 107 108 109 110 111


class StudioLibraryTest(WebAppTest):
    """
    Base class for all Studio library tests.
    """
112
    as_staff = True
113

114
    def setUp(self):  # pylint: disable=arguments-differ
115 116 117 118 119 120 121 122 123 124 125
        """
        Install a library with no content using a fixture.
        """
        super(StudioLibraryTest, self).setUp()
        fixture = LibraryFixture(
            'test_org',
            self.unique_id,
            'Test Library {}'.format(self.unique_id),
        )
        self.populate_library_fixture(fixture)
        fixture.install()
126
        self.library_fixture = fixture
127 128 129
        self.library_info = fixture.library_info
        self.library_key = fixture.library_key
        self.user = fixture.user
130
        self.log_in(self.user, self.as_staff)
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

    def populate_library_fixture(self, library_fixture):
        """
        Populate the children of the test course fixture.
        """
        pass

    def log_in(self, user, is_staff=False):
        """
        Log in as the user that created the library.
        By default the user will not have staff access unless is_staff is passed as True.
        """
        auth_page = AutoAuthPage(
            self.browser,
            staff=is_staff,
            username=user.get('username'),
            email=user.get('email'),
            password=user.get('password')
        )
        auth_page.visit()