Ejemplo n.º 1
0
    def setup_user_and_dates(self):
        user = User(username=os.getenv('TEACHER_USER'),
                    password=os.getenv('TEACHER_PASSWORD'),
                    existing_driver=self.driver)
        user.login()
        user.select_course(appearance='biology')

        today = datetime.date.today()
        open_on = (today + datetime.timedelta(days=3)).strftime('%m/%d/%Y')
        due_at = (today + datetime.timedelta(days=6)).strftime('%m/%d/%Y')
        return (user, open_on, due_at)
Ejemplo n.º 2
0
class TestStaxingUser(unittest.TestCase):
    """Staxing case tests for User."""

    def setUp(self):
        """Pretest settings."""
        self.user = User('', '', '')
        self.user.set_window_size(height=700, width=1200)
        self.server = ''.join(('https://', os.getenv('SERVER_URL')))
        self.login = os.getenv('STUDENT_USER_MULTI')
        self.password = os.getenv('STUDENT_PASSWORD')

    def tearDown(self):
        """Test destructor."""
        try:
            self.user.driver.quit()
        except:
            pass

    @pytest.mark.skipif(str(201) not in TESTS, reason='Excluded')
    def test_user_tutor_login(self):
        """Log into Tutor."""
        self.user.login(self.server, self.login, self.password)
        was_successful = 'dashboard' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url
        assert(was_successful), 'Failed to log into %s' % self.server

    @pytest.mark.skipif(str(202) not in TESTS, reason='Excluded')
    def test_user_tutor_logout(self):
        """Log out of Tutor"""
        self.user.login(self.server, self.login, self.password)
        self.user.logout()
        was_successful = \
            'http://cc.openstax.org/' in self.user.driver.current_url or \
            'https://tutor-qa.openstax.org/?' in self.user.driver.current_url
        assert(was_successful), 'Failed to log out of %s' % self.server

    @pytest.mark.skipif(str(203) not in TESTS, reason='Excluded')
    def test_user_accounts_login(self):
        """Log into Accounts."""
        accounts = self.server.replace('tutor', 'accounts')
        self.user.login(accounts, self.login, self.password)
        assert('profile' in self.user.driver.current_url), \
            'Failed to log into %s' % accounts

    @pytest.mark.skipif(str(204) not in TESTS, reason='Excluded')
    def test_user_accounts_logout(self):
        """Log out of Accounts."""
        accounts = self.server.replace('tutor', 'accounts')
        self.user.login(accounts, self.login, self.password)
        self.user.logout()
        assert('signin' in self.user.driver.current_url), \
            'Failed to log out of %s' % accounts

    @pytest.mark.skipif(str(205) not in TESTS, reason='Excluded')
    def test_user_select_course_by_title(self):
        """Select a course by its title."""
        self.user.login(self.server, self.login, self.password)
        print(self.user.current_url())
        courses = self.user.driver.find_elements(
            By.CLASS_NAME,
            'tutor-course-item'
        )
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        title = courses[course_number].text
        Assignment.scroll_to(self.user.driver, courses[course_number])
        self.user.select_course(title=title)
        was_successful = 'courses' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url or \
            'contents' in self.user.driver.current_url
        assert(was_successful), \
            'Failed to select course in URL: %s' % self.user.driver.current_url
        if 'contents' in self.user.driver.current_url:
            return
        course_name = self.user.driver.find_element(
            By.CLASS_NAME,
            'course-name'
        ).text
        assert(title == course_name), 'Failed to select course "%s"' % title

    @pytest.mark.skipif(str(206) not in TESTS, reason='Excluded')
    def test_user_select_course_by_appearance(self):
        """Select a course by its appearance."""
        self.user.login(self.server, self.login, self.password)
        courses = self.user.driver.find_elements(
            By.CLASS_NAME,
            'tutor-booksplash-course-item'
        )
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        appearance = courses[course_number].get_attribute('data-appearance')
        appearance_courses = self.user.driver.find_elements(
                By.XPATH,
                '//div[contains(@data-appearance,"%s")]' % appearance
            )
        title = ''
        if isinstance(appearance_courses, list):
            for course in appearance_courses:
                title = title.join((' ', course.text))
        else:
            title = courses[course_number].text
        Assignment.scroll_to(self.user.driver, courses[course_number])
        self.user.select_course(appearance=appearance)
        was_successful = 'courses' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url or \
            'contents' in self.user.driver.current_url
        assert(was_successful), \
            'Failed to select course in URL: %s' % self.user.driver.current_url
        if 'contents' in self.user.driver.current_url:
            return
        course_name = self.user.driver.find_element(
            By.CLASS_NAME,
            'course-name'
        ).text
        assert(course_name in title), \
            'Failed to select course "%s"' % course_name

    @pytest.mark.skipif(str(207) not in TESTS, reason='Excluded')
    def test_user_go_to_course_list(self):
        """No test placeholder."""
        self.user.login(self.server, self.login, self.password)
        courses = self.user.driver.find_elements(
            By.CLASS_NAME,
            'tutor-course-item'
        )
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        Assignment.scroll_to(self.user.driver, courses[course_number])
        self.user.select_course(title=courses[course_number].text)
        was_successful = 'courses' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url
        assert(was_successful), 'Failed to select course'
        self.user.goto_course_list()
        course_picker = self.server + '/dashboard/'
        assert(self.user.driver.current_url == course_picker), \
            'Failed to return to the course picker'

    @pytest.mark.skipif(str(208) not in TESTS, reason='Excluded')
    def test_user_open_the_reference_book(self):
        """No test placeholder."""
        self.user.login(self.server, self.login, self.password)
        main_window = self.user.driver.current_window_handle
        courses = self.user.driver.find_elements(
            By.CLASS_NAME,
            'tutor-course-item'
        )
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        Assignment.scroll_to(self.user.driver, courses[course_number])
        self.user.select_course(title=courses[course_number].text)
        was_successful = 'courses' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url
        assert(was_successful), 'Failed to select course'
        self.user.view_reference_book()
        self.user.driver.switch_to_window(self.user.driver.window_handles[1])
        WebDriverWait(self.user.driver, 60).until(
            expect.presence_of_element_located(
                (By.CLASS_NAME, 'center-panel')
            )
        )
        assert('contents' in self.user.driver.current_url or
               'books' in self.user.driver.current_url), \
            'Failed to open the reference or WebView book.'
        self.user.driver.close()
        self.user.driver.switch_to_window(main_window)
        was_successful = 'courses' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url
        assert(was_successful), 'Failed to return to the primary browser tab'
