class EmailerPermissionTests(EmailerBaseTestCase):
    @data(*get_xl_data(CANVAS_ADD_USERS))
    @unpack
    def test_roles_access(self, user_id, given_access):
        # This test masquerades as users in roles specified defined in
        # CANVAS_ADD_USERS (Excel spreadsheet) then validates if the users
        # are granted/denied access based on their role.

        self.masquerade_page.masquerade_as(user_id)
        self.emailer_main_page.get(self.TOOL_URL)

        if given_access == 'no':
            self.assertFalse(
                self.emailer_main_page.is_authorized(),
                'User {} has been authorized, '
                'but should not be.'.format(user_id))

        elif given_access == 'yes':
            self.assertTrue(
                self.emailer_main_page.is_authorized(),
                'User {} not authorized, but should be.'.format(user_id))

        else:
            raise ValueError(
                'given_access column for user {} must be either \'yes\' or '
                '\'no\''.format(user_id))
class ImportiSitesPermissionTests(CourseAdminBaseTestCase):
    @data(*get_xl_data(IMPORT_ISITES_PERMISSION_ROLES))
    @unpack
    def test_roles_access(self, user_id, given_access, expected_role):
        # This test masquerades as users in roles in the spreadsheet
        # specified in IMPORT_ISITES_PERMISSION_ROLES, and then validates the
        # the users are granted/denied access based on their role.

        #  Masquerade as test user
        self.masquerade_page.masquerade_as(user_id)

        # Go back to the Manage Course Dashboard
        self.driver.get(self.TOOL_URL)

        if given_access == 'yes':
            # Verifying that the user can see the import isites card on the
            # manage_course dashboard
            self.assertTrue(
                self.course_admin_dashboard_page.
                import_isites_content_is_displayed(),
                'User {} with expected role {} should see the import '
                'isites content tool on page but does not'.format(
                    user_id, expected_role))

        elif given_access == 'no':
            self.assertFalse(
                self.course_admin_dashboard_page.
                import_isites_content_is_displayed(),
                'User {} with expected role {} should not see the import '
                'isites tool, but can see it.'.format(user_id, expected_role))

        else:
            raise ValueError(
                'given_access column for user {} must be either "yes" or '
                '"no"'.format(user_id, expected_role))
class RemovePeopleTests(ManagePeopleBaseTestCase):
    @screenshot_on_test_exception
    @data(*get_xl_data(MP_TEST_USERS_WITH_ROLES))
    @unpack
    def test_remove_users(self, test_case_id, test_user_id, test_univ_id, role,
                          role_id, canvas_role, success_msg_ind,
                          remove_list_ind, error_msg_ind, add_remove_ind):

        if add_remove_ind != 'remove':
            return

        test_univ_id = self.normalize_xlrd_number(test_univ_id, '{0:08d}')
        role_id = self.normalize_xlrd_number(role_id)

        self.start_message(test_user_id, test_univ_id, role, role_id)

        # Note: ICOMMONS_REST_API_HOST environment needs to match the LTI tool
        # environment (because of shared cache interactions)

        # ensure person is in course before attempting to remove using API
        # 1. remove ALL roles/enrollments for the test user in this course
        #    to ensure no incidental data causes conflict when we try to add
        # 2. add via API the role we want to test removing through the UI
        self.api.remove_user(self.test_settings['test_course']['cid'],
                             test_univ_id)
        self.api.add_user(self.test_settings['test_course']['cid'],
                          test_univ_id, role_id)

        user_list_page = UserListPageObject(self.driver)

        # Note: the refresh has been added due to issues with remove.  If
        # user is added via the api but the page isn't reload, the tests will
        # sporadically fail out with NoSuchElementException.
        self.driver.refresh()
        self.setUp()

        # Delete the user in Canvas
        user_list_page.delete_user(test_univ_id, role_id)

        self.assertTrue(user_list_page.is_loaded())
        # Note: the refresh has been added due to issues with remove. If the
        # user has been deleted via the UI, but the page isn't reloaded,
        # it would sporadically fail out with an assertion error.  We have
        # yet to find a more graceful solution.
        self.driver.refresh()
        self.setUp()

        # Assert that the deleted user does not appear in Manage People
        self.assertFalse(
            user_list_page.user_present_with_role(test_univ_id, role_id))

    @classmethod
    def start_message(cls, test_user_id, test_univ_id, role, role_id):
        row_log = "Attempting to remove user for search term {}, " \
                  "univ_id {}, role {} (in dropdown list), role_id {}..."
        print(row_log.format(test_user_id, test_univ_id, role, role_id))
