def test_create_course(self): self.assertEqual(self.ad1.create_course("CS361", 3), Course("CS361", 3)) self.data.courses.append(self, Course("CS337", 1)) # course already exists self.assertEqual(self.ad1.create_course("CS337", 2), "Course already exists")
def setUp(self): self.SUP = Supervisor("*****@*****.**", "SUP") self.ADMIN = Administrator("*****@*****.**", "ADMIN") self.INS = Instructor("*****@*****.**", "INS") self.TA = TA("*****@*****.**", "TA") self.Course1 = Course("CS351", 3) self.Course2 = Course("CS431", 2) self.Course3 = Course("CS361", 3)
def setUp(self): self.ta0 = TA("*****@*****.**", "password", "ta") self.ta1 = TA("*****@*****.**", "password", "ta") self.ta2 = TA("*****@*****.**", "password", "ta") self.ta3 = TA("*****@*****.**", "password", "ta") self.course1 = Course("CS101", 0) self.course2 = Course("CS201", 0) self.course3 = Course("CS301", 0)
def test_access_info_all_the_things(self): # ALL THE THINGS self.inst1 = Instructor("*****@*****.**", "password", "instructor") self.inst2 = Instructor("*****@*****.**", "password", "instructor") self.ta1 = TA("*****@*****.**", "password", "ta") self.ta2 = TA("*****@*****.**", "password", "ta") self.course1 = Course("CS101", 0) self.course2 = Course("CS102", 0) self.course1.instructor = "*****@*****.**" mod_course1 = models.ModelCourse.objects.get(course_id="CS101") mod_course1.instructor = "*****@*****.**" mod_course1.save() self.course2.instructor = "*****@*****.**" mod_course2 = models.ModelCourse.objects.get(course_id="CS102") mod_course2.instructor = "*****@*****.**" mod_course2.save() mod_ta_course1 = models.ModelTACourse() mod_ta_course1.course = mod_course1 mod_ta1 = models.ModelPerson.objects.get(email="*****@*****.**") mod_ta_course1.TA = mod_ta1 mod_ta_course1.save() mod_ta_course2 = models.ModelTACourse() mod_ta_course2.course = mod_course2 mod_ta2 = models.ModelPerson.objects.get(email="*****@*****.**") mod_ta_course2.TA = mod_ta2 mod_ta_course2.save() access_info = self.ad1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[0], "Administrator:") self.assertEqual(parse_info[1], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[2], "") self.assertEqual(parse_info[3], "Supervisor:") self.assertEqual(parse_info[4], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[5], "") self.assertEqual(parse_info[6], "Instructors:") self.assertEqual(parse_info[7], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[8], "\tCourse: CS101") self.assertEqual(parse_info[9], "") self.assertEqual(parse_info[10], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[11], "\tCourse: CS102") self.assertEqual(parse_info[12], "") self.assertEqual(parse_info[13], "") self.assertEqual(parse_info[14], "TAs:") self.assertEqual(parse_info[15], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[16], "\tCourse: CS101") self.assertEqual(parse_info[17], "") self.assertEqual(parse_info[18], "DEFAULT | [email protected] | 000.000.0000") self.assertEqual(parse_info[19], "\tCourse: CS102") self.assertEqual(parse_info[20], "") self.assertEqual(parse_info[21], "") self.assertEqual(parse_info[22], "Courses:") self.assertEqual(parse_info[23], "CS101") self.assertEqual(parse_info[24], "CS102")
def setUp(self): self.TA1 = TA("*****@*****.**", "ta1Pass") self.TA2 = TA("*****@*****.**", "ta2Pass") self.TA3 = TA("*****@*****.**", "ta3Pass") self.INS = Instructor("*****@*****.**", "insPass") self.SUP = Supervisor("*****@*****.**", "supPass") self.ADMIN = Administrator("*****@*****.**", "adminPass") self.COURSE1 = Course("CS101", 2) self.COURSE2 = Course("CS222", 2)
def setup(self): self.Sup = Supervisor("*****@*****.**", "SupervisorPassword") self.Admin = Administrator("*****@*****.**", "AdministratorPassword") self.Inst = Instructor("*****@*****.**", "InstructorPassword") self.Inst2 = Instructor("*****@*****.**", "InstructorPassword2") self.TA = TA("*****@*****.**", "TAPassword") self.Course1 = Course("SomeCSClass1", 1) self.Course2 = Course("SomeCSClass2", 2) self.Course3 = Course("SomeCSClass3", 3)
def setup(self): self.course1 = Course("CS251", 2) self.course2 = Course("CS535", 0) # fake instructor self.instructor1 = "Professor Professorson" # fake TAs self.ta1 = "Tommy Adams" self.ta2 = "Tanya Anderson" self.ta3 = "Tina Abbot"
def test_assign_ta_course(self): # TA 1 is assigned CS101 # fake instructors self.ta1 = TA("*****@*****.**", "blah", "ta") self.ta2 = TA("*****@*****.**", "inspass", "ta") self.ta3 = TA("*****@*****.**", "pass3", "ta") # fake course self.course1 = Course("CS101-301", 2) self.course2 = Course("CS202-201", 0) # instructor 1 is assigned CS101 self.assertTrue(self.sup1.assign_ta_course(self.ta1, self.course1)) # self.assertEqual(self.course1.tee_ays[0], "*****@*****.**") db_ta_course = models.ModelTACourse.objects.get(course=models.ModelCourse.objects.get(course_id="CS101-301"), TA=models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.TA, models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.course, models.ModelCourse.objects.get(course_id="CS101-301")) # assign TA 1 another course self.assertTrue(self.sup1.assign_ta_course(self.ta1, self.course2)) #self.assertEqual(self.course1.tee_ays[0], "*****@*****.**") db_ta_course = models.ModelTACourse.objects.get(course=models.ModelCourse.objects.get(course_id="CS202-201"), TA=models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.TA, models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.course, models.ModelCourse.objects.get(course_id="CS202-201")) # TA 2 is assigned CS101 self.assertTrue(self.sup1.assign_ta_course(self.ta2, self.course1)) #self.assertEqual(self.course1.tee_ays[0], "*****@*****.**") db_ta_course = models.ModelTACourse.objects.get(course=models.ModelCourse.objects.get(course_id="CS101-301"), TA=models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.TA, models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.course, models.ModelCourse.objects.get(course_id="CS101-301")) # Try to assign a third TA to CS101 self.assertTrue(self.sup1.assign_ta_course(self.ta3, self.course1)) #self.assertEqual(self.course1.tee_ays[0], "*****@*****.**") db_ta_course = models.ModelTACourse.objects.get(course=models.ModelCourse.objects.get(course_id="CS101-301"), TA=models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.TA, models.ModelPerson.objects.get(email="*****@*****.**")) self.assertEqual(db_ta_course.course, models.ModelCourse.objects.get(course_id="CS101-301")) self.admin1 = Administrator("*****@*****.**", "admin1", "administrator") with self.assertRaises(TypeError): self.sup1.assign_ta_course(self.admin1, self.course1) with self.assertRaises(TypeError): self.sup1.assign_ta_course(self.sup1, self.course1) self.ins1 = Instructor("*****@*****.**", "ins11111", "instructor") with self.assertRaises(TypeError): self.sup1.assign_ta_course(self.ins1, self.course1) with self.assertRaises(AttributeError): self.sup1.assign_ta_course(self.ta1, "CS301-111") with self.assertRaises(AttributeError): self.sup1.assign_ta_course("*****@*****.**", self.course1)
def create_course(self, course_id, num_labs): if len(course_id) != 9: print( f"{course_id} is too short to be of the right form (CS###-###)" ) return False if course_id[0:2] != "CS": print(f"{course_id} is not a CS course (CS###-###)") return False if not course_id[2:5].isdigit(): print("The course number contains an invalid digit (CS###-###)") return False if course_id[5] != "-": print( "The course and section number should be separated by a hyphen (CS###-###)" ) return False if not course_id[6:].isdigit(): print("The section number contains an invalid digit (CS###-###)") return False if num_labs < 0 or num_labs > 5: print( "The number of lab sections should be positive and not exceed 5" ) return False try: find_course = models.ModelCourse.objects.get(course_id=course_id) except models.ModelCourse.DoesNotExist: find_course = "none" if find_course != "none": return False new_course = Course(course_id, num_labs) return True
class AssignTALab(TestCase): def setUp(self): self.TA1 = TA("*****@*****.**", "TA1") self.Course1 = Course("CS101", 1) self.Course1.set_lab(1, 801) self.assertEqual(self.ui.command("assign_ta_course [email protected] CS101"), "[email protected] was assigned to CS101") def test_assign_ta_lab(self): # best case self.assertEqual(self.ui.command("assign_ta_lab [email protected] 801"), "[email protected] was assigned to lab 801") def test_assign_ta_lab_args_dne(self): # entered arguments that don't exist self.assertEqual(self.ui.command("assign_ta_lab TA1, 801"), "Error: invalid email address") self.assertEqual( self.ui.command("assign_ta_lab [email protected], 801"), "[email protected] could not be assigned since it does not exist") self.assertEqual(self.ui.command("assign_ta_lab [email protected], 802"), "802 could not be assigned since it does not exist") def test_assign_ta_lab_num_args(self): # test number of arguments self.assertEqual(self.ui.command("assign_ta_lab [email protected]"), "Error: too few arguments") self.assertEqual(self.ui.command("assign_ta_lab"), "Error: too few arguments") def test_assign_ta_lab_full(self): # test if lab section already has a TA self.TA2 = ("*****@*****.**", "TA2") self.assertEqual(self.ui.command("assign_ta_lab [email protected] 801"), "Lab 801 already has been assigned a TA") def test_assign_ta_lab_not_ta(self): # test against non-TAs self.SUP = Supervisor("*****@*****.**", "SUP") self.ADMIN = Administrator("*****@*****.**", "ADMIN") self.INS = Instructor("*****@*****.**", "INS") self.assertEqual(self.ui.command("assign_ta_lab [email protected] 801"), "Error: [email protected] is not a TA") self.assertEqual(self.ui.command("assign_ta_lab [email protected] 801"), "Error: [email protected] is not a TA") self.assertEqual(self.ui.command("assign_ta_lab [email protected] 801"), "Error: [email protected] is not a TA")
def test_assign_instructor_course(self): # fake instructors self.ins1 = Instructor("*****@*****.**", "blah", "instructor") self.ins2 = Instructor("*****@*****.**", "inspass", "instructor") # fake course self.course1 = Course("CS101", 2) self.course2 = Course("CS202", 0) # instructor 1 is assigned CS101 self.assertTrue(self.sup1.assign_instructor(self.ins1, self.course1)) # self.assertEqual(self.ins1.courses[0], self.course1) self.assertEqual(self.course1.instructor.email, "*****@*****.**") # assign instructor 1 another course self.assertTrue(self.sup1.assign_instructor(self.ins1, self.course2)) # self.assertEqual(self.ins1.courses[1], self.course2) self.assertEqual(self.course2.instructor.email, "*****@*****.**") # instructor 2 is assigned CS101 self.assertTrue(self.sup1.assign_instructor(self.ins2, self.course1)) # self.assertEqual(self.ins2.courses[0], self.course1) self.assertEqual(self.course1.instructor.email, "*****@*****.**") # self.assertNotEqual(self.ins1.courses[0], self.course1) self.ta1 = TA("*****@*****.**", "beh", "TA") with self.assertRaises(TypeError): self.sup1.assign_instructor(self.ta1, self.course1) self.admin1 = Administrator("*****@*****.**", "admin1", "administrator") with self.assertRaises(TypeError): self.sup1.assign_instructor(self.admin1, self.course1) with self.assertRaises(TypeError): self.sup1.assign_instructor(self.sup1, self.course1) with self.assertRaises(AttributeError): self.sup1.assign_instructor(self.ins1, "CS301-111") with self.assertRaises(AttributeError): self.sup1.assign_instructor("*****@*****.**", self.course1) self.sup1.create_course("CS337-401", 3) da_course = models.ModelCourse.objects.get(course_id="CS337-401") # self.test_course = Course(da_course.course_id, da_course.num_labs) # self.sup.assign_instructor(self.ins1, self.test_course) da_courseaa = models.ModelCourse.objects.get(course_id="CS337-401") self.assertEquals(da_courseaa.num_labs, da_course.num_labs) self.assertEquals(da_courseaa.course_id, da_course.course_id)
def setUp(self): # self.instructor1 = Instructor("*****@*****.**", "DEFAULT_PASSWORD") # self.instructor2 = Instructor("*****@*****.**", "DEFAULT_PASSWORD") # fake TA # self.ta1 = ("*****@*****.**", "DEFAULT_PASSWORD") # self.ta2 = ("*****@*****.**", "DEFAULT_PASSWORD") # fake Course # self.course1 = ("Course 1", 2, self.instructor1, [self.ta1]) # self.course2 = ("Course 2", 2, self.instructor2, [self.ta2]) self.inst0 = Instructor("*****@*****.**", "password", "instructor") self.ta0 = TA("*****@*****.**", "password", "ta") self.ta1 = TA("*****@*****.**", "password", "ta") self.ta2 = TA("*****@*****.**", "password", "ta") self.ta3 = TA("*****@*****.**", "password", "ta") self.course1 = Course("CS101", 0) self.course2 = Course("CS201", 0) self.course3 = Course("CS301", 0)
def getCourses(url): driver = webdriver.Chrome(chrome_driver, options=chrome_options) driver.get(url) html = driver.page_source soup = BeautifulSoup(html, 'lxml') courses = [] driver.execute_script("window.scrollTo(0, window.scrollY + 4400)") pageCount = len(driver.find_elements_by_xpath("//div[@class='pageButtons']/div[contains(@class, 'pageNumber')]")) courseCount = driver.find_element_by_xpath("//div[@class='race-count']/p[1]").text # Do the first page driver.execute_script("window.scrollTo(0, window.scrollY + 0)") currPage = 1 for i in progressbar(range(pageCount), "Getting Courses: "): html = driver.page_source soup = BeautifulSoup(html, 'lxml') for courseDiv in soup.find_all('div', {'class' : 'race-card'}): name = courseDiv.find('div', {'class' : 'details-left'}).h3.text location = courseDiv.find('p', {'class' : 'race-location'}).text month = courseDiv.find('p', {'class' : 'race-month'}).text day = courseDiv.find('p', {'class' : 'race-day'}).text year = courseDiv.find('p', {'class' : 'race-year'}).text date = month + ' ' + day + ' ' + year url = courseDiv.find('div', {'class' : 'race-details-right'}).a['href'] courseID = None with Database() as db: checkCourseExists = db.query("SELECT course_id from course where name = %s", (name,)) if not checkCourseExists: db.execute("INSERT INTO course (name, location, url) VALUES (%s, %s, %s)", (name,location, url,)) courseID = db.cursor.lastrowid else: courseID = checkCourseExists[0][0] course = Course(courseID, name, location, url) courses.append(course) # Make and insert the next race for this course here if currPage != pageCount: driver.execute_script("window.scrollTo(0, window.scrollY + 4400)") time.sleep(2) nxt = driver.find_element_by_xpath("//div[@class='paginationButtons']/button[@class='nextPageButton']") actions = ActionChains(driver) actions.click(nxt).perform() currPage += 1 time.sleep(2) driver.quit() return courses
def test_access_info_inst_one_course(self): # Instructor with a course self.inst1 = Instructor("*****@*****.**", "password", "instructor") self.course1 = Course("CS101", 0) self.course1.instructor = "*****@*****.**" mod_course1 = models.ModelCourse.objects.get(course_id="CS101") mod_course1.instructor = "*****@*****.**" mod_course1.save() access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[8], "\tCourse: CS101")
def test_access_info_ta_one_course(self): # TA with a course self.ta1 = TA("*****@*****.**", "password", "ta") mod_ta_course1 = models.ModelTACourse() self.course1 = Course("CS101", 0) mod_course1 = models.ModelCourse.objects.get(course_id="CS101") mod_ta_course1.course = mod_course1 mod_ta1 = models.ModelPerson.objects.get(email="*****@*****.**") mod_ta_course1.TA = mod_ta1 mod_ta_course1.save() access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[10], "\tCourse: CS101")
def create_courses(courses_file): import csv if not str(courses_file).__contains__(".csv"): courses_file = courses_file + ".csv" with open(courses_file) as csvfile: reader = csv.reader(csvfile, delimiter=',') cell_count = 0 course_list = [] for row in reader: if cell_count > 0 and readable_row(row): course_list.append(Course( cell_count, row[0], row[1], row[2], float(row[3]), row[7], row[6])) cell_count += 1 course_list = inital_clean(course_list) i = 0 for course in course_list: course.prereqs = process_prerequisites.create_reqs_list(course.prereqs) course.attributes = process_attributes.create_attr_list(course.attributes) return course_list
def _add_course(self): test_list = set() should_take = {} for mark in self._marks: if mark.test_id not in test_list: test_list.add(mark.test_id) test = Test(mark.test_id) course = Course(test.course_id) should_take[course.name] = len(course.weights) weighted_mark = mark.mark * \ course.weights[test.test_id] if course.name not in self.enrolled_courses: self.enrolled_courses[course.name] = [weighted_mark] self.course_teacher[course.name] = course.teacher self.course_id[int(test.course_id)] = course.name else: self.enrolled_courses[course.name].append(weighted_mark) for course_name in self.enrolled_courses: test_taken = len(self.enrolled_courses[course_name]) if test_taken != should_take[course_name]: raise Exception( f"Student {self.name} did not taken enough test in {course_name}" )
def setUp(self): self.TA1 = TA("*****@*****.**", "TA1") self.Course1 = Course("CS101", 1) self.Course1.set_lab(1, 801) self.assertEqual(self.ui.command("assign_ta_course [email protected] CS101"), "[email protected] was assigned to CS101")
def create_course(self, course_id, num_labs): new_course = Course(course_id, num_labs) if Database.courses.contains(course_id): return "Course already exists" Database.courses.append(course_id) return new_course
class TestCourse(TestCase): def setup(self): self.course1 = Course("CS251", 2) self.course2 = Course("CS535", 0) # fake instructor self.instructor1 = "Professor Professorson" # fake TAs self.ta1 = "Tommy Adams" self.ta2 = "Tanya Anderson" self.ta3 = "Tina Abbot" def test___init__(self): self.assertEquals(self.course1.course_id, "CS251") self.assertEquals(self.course1.num_labs, 2) self.assertEquals(self.course1.instructor, "Dr. Default") self.assertEquals(self.course1.tee_ays, []) def test_set_course_id(self): self.course1.set_course_id("CS351") self.assertEquals(self.course1.course_id, "CS351") self.assertNotEquals(self.course1.course_id, "CS251") def test_set_instructor(self): # this needs to use self.course1.set_instructor("Professor Professorson") self.assertEquals(self.course1.instructor, self.instructor1) self.assertNotEquals(self.course1.instructor, "Dr. Default") def test_set_num_labs(self): self.course1.set_num_labs(4) self.assertEquals(self.course1.num_labs, 4) self.assertNotEquals(self.course1.num_labs, 2) def test_add_tee_ay(self): self.course1.add_tee_ay(self.ta1) self.course1.add_tee_ay(self.ta2) self.course2.add_tee_ay(self.ta3) self.assertEquals(self.course1.tee_ays[0], self.ta1) self.assertEquals(self.course1.tee_ays[0], self.ta2) self.assertEquals(self.course2.tee_ays[0], self.ta3) self.assertNotEquals(self.course1.tee_ays, []) self.assertNotEquals(self.course2.tee_ays, []) def test_get_course_id(self): self.assertEquals(self.course1.get_course_id(), "CS351") self.assertNotEquals(self.course1.get_course_id(), "CS251") def test_get_num_labs(self): self.assertEquals(self.course1.get_num_labs(), 4) self.assertNotEquals(self.course1.get_num_labs(), 2) def test_get_tee_ays(self): self.assertEquals(self.course1.get_tee_ays(), [self.ta1, self.ta2]) self.assertEquals(self.course2.get_tee_ays(), [self.ta3]) self.assertNotEquals(self.course1.get_tee_ays(), []) self.assertNotEquals(self.course2.get_tee_ays(), [])
def test_access_info_course(self): # just a course self.course1 = Course("CS101", 0) access_info = self.sup1.access_info() parse_info = access_info.split("\n") self.assertEqual(parse_info[11], "CS101")