Ejemplo n.º 3
0
class TestStaxingUser(unittest.TestCase):
    """Staxing case tests for User."""
    def setUp(self):
        """Pretest settings."""
        self.user = User('', '', '', driver_type=DRIVER)
        print(self.user.driver.get_window_size())
        self.user.set_window_size(height=700, width=1200)
        print(self.user.driver.get_window_size())
        self.server = ''.join(('https://', os.getenv('SERVER_URL')))
        self.login = os.getenv('TEACHER_USER_MULTI')
        self.password = os.getenv('TEACHER_PASSWORD')

    def tearDown(self):
        """Test destructor."""
        try:
            self.user.delete()
        except Exception:
            pass

    @pytest.mark.skipif(str(201) not in TESTS, reason='Excluded')
    def test_user_tutor_login_201(self):
        """Log into Tutor."""
        self.user.login(self.server, self.login, self.password)
        was_successful = 'course' in self.user.current_url() or \
                         'dashboard' in self.user.current_url() or \
                         'calendar' in self.user.current_url()
        assert (was_successful), 'Failed to log into %s' % self.server

    @pytest.mark.skipif(str(202) not in TESTS, reason='Excluded')
    def test_user_tutor_logout_202(self):
        """Log out of Tutor"""
        self.user.login(self.server, self.login, self.password)
        self.user.logout()
        was_successful = 'tutor' in self.user.current_url() and \
                         '.openstax.org' in self.user.current_url()
        assert (was_successful), 'Failed to log out of %s' % self.server

    @pytest.mark.skipif(str(203) not in TESTS, reason='Excluded')
    def test_user_accounts_login_203(self):
        """Log into Accounts."""
        accounts = self.server.replace('tutor', 'accounts')
        self.user.login(accounts, self.login, self.password)
        assert('profile' in self.user.current_url()), \
            'Failed to log into %s' % accounts

    @pytest.mark.skipif(str(204) not in TESTS, reason='Excluded')
    def test_user_accounts_logout_204(self):
        """Log out of Accounts."""
        accounts = self.server.replace('tutor', 'accounts')
        self.user.login(accounts, self.login, self.password)
        self.user.logout()
        assert('login' in self.user.current_url()), \
            'Failed to log out of %s' % accounts

    @pytest.mark.skipif(str(205) not in TESTS, reason='Excluded')
    def test_user_select_course_by_title_205(self):
        """Select a course by its title."""
        self.user.login(self.server, self.login, self.password)
        print(self.user.current_url())
        courses = self.user.get_course_list()
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        title = courses[course_number].get_attribute('data-title')
        self.user.scroll_to(courses[course_number])
        self.user.select_course(title=title)
        position = self.user.current_url()
        was_successful = 'course' in position or \
                         'list' in position or \
                         'calendar' in position or \
                         'contents' in position
        assert(was_successful), \
            'Failed to select course in URL: %s' % position
        if 'contents' in position:
            return
        course_name = self.user.find(By.CLASS_NAME, 'title').text
        assert (title == course_name), 'Failed to select course "%s"' % title

    @pytest.mark.skipif(str(206) not in TESTS, reason='Excluded')
    def test_user_select_course_by_appearance_206(self):
        """Select a course by its appearance."""
        self.user.login(self.server, self.login, self.password)
        courses = self.user.get_course_list()
        course_number = 0 if len(courses) == 1 \
            else randint(1, len(courses)) - 1
        assert (course_number >= 0), 'No courses found.'

        appearance = courses[course_number].get_attribute('data-appearance')
        appearance_courses = self.user.find_all(
            By.XPATH, '//div[contains(@data-appearance,"%s")]' % appearance)
        title = ''
        if isinstance(appearance_courses, list):
            for course in appearance_courses:
                title = title.join((' ', course.text))
        else:
            title = courses[course_number].text
        self.user.scroll_to(courses[course_number])
        self.user.select_course(appearance=appearance)
        position = self.user.current_url()
        was_successful = 'course' in position or \
                         'list' in position or \
                         'calendar' in position or \
                         'contents' in position
        assert(was_successful), \
            'Failed to select course in URL: %s' % position
        if 'contents' in position:
            return

        course_name = self.user.find(By.CLASS_NAME, 'title').text
        assert(course_name in title.replace('\n', ' ')), \
            'Failed to select course "%s"' % course_name

    @pytest.mark.skipif(str(207) not in TESTS, reason='Excluded')
    def test_user_go_to_course_list_207(self):
        """Go to the course list."""
        self.user.login(self.server, self.login, self.password)
        courses = self.user.get_course_list()
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        self.user.scroll_to(courses[course_number])
        self.user.select_course(
            title=courses[course_number].get_attribute('data-title'))
        url = self.user.current_url()
        was_successful = 'course' in url or \
            'list' in url or \
            'calendar' in url
        print('%s in %s == %s' %
              ('(course,list,calendar)', url, was_successful))
        assert (was_successful), 'Failed to select course'
        self.user.goto_course_list()
        course_picker = self.server + '/dashboard'
        url = self.user.current_url()
        print('%s ?= %s' % (url, course_picker))
        assert(url == course_picker), \
            'Failed to return to the course picker'

    @pytest.mark.skipif(str(208) not in TESTS, reason='Excluded')
    def test_user_open_the_reference_book_208(self):
        """Open the reference view of the textbook."""
        self.user.login(self.server, self.login, self.password)
        main_window = self.user.driver.current_window_handle
        courses = self.user.get_course_list()
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        Assignment.scroll_to(self.user.driver, courses[course_number])
        self.user.select_course(
            title=courses[course_number].get_attribute('data-title'))
        url = self.user.current_url()
        was_successful = 'course' in url or \
            'list' in url or \
            'calendar' in url
        print('%s in %s == %s' %
              ('(course,list,calendar)', url, was_successful))
        assert (was_successful), 'Failed to select course'
        self.user.view_reference_book()
        self.user.sleep(1)
        self.user.driver.switch_to_window(self.user.driver.window_handles[1])
        WebDriverWait(self.user.driver, 60).until(
            expect.presence_of_element_located(
                (By.CLASS_NAME, 'center-panel')))
        assert('contents' in self.user.current_url() or
               'books' in self.user.current_url()), \
            'Failed to open the reference or WebView book.'
        self.user.driver.close()
        self.user.driver.switch_to_window(main_window)
        was_successful = 'course' in self.user.current_url() or \
            'list' in self.user.current_url() or \
            'calendar' in self.user.current_url()
        assert (was_successful), 'Failed to return to the primary browser tab'