class ManageSectionsPermissionTests(ManageSectionsBaseTestCase):
    @data(*get_xl_data(MANAGE_SECTION_PERMISSIONS))
    @unpack
    def test_roles_access(self, user_id, given_access, expected_role):
        # This test masquerades as users in the spreadsheet
        # specified in MANAGE_SECTION_PERMISSIONS, and then validates that
        # the users are granted/denied access based on their role.
        # Their role in our test instance of Canvas is expected to match
        # what's in the expected_role column of the test spreadsheet.

        #  Instantiate
        main_page = MainPageObject(self.driver)

        #  Masquerade as test user
        self.masquerade_page.masquerade_as(user_id)

        # Go back to the Manage Course Dashboard
        self.driver.get(self.TOOL_URL)

        if given_access == 'yes':
            # test user should be able to access the dashboard, so we can test
            #  if the manage sections app is visible
            self.assertTrue(self.course_admin_dashboard_page.is_loaded())

            # If user should have access to Manage Sections tool, verify that
            # the user sees the manage sections button
            self.assertTrue(
                self.course_admin_dashboard_page.
                manage_sections_button_is_displayed(),
                'User {} with expected role {} should see the manage_sections '
                'button on page but does not.'.format(user_id, expected_role))

            # Clicks into tool
            self.course_admin_dashboard_page.select_manage_sections_link()

            # Verifies that user can click into and see the manage sections tool
            self.assertTrue(main_page.is_loaded())

        elif given_access == 'no':
            if self.course_admin_dashboard_page.is_loaded():
                self.assertFalse(
                    self.course_admin_dashboard_page.
                    manage_sections_button_is_displayed(),
                    'User {} with expected role {} should not see the '
                    'manage_sections button, but can see it.'.format(
                        user_id, expected_role))
            else:
                # user does not have access to Manage Course dashboard, so we
                # can assume this test passed
                pass

        else:
            raise ValueError(
                'given_access column for user {} with expected role {} must be '
                'either "yes" or "no".'.format(user_id, expected_role))
Exemplo n.º 5
0
class RemoveCrossListingTests(CrossListingBaseTestCase):

    @data(*get_xl_data(TEST_DATA_CROSS_LISTING_MAPPINGS))
    @unpack
    def test_remove_and_search_successful(self, _unused_test_case_id,
                                          primary_cid,
                                          secondary_cid,
                                          expected_result,
                                          _unused_expected_alert_text):

        """
        Jira requirement stories: TLT-1979 (remove), TLT-2670 (search
        Selenium sub-task: TLT-2595.
        These tests cover AC #1 and #2.

        The test is performing these steps:
        1.  Remove  existing cross-list mappings via rest api first to
        avoid incidental conflict when we try to add a new mapping.
        2.  Add cross-listing via rest api of the pairing that we
        want to test the 'remove' functionality on.
        3.  Find this new cross-listing using the search box
        4.  Test remove by clicking on the cross-list remove icon via UI

        """
        # Remove tests only apply those those cases where there is an expected
        # successful add.
        if expected_result == 'success':
            # Remove xlisted pairing - if it exists - via rest api first
            # for a clean test.
            self.api.remove_xlisted_course(primary_cid, secondary_cid)

            # Add the xlisted pair via rest api
            self.api.add_xlisted_course(primary_cid, secondary_cid)

            # Get the xlist_map_id to locate the right delete icon
            xlist_map_id = self.api.lookup_xlist_map_id(primary_cid,
                                                        secondary_cid)

            # Search for the new cross-listing so it is on the first page of
            # results and therefore clickable
            self.main_page.search('{} {}'.format(primary_cid, secondary_cid))

            # Clicks on the delete icon associated with the xlist_map_id.
            # Known limitation: this works only if the cross-listing pairing is
            # on the first page of results presently shown.
            self.main_page.delete_cross_listing_pairing(xlist_map_id)

            # Verifies pair has been de-crosslisted by confirmation message
            expected_text = "Successfully de-cross-listed {} and {}.".format(
                                                    primary_cid, secondary_cid)
            actual_text = self.main_page.get_confirmation_text()
            # Checks that the de-cross-list message appears.
            self.assertEqual(actual_text, expected_text)
