class TestManageDistricsSchoolsAndCourses(unittest.TestCase): """T1.59 - Manage districts, schools, and courses.""" def setUp(self): """Pretest settings.""" # login as admin, go to user menu, click admin option self.ps = PastaSauce() self.desired_capabilities['name'] = self.id() if not LOCAL_RUN: self.admin = Admin(use_env_vars=True, pasta_user=self.ps, capabilities=self.desired_capabilities) else: self.admin = Admin(use_env_vars=True, ) self.wait = WebDriverWait(self.admin.driver, Assignment.WAIT_TIME) self.admin.login() self.admin.goto_admin_control() def tearDown(self): """Test destructor.""" if not LOCAL_RUN: self.ps.update_job(job_id=str(self.admin.driver.session_id), **self.ps.test_updates) try: self.admin.delete() except: pass def test_set_course_details_admin(self): """ Pre-req: "Course-Navigate" Log into Admin Click on user name for drop down Click on 'Admin' option in menu Click on 'Course Organization' for dropdown menu Click on 'Courses' Click on 'Edit' Type new course scholastic year into 'Year' text-book ***(t1.59.21)*** Type new number into number of sections ***(t1.59.22)*** Set the course start date and time under the 'Starts at' text box ***(t1.59.23)*** Set the course end date and time under the 'Ends at' textbox ***(t1.59.24)*** Set the course offering under the 'Catalog Offering' dropdown ***(t1.59.25)*** Set the course offering appearance code under the 'Appearance Code' dropdown ***(t1.59.26)*** Click 'Course duration' ***End and start dates should be displayed (t2.07.11)*** Corresponds to... t1.59 21 --> 26 :return: """ # t1.59.21 --> Type new course scholastic year into 'Year' text-book # Setup() leaves you at the admin control self.admin.goto_course_list() ### # Create the course create_new_course = self.admin.find(By.XPATH, "//a[text()='Add Course']") self.admin.driver.execute_script( 'return arguments[0].scrollIntoView();', create_new_course) create_new_course.click() self.admin.find( By.ID, "course_year").send_keys((Keys.DELETE * 4) + str(datetime.date.today().year)) # t1.59.22 --> Type new number into number of sections self.admin.find(By.ID, "course_num_sections").send_keys((Keys.DELETE) + str(1)) # t1.59.23 -->Set the course start date and time under the 'Starts at' text box self.admin.find(By.ID, "course_starts_at").click() self.admin.sleep(1) next_calendar_arrows = self.admin.find_all( By.XPATH, '//div[contains(@class,"datepicker")]' + '//button[contains(@class,"_next")]') # next_calendar_arrows[0].click() # have to find all because the two right arrows for the # start and end date have identical xpath's --> doing this allows us to pick the first or second #get the date right_now = datetime.datetime.now() hour_plus_one = str(right_now.replace(hour=right_now.hour + 1).hour) month_now = str(right_now.replace(month=right_now.month - 1).month) month_plus_one = str( right_now.month) # months are 1 minus their actual number print(right_now) print(month_now) print(hour_plus_one) print(month_plus_one) self.admin.find( By.XPATH, '//div[contains(@class,"calendar")]' + '//td[@data-date="1" and @data-month="{0}"]'.format(month_now) ).click() # Choose start date self.wait.until( expect.visibility_of_element_located( (By.XPATH, '//div[contains(@class,"timepicker")]//div[@data-hour="{0}"]'. format(hour_plus_one)))).click() # t1.59.24 --> Set the course end date and time under the 'Ends at' textbox # Choose end date self.admin.find(By.ID, "course_ends_at").click() self.admin.sleep(1) next_calendar_arrows[-1].click() self.admin.find_all( By.XPATH, '//div[contains(@class,"calendar")]' + '//td[@data-date="1" and @data-month="{0}"]'.format(month_plus_one) )[-1].click() self.admin.sleep(5) # choose end time self.admin.find_all( By.XPATH, '//div[contains(@class,"timepicker")]//div[@data-hour="{0}"]'. format(hour_plus_one))[-1].click() # t1.59.25 --> Set the course offering under the 'Catalog Offering' dropdown self.admin.find(By.ID, "course_catalog_offering_id").click() self.admin.find( By.XPATH, '//select[@id="course_catalog_offering_id"]/option[2]').click() # t1.59.26 -->Set the course offering appearance code under the 'Appearance Code' dropdown self.admin.find(By.ID, "course_appearance_code").click() self.admin.find( By.XPATH, '//select[@id="course_appearance_code"]/option[2]').click()
class TestTutorAdmin(unittest.TestCase): """Tutor | Teacher""" def setUp(self): """Pretest settings.""" self.ps = PastaSauce() self.desired_capabilities['name'] = self.id() if not LOCAL_RUN: self.admin = Admin( use_env_vars=True, pasta_user=self.ps, capabilities=self.desired_capabilities ) else: self.admin = Admin( use_env_vars=True ) def tearDown(self): """Test destructor.""" if not LOCAL_RUN: self.ps.update_job( job_id=str(self.teacher.driver.session_id), **self.ps.test_updates ) try: self.admin.delete() except: pass @pytest.mark.skipif(str(162255) not in TESTS, reason='Excluded') def test_admin_change_course_start_end_dates_162255(self): """ Log in as an Admin Go to the course management page Edit a course Change the term and course year Click Save ***Start and end dates should reflect the new term's timeframe*** Edit a course Change the Starts at date and Ends at date Click Save Expected Result: ***Start and end dates are changed*** https://trello.com/c/YuvX7DN0/25-admin-change-course-start-end-dates """ self.ps.test_updates['name'] = 'tutor_course_settings_admin_162255' + \ inspect.currentframe().f_code.co_name[4:] self.ps.test_updates['tags'] = ['tutor', 'course_settings', 'admin', '162255'] self.ps.test_updates['passed'] = False # go to courses admin page directly and log in URL = str(os.getenv('SERVER_URL')) + '/admin/courses' self.admin.login(url=URL) # search 'preview' in the search bar self.admin.find(By.CSS_SELECTOR, "#search-courses").send_keys('preview\n') self.admin.page.wait_for_page_load() pages = self.admin.find_all(By.CSS_SELECTOR, ".pagination>a") # go to very last page self.admin.scroll_to(pages[-2]) self.admin.sleep(1) pages[-2].click() # click on Edit button for very last course edit = self.admin.find_all(By.XPATH, ".//*[contains(text(),'Edit')]") self.admin.scroll_to(edit[-1]) edit[-1].click() # change year field by adding 1 yearfield = self.admin.find(By.CSS_SELECTOR, "#course_year") year = yearfield.get_attribute('value') newyear = str(int(year) + 1) yearfield.send_keys(len(year) * Keys.DELETE) yearfield.send_keys(newyear) # change start date and end date oldstartdatefield = self.admin.find(By.CSS_SELECTOR, "#course_starts_at") oldenddatefield = self.admin.find(By.CSS_SELECTOR, "#course_ends_at") # get start date and end date values oldstartdate = oldstartdatefield.get_attribute('value') oldenddate = oldenddatefield.get_attribute('value') change = datetime.timedelta(days=400) # converts start date and end date values into datetime objects and adds the change newstartdate = datetime.datetime.strptime( oldstartdate, '%Y-%m-%d %X %Z') + change # converts into a string format accepted by the form oldstartdatefield.send_keys( datetime.datetime.strftime( newstartdate, '%Y/%m/%d %X' )[:-3] ) # converts start date and end date values into datetime objects and adds change ( 400 days) newenddate = datetime.datetime.strptime( oldenddate, '%Y-%m-%d %X %Z') + change # converts into a string format accepted by teh form # newenddate = datetime.datetime.strftime(newenddate1, '%Y/%m/%d %X')[:-3] oldenddatefield.send_keys( datetime.datetime.strftime( newenddate, '%Y/%m/%d %X')[:-3] ) # saves changes self.admin.sleep(1) self.admin.find(By.CSS_SELECTOR, "#edit-save").click() self.admin.sleep(1) # updated start date and end date fields, get their values updatedstartdate = self.admin.find( By.CSS_SELECTOR, "#course_starts_at").get_attribute('value') updatedstartdatetime = datetime.datetime.strptime( updatedstartdate, '%Y-%m-%d %X %Z' ) updatedenddate = self.admin.find( By.CSS_SELECTOR, "#course_ends_at").get_attribute('value') updatedenddatetime = datetime.datetime.strptime( updatedenddate, '%Y-%m-%d %X %Z' ) # assert that the datetime objects I put into it are the ones in the updated field assert(newstartdate.isocalendar() == updatedstartdatetime.isocalendar()) assert(newenddate.isocalendar() == updatedenddatetime.isocalendar()) # change start date and end date to what it was yearfield = self.admin.find(By.CSS_SELECTOR, "#course_year") yearfield.send_keys(len(year) * Keys.DELETE) yearfield.send_keys(year) startdatefield = self.admin.find(By.CSS_SELECTOR, "#course_starts_at") startdatefield.send_keys(datetime.datetime.strftime( datetime.datetime.strptime(oldstartdate, '%Y-%m-%d %X %Z'), '%Y/%m/%d %X')[:-3] ) enddatefield = self.admin.find(By.CSS_SELECTOR, "#course_ends_at") enddatefield.send_keys(datetime.datetime.strftime( datetime.datetime.strptime(oldenddate, '%Y-%m-%d %X %Z'), '%Y/%m/%d %X')[:-3] ) self.admin.find(By.CSS_SELECTOR, "#edit-save").click() self.ps.test_updates['passed'] = True @pytest.mark.skipif(str(162256) not in TESTS, reason='Excluded') def test_notification_and_faulty_url_162256(self): """ Go to tutor qa Log in as admin Click "Admin" from the user menu Click "System Setting" Click "Notifications" Enter a new notification into the text box Click "Add" Log out of admin account Log in as a teacher ***An orange header with the notification pops up when you sign in*** Go to a fake url page to test if styled error page is displayed Expected result: ***a styled error page is displayed*** Corresponding test case: T2.18 001, 030 """ self.ps.test_updates['name'] = 'tutor_system_settings_admin_162256' + \ inspect.currentframe().f_code.co_name[4:] self.ps.test_updates['tags'] = ['tutor', 'system_settings', 'admin', '162256'] self.ps.test_updates['passed'] = False # go to admin instance self.admin.login(url=os.getenv('SERVER_URL') + '/admin') # go to system settings, then notifications, then set a notification self.admin.find(By.XPATH,".//*[contains(text(),'System Setting')]").click() self.admin.find(By.CSS_SELECTOR,"a[href*='notification']").click() self.admin.find(By.CSS_SELECTOR, "#message").send_keys('test_notification') self.admin.find(By.CSS_SELECTOR, ".btn.btn-default").click() # logout of admin self.admin.find(By.XPATH,".//*[contains(text(),'admin')]").click() self.admin.find(By.CSS_SELECTOR, 'a[href*="logout"]').click() # log into teacher account self.admin.login(username=os.getenv('TEACHER_USER'), password=os.getenv('TEACHER_PASSWORD')) self.admin.find(By.CSS_SELECTOR, '.my-courses-item-title>a').click() # if popup asking how you will be using Tutor shows up try: self.admin.find(By.XPATH, './/*[contains(text(),"I don’t know yet")]') except: pass # checks if notification is there self.admin.wait.until( expect.visibility_of_element_located(( By.XPATH, '//div[contains(@class,"notifications-bar")]' + '//span[text()="test_notification"]' )) ) self.admin.find( By.XPATH, '//div[contains(@class,"notifications-bar")]' + '//span[text()="test_notification"]' ) # log out of teacher self.admin.logout() # log into admin self.admin.login(url=os.getenv('SERVER_URL') + '/admin') self.admin.find(By.XPATH, '//a[text()="System Setting"]').click() self.admin.find(By.XPATH, '//a[text()="Notifications"]').click() # remove general notification self.admin.find(By.XPATH, '//a[text()="Remove"]').click() self.admin.driver.switch_to_alert().accept() # go to invalid website self.admin.get(os.getenv('SERVER_URL') + '/not_a_Real_page') # confirm styling of webpage self.admin.find(By.CSS_SELECTOR, '.invalid-page') self.ps.test_updates['passed'] = True