class RemovePeopleTests(CourseInfoBaseTestCase):
    @data(*get_xl_data(TEST_USERS_WITH_ROLES_PATH))
    @unpack
    def test_remove_person(self, test_case_id, test_user, canvas_role,
                           role_id):
        """ Removes a user from course using the Admin Console """

        test_course_key = 'test_course'
        course_instance_id = self.test_settings[test_course_key]['cid']

        # Note: ICOMMONS_REST_API_HOST environment needs to match the LTI tool
        # environment (because of shared cache interactions)

        # ensure person is in course using API before attempting to remove in UI
        # 1. remove ALL roles/enrollments for the test user in this course
        #    to ensure no incidental data causes conflict when we try to add
        # 2. add via API the role we want to test removing through the UI
        self.api.remove_user(course_instance_id, test_user)
        self.api.add_user(course_instance_id, test_user, role_id)

        self._load_test_course(test_course_key)

        self.detail_page.go_to_people_page()

        # asserts test user is on people page and to-be-removed user is on page
        # Note: If the course has a lot of people enrolled, results are
        # paginated and it's possible that user may not be on the initial
        # page.

        self.assertTrue(self.people_page.is_person_on_page(test_user))

        # asserts that the delete confirmation text is not already on the page
        self.assertFalse(self.people_page.delete_was_successful())

        # deletes user and confirms that delete is successful
        self.people_page.delete_user(test_user)

        self.assertTrue(self.people_page.delete_was_successful())
        '''Note: Page needs to reloaded as tests are persistently failing
        for element not found - perhaps cache has changed" for different test
        id (as the test ID are being removed so DOM has changed). This ensures
        that the page is reloaded.'''
        self.driver.refresh()
        self.setUp()
        self._load_test_course()

        # Verifies that user has been removed from course.
        self.assertTrue(
            self.people_page.is_person_removed_from_list(test_user))
Exemplo n.º 7
0
class AddCrossListingTests(CrossListingBaseTestCase):

    @data(*get_xl_data(TEST_DATA_CROSS_LISTING_MAPPINGS))
    @unpack
    def test_add_cross_listing_pairing(self, _unused_test_case_id,
                                       primary_cid,
                                       secondary_cid,
                                       expected_result,
                                       expected_alert_text):
        """
        Jira requirement story: TLT-1314
        Selenium sub-task: TLT-2589.
        These tests cover AC #1 and #7.

        This test adds a valid cross-list pairing to the cross-listing table
        """

        if expected_result not in ['success', 'fail']:
            raise ValueError(
                'given_access column for user {} must be either \'success\' '
                'or \'fail\''.format(expected_result))

        # Removes cross-listed courses if it exists before testing add
        try:
            self.api.remove_xlisted_course(primary_cid, secondary_cid)
        except RuntimeError as e:
            if 'CanvasAPIError' in e.message and \
                    'section is not cross-listed' in e.message:
                # this is a known possibility with test cases that
                # result in a partial success (e.g. the Canvas side failed)
                pass
            else:
                raise e

        # This adds a pairing to cross-list table, clicks submit,
        # and confirm an alert box appears.
        self.assertTrue(self.main_page.add_cross_listing_pairing(primary_cid,
                                                                 secondary_cid))
        #  Verifies expected alert text
        #  (e.g. confirmation if successful, error message if unsuccessful)
        self.assertTrue(
            self.main_page.confirmation_contains_text(expected_alert_text))

        # Verify a successful cross-list add
        if expected_result == 'success':
            # Clean up and remove the cross-listed course when test is done
            self.api.remove_xlisted_course(primary_cid, secondary_cid)
class ClassRosterPermissionTests(ClassRosterBaseTestCase):
    @data(*get_xl_data(CLASS_ROSTER_PERMISSION_ROLES))
    @unpack
    def test_roles_access(self, user_id, given_access, expected_role):
        # This test masquerades as users in roles in the spreadsheet
        # specified in CLASS_ROSTER_PERMISSION_ROLES, and then validates the
        # the users are granted/denied access based on their role.

        #  Instantiate
        main_page = MainPageObject(self.driver)

        #  Masquerade as test user
        self.masquerade_page.masquerade_as(user_id)

        # Go back to the Manage Course Dashboard
        self.driver.get(self.TOOL_URL)

        if given_access == 'yes':
            # If user should have access to Class Roster tool, verify
            # that the user sees the class roster button
            self.assertTrue(
                self.course_admin_dashboard_page.
                class_roster_button_is_displayed(),
                'User {} with expected role {} should see the class roster '
                'button on page but does not'.format(user_id, expected_role))

            # Clicks into tool
            self.course_admin_dashboard_page.select_class_roster_link()

            # Verifies that user can click into and see the class roster tool
            self.assertTrue(main_page.is_loaded())

        elif given_access == 'no':
            self.assertFalse(
                self.course_admin_dashboard_page.
                class_roster_button_is_displayed(),
                'User {} with expected role {} should not see the class '
                'roster tool, but can see it.'.format(user_id, expected_role))

        else:
            raise ValueError(
                'given_access column for user {} must be either "yes" or '
                '"no"'.format(user_id, expected_role))
Exemplo n.º 9
0
class AddPeopleTests(CourseInfoBaseTestCase):

    @data(*get_xl_data(TEST_USER_SEARCH_TERMS_PATH))
    @unpack
    def test_add_people(self, test_case_id, search_terms, canvas_role, role_id,
                        successes, failures):
        """ verify the person search and add functionality """

        # Note: ICOMMONS_REST_API_HOST environment needs to match the LTI tool
        # environment (because of shared cache interactions)

        # ensure people are not in course before attempting to add using API;
        # remove ALL roles/enrollments for the test users in this course
        # to ensure no incidental data causes conflict when we try to add

        test_course_key = 'test_course'
        test_cid = self.test_settings[test_course_key]['cid']
        id_list = [s.strip() for s in search_terms.split(',')]

        for user_id in id_list:
            self.api.remove_user(test_cid, user_id)

        self._load_test_course(test_course_key)

        self.detail_page.go_to_people_page()

        # search for a user and add user to course
        self.assertTrue(self.people_page.is_loaded())

        # assert that the results message is not already loaded on the page
        self.assertFalse(self.people_page.people_added(int(successes), int(failures)))

        # add user to role
        self.people_page.search_and_add_users(search_terms, canvas_role)

        # Assert that the results summary text is displayed
        self.assertTrue(self.people_page.people_added(int(successes), int(failures)))

        # clean up (avoid cluttering the course if multiple different
        # test users are used)
        for user_id in id_list:
            self.api.remove_user(test_cid, user_id)
Exemplo n.º 10
0
class MPPermissionTests(CourseAdminBaseTestCase):
    @data(*get_xl_data(MP_PERMISSION_ROLES))
    @unpack
    def test_roles_access(self, user_id, given_access, expected_role):
        # This test masquerades as users in roles in the spreadsheet
        # specified in MP_PERMISSION_ROLES, and then validates the the users
        # are granted/denied access based on their role.

        self.masquerade_page.masquerade_as(user_id)
        # Go back to the Manage Course Dashboard
        self.driver.get(self.TOOL_URL)

        if given_access == 'yes':
            self.assertTrue(
                self.course_admin_dashboard_page.
                manage_people_button_is_displayed(),
                'User {} with expected role {} should see the manage people '
                'button on page but does not.'.format(user_id, expected_role))

            #  Clicks into tool
            self.course_admin_dashboard_page.select_manage_people_link()
            # Verifies that user can see the manage people tool

            manage_people_page = MainPageObject(self.driver)
            # Switch frame and verify main page is loaded
            manage_people_page.focus_on_tool_frame()
            self.assertTrue(manage_people_page.is_loaded())

        elif given_access == 'no':
            self.assertFalse(
                self.course_admin_dashboard_page.
                manage_people_button_is_displayed(), 'User {} with '
                'expected role {} should not see the manage_sections button, '
                'but can see it.'.format(user_id, expected_role))

        else:
            raise ValueError(
                'given_access column for user {} with expected role {} must be '
                'either "yes" or "no".'.format(user_id, expected_role))
class BulkCreatePermissionTests(AccountAdminBaseTestCase):
    @data(*get_xl_data(CANVAS_PERMISSION_ROLES))
    @unpack
    def test_roles_access(self, user_id, given_access):
        """
        This test masquerades as various roles from the test data spreadsheet
        and verifies that user in said role should or should not be granted
        access to the Course Bulk Creator.
        """

        masquerade_page = CanvasMasqueradePageObject(self.driver,
                                                     self.CANVAS_BASE_URL)
        index_page = IndexPageObject(self.driver)

        # Masquerade as a user defined in the Test_Data/Roles Access spreadsheet
        masquerade_page.masquerade_as(user_id)

        # Once masqueraded as user, go back to Account Admin Console
        self.driver.get(self.TOOL_URL)

        if given_access == 'no':
            print "Verifying user %s is denied access to course bulk create " \
                  "tool" % user_id
            self.assertFalse(index_page.is_authorized(),
                             'User {} unexpectedly authorized'.format(user_id))

        elif given_access == 'yes':
            print "Verifying user %s is granted access to course bulk create " \
                  "tool" % user_id

            # Clicks into Canvas Site Create tool
            self.acct_admin_dashboard_page.select_create_canvas_site_link()

            # Verifies that the user can click into the bulk create tool
            self.assertTrue(index_page.is_loaded())

        else:
            raise ValueError('given_access column for user {} must be either '
                             '\'yes\' or \'no\''.format(user_id))
class CourseAdminDashboardPermissionTests(CourseAdminBaseTestCase):
    @data(*get_xl_data(MANAGE_COURSE_PERMISSIONS))
    @unpack
    def test_roles_access(self, user_id, given_access, expected_role):
        """This test masquerades as users in the spreadsheet
        specified in MANAGE_COURSE_PERMISSIONS, and then validates that
        the users are granted/denied access based on their role.
        Their role in our test instance of Canvas is expected to match
        what's in the expected_role column of the test spreadsheet."""

        # initialize
        dashboard = self.course_admin_dashboard_page

        #  Masquerade as test user
        self.masquerade_page.masquerade_as(user_id)

        # Go back to the Manage Course Dashboard
        dashboard.get(self.TOOL_URL)

        if given_access == 'yes':
            # test user should be able to access the dashboard
            self.assertTrue(
                dashboard.is_loaded(),
                'User {} with expected role {} should be able to access the '
                'Manage Course dashboard but cannot.'.format(
                    user_id, expected_role))
        elif given_access == 'no':
            self.assertFalse(
                dashboard.is_loaded(),
                'User {} with expected role {} should not have access to the '
                'Manage Course dashboard, but can access it.'.format(
                    user_id, expected_role))
        else:
            raise ValueError(
                'given_access column for user {} with expected role {} must be '
                'either "yes" or "no".'.format(user_id, expected_role))
Exemplo n.º 13
0
class AddingTests(ManagePeopleBaseTestCase):
    @data(*get_xl_data(MP_TEST_USERS_WITH_ROLES))
    @unpack
    @screenshot_on_test_exception
    def test_adding_users_by_roles(self, test_case_id, test_user_id,
                                   test_univ_id, role, role_id, canvas_role,
                                   success_msg_ind, remove_list_ind,
                                   error_msg_ind, add_remove_indicator):

        if add_remove_indicator != 'add':
            return

        test_univ_id = self.normalize_xlrd_number(test_univ_id, '{0:08d}')
        test_user_id = self.normalize_xlrd_number(test_user_id, '{0:08d}')
        role_id = self.normalize_xlrd_number(role_id)

        self.start_message(test_user_id, test_univ_id, role, role_id)

        # Note: ICOMMONS_REST_API_HOST environment needs to match the LTI tool
        # environment (because of shared cache interactions)

        # ensure person is not in course before attempting to add using API;
        # remove ALL roles/enrollments for the test user in this course
        # to ensure no incidental data causes conflict when we try to add
        self.api.remove_user(self.test_settings['test_course']['cid'],
                             test_univ_id)

        user_list_page = UserListPageObject(self.driver)
        search_page = FindUserPageObject(self.driver)
        results_page = ResultsListPageObject(self.driver)

        # from Main/User list page: click links to add people to course
        user_list_page.add_user()
        # from Search page: find a user and submit form
        search_page.find_user(test_user_id)
        # verify that we are now on the results page from search
        self.assertTrue(
            results_page.is_loaded(),
            "Problem finding user %s: results page not loaded" % test_user_id)

        results_page.add_id_to_course(test_univ_id, role)

        self.assertTrue(
            results_page.user_confirmation_visible(),
            'User %s with role %s could not be added to the '
            'course; another conflicting role may exist for '
            'the user already.' % (test_univ_id, role_id))

        results_page.return_to_manage_people()
        self.assertTrue(
            user_list_page.user_present_with_role(test_univ_id, role_id))

        # ensure person is removed from course as cleanup
        self.api.remove_user(self.test_settings['test_course']['cid'],
                             test_univ_id, role_id)

    @classmethod
    def start_message(cls, test_user_id, test_univ_id, role, role_id):
        row_log = "Attempting to add user for search term {}, " \
                  "univ_id {}, role {} (in dropdown list), role_id {}..."
        print(row_log.format(test_user_id, test_univ_id, role, role_id))