Best JavaScript code snippet using fast-check-monorepo
leopardWeb.py
Source:leopardWeb.py
...11 ret = False12 data = self.crs.printCourse()13 for val in data:14 ret = True15 print(16 f"{val['crn']} | {val['title']} | {val['instructor']} | {val['time']} | {val['credit']}")17 return ret18 except Exception as e:19 print("No Classes Found")20 return False 21 def searchCourseByName(self, name):22 try:23 ret = False24 data = self.crs.searchCourseByName(name)25 for val in data:26 ret = True27 print(28 f"{val['title']} | {val['instructor']} | {val['time']} | {val['credit']}")29 return ret30 except Exception as e:31 print("No Classes Found")32 return False33 def searchCourseByCrn(self, crn):34 try:35 ret = False36 data = self.crs.searchCourseByCrn(crn)37 for val in data:38 ret = True39 print(40 f"{val['title']} | {val['instructor']} | {val['time']} | {val['credit']}")41 return ret42 except Exception as e:43 print("No Classes Found")44 return False45 # Zach46 def searchCourseByTime(self, time):47 try:48 ret = False49 data = self.crs.searchCourseByTime(time)50 for val in data:51 ret = True52 print(53 f"{val['title']} | {val['instructor']} | {val['time']} | {val['credit']}")54 return ret55 except Exception as e:56 print("No Classes Found")57 return False 58 def searchCourseByDay(self, days):59 try:60 ret = False61 data = self.crs.searchCourseByDay(days)62 for val in data:63 ret = True64 print(65 f"{val['title']} | {val['instructor']} | {val['time']} | {val['credit']}")66 return ret67 except Exception as e:68 print("No Classes Found")69 return False70 # End Zach71# Brennan72class student(user):73 def login(self, uid, password):74 logRet = self.stud.checkLogin(uid, password)75 if logRet == True:76 self.uid = uid77 return logRet78 def addClass(self, crn):79 try:80 self.crs.addStudentTo(self.uid, crn)81 print("Class Added")82 return True83 except Exception as e:84 print("Error")85 return False86 def dropClass(self, crn):87 try:88 self.crs.removeStudentFrom(self.uid, crn)89 print("Class Dropped")90 return True91 except Exception as e:92 print("Error")93 return False94 def printSchedule(self):95 try:96 data = self.stud.printSchedule(self.uid)97 for val in data:98 print(99 f"{val['title']} | {val['instructor']} | {val['time']} | {val['credit']}")100 return True101 except Exception as e:102 print("No Classes Found")103 return False104class instructor(user):105 def login(self, uid, password):106 logRet = self.inst.checkLogin(uid, password)107 if logRet == True:108 self.uid = uid109 return logRet110 def printSchedule(self):111 try:112 data = self.inst.printSchedule(self.uid)113 for val in data:114 print(115 f"{val['title']} | {val['instructor']} | {val['time']} | {val['credit']}")116 return True117 except Exception as e:118 print("No Classes Found")119 return False120 def printClassList(self, crn):121 try:122 data = self.crs.printRoster(crn)123 for val in data:124 print(f"{val['uid']} | {val['name']}" | {val['email']})125 return True126 except Exception as e:127 print("Error")128 return False129class admin(user):130 def login(self, uid, password):131 logRet = self.adm.checkLogin(uid, password)132 if logRet == True:133 self.uid = uid134 return logRet135 # End Brennan136 # Zach137 # add course to COURSE db138 def addCourse(self, crn, title, dept, time, days, semester, year, creditVal, instructor):139 try:140 self.crs.createCourse(crn, title, dept, time, days, semester, year, creditVal, instructor)141 print("Course added")142 return True143 except Exception as e:144 print("Error: Course already exists")145 return False146 def removeCourse(self, crn): # remove course from COURSE db147 try:148 self.crs.removeCourse(crn)149 print("Course removed")150 return True151 except Exception as e:152 print("Error: Course not found")153 return False154 def addStudentTo(self, uid, crn): # add student to course list for specified course155 try:156 self.crs.addStudentTo(uid, crn)157 print("Student added to course")158 return True159 except Exception as e:160 print("Error: Student already in course")161 return False162 # remove student from course list for specified course163 def removeStudentTo(self, uid, crn):164 try:165 self.crs.removeStudentFrom(uid, crn)166 print("Student removed from course")167 return True168 except Exception as e:169 print("Error: Student not in course")170 return False171 # add student to STUDENT db172 def addStudent(self, uid, pword, fname, lname, gradyear, major, email):173 try:174 self.stud.createStudent(uid, pword, fname, lname, gradyear, major, email)175 print("Student added")176 return True177 except Exception as e:178 print("Error")179 return False180 # add instructor to INSTRUCTOR db181 def addInstructor(self, uid, pword, fname, lname, title, hireyear, dept, email):182 try:183 self.inst.createInstructor(uid, pword, fname, lname, title, hireyear, dept, email)184 print("Instructor added")185 return True186 except Exception as e:187 print("Error")188 return False189 def addAdmin(self, uid, pword, fname, lname, title, office, email): # add admin to ADMIN db190 try:191 self.adm.createAdmin(uid, pword, fname, lname, title, office, email)192 print("Admin added")193 return True194 except Exception as e:195 print("Error")196 return False197 198 def removeStudent(self, uid): # remove student from STUDENT db199 try:200 self.stud.removeStudent(uid)201 print("Student removed")202 return True203 except Exception as e:204 print("Error")205 return False206 def removeInstructor(self, uid): # remove instructor from INSTRUCTOR db207 try:208 self.inst.removeInstructor(uid)209 print("Instructor removed")210 return True211 except Exception as e:212 print("Error")213 return False214 def removeAdmin(self, uid): # remove admin from ADMIN db215 try:216 self.adm.removeAdmin(uid)217 print("Admin removed")218 return True219 except Exception as e:220 print("Error")221 return False222 # End Zach223# Brennan224 def printRoster(self, crn):225 try:226 data = self.crs.printRoster(crn)227 for val in data:228 print(f"{val['uid']} | {val['name']} | {val['email']}")229 return True230 except Exception as e:231 print("Error")232 return False233class leopardWeb():234 def __init__(self):235 self.menu()236 def menu(self):237 retry = True238 while(retry):239 print("Welcome to LeopardWeb!\n")240 print("Please select an option:")241 print("1. Login as a student")242 print("2. Login as an instructor")243 print("3. Login as an administrator")244 print("4. Quit")245 res = input("Enter your choice: ")246 if res == "1":247 self.student()248 elif res == "2":249 self.instructor()250 elif res == "3":251 self.admin()252 elif res == "4":253 print("Goodbye!")254 sys.exit()255 else:256 print("Invalid input.")257 def student(self):258 retry = True259 while(retry):260 self.student = student()261 print("Please enter your ID:")262 idNum = input("ID: ")263 print("Please enter your password:")264 pword = input("Password: ")265 login = self.student.login(idNum, pword)266 if login:267 retry = False268 else:269 print("Invalid ID or password. Please try again.")270 retry = True271 while(retry):272 print("Please select an option:")273 print("1. Search for a class")274 print("2. Add a class")275 print("3. Drop a class")276 print("4. Print your schedule")277 print("5. Logout")278 res = input("Enter your choice: ")279 if res == "1":280 print("1. Search for a class by name")281 print("2. Search for a class by CRN")282 print("3. Search for a class by time")283 print("4. Search for a class by day")284 res = input("Enter your choice: ")285 if res == "1":286 print("Please enter the name of the class:")287 name = input("Name: ")288 self.student.searchCourseByName(name)289 elif res == "2":290 print("Please enter the CRN of the class:")291 crn = input("CRN: ")292 self.student.searchCourseByCrn(crn)293 elif res == "3":294 print("Please enter the time of the class:")295 time = input("Time: ")296 self.student.searchCourseByTime(time)297 elif res == "4":298 print("Please enter the day of the class:")299 days = input("Day: ")300 self.student.searchCourseByDay(days)301 else:302 print("Invalid input.")303 elif res == "2":304 print("Please enter the CRN of the class:")305 crn = input("CRN: ")306 self.student.addClass(crn)307 elif res == "3":308 print("Please enter the CRN of the class:")309 crn = input("CRN: ")310 self.student.dropClass(crn)311 elif res == "4":312 self.student.printSchedule()313 elif res == "5":314 self.menu()315 def admin(self):316 retry = True317 while(retry):318 self.admin = admin()319 print("Please enter your ID:")320 idNum = input("ID: ")321 print("Please enter your password:")322 pword = input("Password: ")323 login = self.admin.login(idNum, pword)324 if login:325 retry = False326 else:327 print("Invalid ID or password. Please try again.")328# Brennan end329 # Zach330 retry = True331 while (retry):332 print("Please select an option:")333 print("1. Search for a course")334 print("2. Add course to system")335 print("3. Remove course from system")336 print("4. Add student to course")337 print("5. Remove student from course")338 print("6. Add user to system")339 print("7. Remove user from system")340 print("8. Print roster of course by CRN")341 print("9. Logout")342 res = input("Enter your choice: ")343 if res == "1": # search course344 print("1. Search for a class by name")345 print("2. Search for a class by CRN")346 print("3. Search for a class by meeting day")347 print("4. Search for a class by meeting time")348 print("5. Print all courses")349 res = input("Enter your choice: ")350 if res == "1": # search course by name351 print("Please enter the name of the class:")352 name = input("Name: ")353 self.admin.searchCourseByName(name)354 elif res == "2": # search course by CRN355 print("Please enter the CRN of the class:")356 crn = input("CRN: ")357 self.admin.searchCourseByCrn(crn)358 elif res == "3": # search course by meeting days359 print("M = Monday")360 print("T = Tuesday")361 print("W = Wednesday")362 print("R = Thursday")363 print("F = Friday")364 print("Combine days with no spaces - such as (MWF) or (TR)")365 print("Please enter the meeting days of the class:")366 days = input("Meeting Days: ")367 self.admin.searchCourseByDay(days)368 elif res == "4": # search course by meeting time369 print("Format is: (1:00pm-2:50pm)")370 print("Please enter the meeting time of the class:")371 time = input("Meeting time: ")372 self.admin.searchCourseByTime(time)373 elif res == "5": # print all courses374 self.admin.printCourse()375 else:376 print("Invalid input.")377 elif res == "2": # add course378 crn = input("Enter course CRN: ")379 title = input("Enter course title: ")380 dept = input("Enter course department: ")381 times = input("Enter course meeting time: ")382 days = input("Enter course meeting day(s): ")383 semester = input("Enter course semester: ")384 year = input("Enter course year: ")385 credit = input("Enter course credit amount: ")386 instructor_entry = input("Enter instructor id: ")387 self.admin.addCourse(388 crn, title, dept, times, days, semester, year, credit, instructor_entry)389 elif res == "3": # remove course from system390 print("Please enter the CRN of the class:")391 crn = input("CRN: ")392 self.admin.removeCourse(crn)393 elif res == "4": # add student to course394 print("Please enter the UID of the student")395 uid = input("UID: ")396 print("Please enter the CRN of the course")397 crn = input("CRN: ")398 self.admin.addStudentTo(uid, crn)399 elif res == "5": # remove student from course400 print("Please enter the UID of the student")401 uid = input("UID: ")402 print("Please enter the CRN of the course")403 crn = input("CRN: ")404 self.admin.removeStudentTo(uid, crn)405 elif res == "6": # add user to system406 print("1. Add student to system")407 print("2. Add instructor to system")408 print("3. Add administrator to system")409 res = input("Enter your choice: ")410 if res == "1": # add student to system411 uid = input("Enter student id: ")412 pword = input("Enter student password: ")413 fname = input("Enter first name: ")414 lname = input("Enter last name: ")415 gradyear = input("Enter graduation year: ")416 major = input("Enter student major: ")417 email = input("Enter student email: ")418 self.admin.addStudent(419 uid, pword, fname, lname, gradyear, major, email)420 elif res == "2": # add instructor to system421 uid = input("Enter instructor id: ")422 pword = input("Enter instructor password: ")423 fname = input("Enter first name: ")424 lname = input("Enter last name: ")425 title = input("Enter title: ")426 hireyear = input("Enter hire year: ")427 dept = input("Enter department: ")428 email = input("Enter instructor email: ")429 self.admin.addInstructor(430 uid, pword, fname, lname, title, hireyear, dept, email)431 elif res == "3": # add admin to system432 uid = input("Enter admin id: ")433 pword = input("Enter admin password: ")434 fname = input("Enter first name: ")435 lname = input("Enter last name: ")436 title = input("Enter title: ")437 office = input("Enter hire year: ")438 email = input("Enter admin email: ")439 self.admin.addAdmin(uid, pword, fname,440 lname, title, office, email)441 else:442 print("Invalid input.")443 elif res == "7":444 print("1. Remove student")445 print("2. Remove instructor")446 print("3. Remove administrator")447 res = input("Enter your choice: ")448 if res == "1": # remove student449 uid = input("Enter student id: ")450 self.admin.removeStudent(uid)451 elif res == "2": # remove instructor452 uid = input("Enter instructor id: ")453 self.admin.removeInstructor(uid)454 elif res == "3": # remove admin455 uid = input("Enter admin id: ")456 self.admin.removeAdmin(uid)457 else:458 print("Invalid input.")459 elif res == "8": # print roster of a course460 print("Please enter the CRN of the course")461 crn = input("CRN: ")462 self.admin.printRoster(crn)463 elif res == "9": # logout464 self.menu()465 else:466 print("Invalid Input.")467 # Zach end468# Brennan469 def instructor(self):470 retry = True471 while(retry):472 self.instructor = instructor()473 print("Please enter your ID:")474 idNum = input("ID: ")475 print("Please enter your password:")476 pword = input("Password: ")477 login = self.instructor.login(idNum, pword)478 if login:479 retry = False480 else:481 print("Invalid ID or password. Please try again.")482 retry = True483 while(retry):484 print("Please select an option:")485 print("1. Search for a class")486 print("2. Print your schedule")487 print("3. Print class list")488 print("4. Logout")489 res = input("Enter your choice: ")490 if res == "1":491 print("1. Search for a class by name")492 print("2. Search for a class by CRN")493 print("3. Search for a class by instructor")494 print("4. Search for a class by time")495 res = input("Enter your choice: ")496 if res == "1":497 print("Please enter the name of the class:")498 name = input("Name: ")499 self.instructor.searchCourseByName(name)500 elif res == "2":501 print("Please enter the CRN of the class:")502 crn = input("CRN: ")503 self.instructor.searchCourseByCrn(crn)504 elif res == "3":505 print("Please enter the name of the instructor:")506 name = input("Name: ")507 self.instructor.searchCourseByInstructor(name)508 elif res == "4":509 print("Please enter the time of the class:")510 time = input("Time: ")511 self.instructor.searchCourseByTime(time)512 else:513 print("Invalid input.")514 elif res == "2":515 self.instructor.printSchedule()516 elif res == "3":517 print("Please enter the CRN of the class:")518 crn = input("CRN: ")519 # Zach - added fix to print info properly520 # now displays as (student_name | student_id)521 self.instructor.printRoster(crn)522 elif res == "4":523 self.menu()524if __name__ == '__main__':...
database.py
Source:database.py
...45 students = ForeignKeyField(STUDENT, backref='courses')46 course = ForeignKeyField(COURSE, backref='courses')47class courseController():48 def createCourse(self, crnEntry, titleEntry, departmentEntry, dayEntry, timeEntry, semesterEntry, yearEntry, creditEntry, instructorEntry):49 instr = INSTRUCTOR.get(INSTRUCTOR.UID == instructorEntry)50 COURSE.create(crn=crnEntry, title=titleEntry, department=departmentEntry, time=timeEntry,51 days=dayEntry, semester=semesterEntry, year=yearEntry, credit=creditEntry, instructor=instr)52 def removeCourse(self, crnVal):53 '''remove COURSE based on CRN'''54 COURSE.delete().where(COURSE.crn == crnVal).execute()55 def printCourse(self):56 crs = COURSE.select()57 crsInfo = []58 for entry in crs:59 csrEntry = {}60 csrEntry['crn'] = entry.crn61 csrEntry['title'] = entry.title62 csrEntry['instructor'] = entry.instructor.NAME + " " + entry.instructor.SURNAME63 csrEntry['time'] = entry.time64 csrEntry['credit'] = entry.credit65 crsInfo.append(csrEntry)66 return crsInfo67 def searchCourseByCrn(self, crnVal):68 '''search COURSE by crn, return as dict'''69 crs = COURSE.select().where(COURSE.crn == crnVal)70 crsInfo = []71 for entry in crs:72 csrEntry = {}73 csrEntry['title'] = entry.title74 csrEntry['instructor'] = entry.instructor.NAME + " " + entry.instructor.SURNAME75 csrEntry['time'] = entry.time76 csrEntry['credit'] = entry.credit77 crsInfo.append(csrEntry)78 return crsInfo79 def searchCourseByName(self, nameVal):80 # search COURSE by name, return as list81 crs = COURSE.select().where(COURSE.title == nameVal)82 crsInfo = []83 for entry in crs:84 csrEntry = {}85 csrEntry['title'] = entry.title86 csrEntry['instructor'] = entry.instructor.NAME + " " + entry.instructor.SURNAME87 csrEntry['time'] = entry.time88 csrEntry['credit'] = entry.credit89 crsInfo.append(csrEntry)90 return crsInfo91 # Zach - added functions to search crs by some additional parameters92 def searchCourseByTime(self, timeVal):93 # search COURSE by time, return as nested list94 crs = COURSE.select().where(COURSE.time == timeVal)95 crsInfo = []96 for entry in crs:97 csrEntry = {}98 csrEntry['title'] = entry.title99 csrEntry['instructor'] = entry.instructor.NAME + " " + entry.instructor.SURNAME100 csrEntry['time'] = entry.time101 csrEntry['credit'] = entry.credit102 crsInfo.append(csrEntry)103 return crsInfo104 def searchCourseByDay(self, dayVal):105 # search COURSE by days, return as list106 crs = COURSE.select().where(COURSE.days == dayVal)107 crsInfo = []108 for entry in crs:109 csrEntry = {}110 csrEntry['title'] = entry.title111 csrEntry['instructor'] = entry.instructor.NAME + " " + entry.instructor.SURNAME112 csrEntry['time'] = entry.time113 csrEntry['credit'] = entry.credit114 crsInfo.append(csrEntry)115 return crsInfo116 def addStudentTo(self, uid, crn): # add student to course - update COURSE_LIST117 stud = STUDENT.get(STUDENT.UID == uid)118 crsEntry = COURSE.get(COURSE.crn == crn)119 COURSE_LIST.create(students=stud, course=crsEntry)120 # remove student from course - update COURSE_LIST121 def removeStudentFrom(self, uid, crn):122 stud = STUDENT.get(STUDENT.UID == uid)123 crs = COURSE.get(COURSE.crn == crn)124 COURSE_LIST.delete().where(COURSE_LIST.students == stud).where(125 COURSE_LIST.course == crs).execute()126 def printRoster(self, crn):127 crs = COURSE.select().where(COURSE.crn == crn)128 roster = COURSE_LIST.select().where(COURSE_LIST.course == crs)129 crsList = []130 for entry in roster:131 data = {}132 data['uid'] = entry.students.UID133 data['name'] = entry.students.NAME + " " + entry.students.SURNAME134 data['email'] = entry.students.EMAIL135 crsList.append(data)136 return crsList137 def updateCourse(self, crnEntry=None, titleEntry=None, departmentEntry=None, timeEntry=None, dayEntry=None, semesterEntry=None, yearEntry=None, creditEntry=None, instructorEntry=None):138 '''update STUDENT, set any vals that should not be changed to null'''139 crs = COURSE.select().where(COURSE.crn == crnEntry).dicts()140 if crnEntry != None:141 crs.crn = crnEntry142 if titleEntry != None:143 crs.title = titleEntry144 if departmentEntry != None:145 crs.department = departmentEntry146 if timeEntry != None:147 crs.time = timeEntry148 if dayEntry != None:149 crs.days = dayEntry150 if semesterEntry != None:151 crs.semester = semesterEntry152 if yearEntry != None:153 crs.year = yearEntry154 if creditEntry != None:155 crs.credit = creditEntry156 if instructorEntry != None:157 instr = INSTRUCTOR.get(INSTRUCTOR.UID == instructorEntry)158 crs.instructor = instr159 crs.save()160 def matchInstructor(self):161 '''List all available instructors for each course'''162 retList = []163 for entry in COURSE:164 instList = []165 instQuery = INSTRUCTOR.select().where(INSTRUCTOR.DEPT == entry.department).get()166 try:167 for inst in instQuery:168 instList.append(inst.NAME)169 except Exception as e:170 instList.append(instQuery.NAME)171 retList.append({entry.title: instList})172 return retList173class studentController():174 def createStudent(self, idVal, pword, fName, lName, expecGrad, majorVal, emailVal):175 STUDENT.create(UID=idVal, PASSWORD=pword, NAME=fName, SURNAME=lName,176 GRADYEAR=expecGrad, MAJOR=majorVal, EMAIL=emailVal)177 def removeStudent(self, idNum):178 '''remove STUDENT based on uid'''179 STUDENT.delete().where(STUDENT.UID == idNum).execute()180 def searchStudentByUID(self, idVal):181 '''search STUDENT by id, return as dict'''182 stud = STUDENT.select().where(STUDENT.UID == idVal)183 return stud.get()184 def printSchedule(self, uid):185 stud = STUDENT.get(STUDENT.UID == uid)186 retList = []187 for entry in COURSE_LIST:188 if entry.students == stud:189 data = {}190 data['title'] = entry.course.title191 try: #check to see if instructor is assigned to course192 data['instructor'] = entry.instructor.NAME + " " + entry.course.instructor.SURNAME193 except Exception as e:194 data['instructor'] = "N/A"195 data['time'] = entry.course.time196 data['credit'] = entry.course.credit197 retList.append(data)198 return retList199 def checkLogin(self, uid, pword):200 try:201 user = STUDENT.select().where(STUDENT.UID == uid).get()202 if user.PASSWORD == pword:203 return True204 else:205 return False206 except Exception as e:207 return False208 def updateStudent(self, idVal, newID=None, pword=None, fName=None, lName=None, expecGrad=None, majorVal=None, emailVal=None):209 '''update STUDENT, set any vals that should not be changed to null'''210 stud = STUDENT.select().where(STUDENT.UID == idVal).get()211 if newID != None:212 stud.UID = newID213 if pword != None:214 stud.PASSWORD = pword215 if fName != None:216 stud.NAME = fName217 if lName != None:218 stud.SURNAME = lName219 if expecGrad != None:220 stud.GRADYEAR = expecGrad221 if majorVal != None:222 stud.MAJOR = majorVal223 if emailVal != None:224 stud.EMAIL = emailVal225 stud.save()226class instructorController():227 def createInstructor(self, idVal, pword, fName, lName, titleVal, yearHired, departmentVal, emailVal):228 INSTRUCTOR.create(UID=idVal, PASSWORD=pword, NAME=fName, SURNAME=lName,229 TITLE=titleVal, HIREYEAR=yearHired, DEPT=departmentVal, EMAIL=emailVal)230 def removeInstructor(self, idNum):231 '''remove INSTRUCTOR based on uid'''232 INSTRUCTOR.delete().where(INSTRUCTOR.UID == idNum).execute()233 def searchInstructorByUID(self, idVal):234 '''search INSTRUCTOR by id, return as dict'''235 inst = INSTRUCTOR.select().where(INSTRUCTOR.UID == idVal)236 return inst.get()237 def printSchedule(self, uid):238 inst = INSTRUCTOR.get(INSTRUCTOR.UID == uid)239 retList = []240 for entry in COURSE_LIST:241 if entry.instructor == inst:242 data = {}243 data['title'] = entry.title244 data['crn'] = entry.crn245 data['time'] = entry.time246 data['days'] = entry.days247 retList.append(data)248 return retList249 def checkLogin(self, uid, pword):250 try:251 user = INSTRUCTOR.select().where(INSTRUCTOR.UID == uid).get()252 if user.PASSWORD == pword:253 return True254 else:255 return False256 except Exception as e:257 return False258 def updateInstructor(self, idVal, newID=None, pword=None, fName=None, lName=None, titleVal=None, yearHired=None, departmentVal=None, emailVal=None):259 '''search STUDENT by id, return as dict'''260 instr = INSTRUCTOR.select().where(INSTRUCTOR == idVal).get()261 if newID != None:262 instr.UID = newID263 if pword != None:264 instr.PASSWORD = pword265 if fName != None:266 instr.NAME = fName267 if lName != None:268 instr.SURNAME = lName269 if titleVal != None:270 instr.TITLE = titleVal271 if yearHired != None:272 instr.HIREYEAR = yearHired273 if departmentVal != None:274 instr.DEPT = departmentVal275 if emailVal != None:276 instr.EMAIL = emailVal277 instr.save()278class adminController():279 def createAdmin(self, idVal, pword, fName, lName, titleVal, officeVal, emailVal):280 ADMIN.create(UID=idVal, PASSWORD=pword, NAME=fName, SURNAME=lName,281 TITLE=titleVal, OFFICE=officeVal, EMAIL=emailVal)282 def removeAdmin(self, idNum):283 '''remove ADMIN based on uid'''284 ADMIN.delete().where(ADMIN.UID == idNum).execute()285 def searchAdminByUID(self, idVal):286 '''search ADMIN by id, return as dict'''287 adm = ADMIN.select().where(ADMIN.UID == idVal)288 return adm.get()289 def checkLogin(self, uid, pword):290 try:291 user = ADMIN.select().where(ADMIN.UID == uid).get()292 if user.PASSWORD == pword:293 return True294 else:295 return False296 except Exception as e:297 return False298 def updateAdmin(self, idVal, newID=None, pword=None, fName=None, lName=None, titleVal=None, OfficeVal=None, emailVal=None):299 '''search STUDENT by id, return as dict'''300 adm = ADMIN.select().where(ADMIN.UID == idVal).get()301 if newID != None:302 adm.UID = newID303 if pword != None:304 adm.PASSWORD = pword305 if fName != None:306 adm.NAME = fName307 if lName != None:308 adm.SURNAME = lName309 if titleVal != None:310 adm.TITLE = titleVal311 if OfficeVal != None:312 adm.OFFICE = OfficeVal313 if emailVal != None:314 adm.EMAIL = emailVal315 adm.save()316if __name__ == '__main__':317 # Run this file on its own to create COURSE table318 parser = argparse.ArgumentParser("Create databases or delete databases.")319 parser.add_argument('mode', type=str,320 help='flag, if c then create database tables if d delete')321 args = parser.parse_args(sys.argv[1:])322 db.connect()323 if args.mode == 'c':324 db.create_tables([INSTRUCTOR, STUDENT, COURSE, COURSE_LIST, ADMIN])325 elif args.mode == 'd':326 db.drop_tables([INSTRUCTOR, STUDENT, COURSE, COURSE_LIST, ADMIN])327 else:...
leopardWebTest.py
Source:leopardWebTest.py
...5from leopardWeb import admin67#TODO: Fix search functions so they return False when no result is found89class adminTest(unittest.TestCase):10 @classmethod11 def setUpClass(self):12 self.adm = admin()13 self.admin = adminController()14 self.instructor = instructorController()1516 self.admin.createAdmin(90287, 'slyOmen12', 'Adam', 'Santano', 'President', 'Wentworth100', 'santanoa')17 18 self.instructor.createInstructor(201100, 'pword', 'Aaron', 'Carpenter', 'Assistant Professor', '2002', 'Electrical', 'acarpenter')19 20 #test login with incorrect credentials21 def testFalseLogin(self):22 self.assertFalse(self.adm.login(11111, 'pword'),23 "Expected error while login")2425 #test login with correct UID & password26 def testLogin(self):27 self.assertTrue(self.adm.login(90287, 'slyOmen12'), 28 "Expected successful login")2930 #test creating admin31 def testCreateAdmin(self):32 ret = self.adm.addAdmin(67824, 'pword', 'Tom', 'Cat', 'Registrar', 'Williston110', 'catt')33 self.assertTrue(ret)34 35 #test creating admin with invalid UID36 def testCreateFalseAdmin(self):37 ret = self.adm.addAdmin(67824, 'pword', 'Tom', 'Cat', 'Registrar', 'Williston110', 'catt')38 self.assertFalse(ret)3940 #test deleting admin41 def testDeleteAdmin(self):42 ret = self.adm.removeAdmin(67824)43 self.assertTrue(ret)4445 #test adding a course to the system46 def testAddCourse(self):47 ret = self.adm.addCourse(918026, 'Applied Programming Concepts', 'BSCS', '8:00am-9:50am', 'TR', 'Spring', '2022', 3, 201100)48 self.assertTrue(ret)4950 #test adding an invalid course51 def testAddInvalidCourse(self):52 ret = self.adm.addCourse(918026, 'Applied Programming Concepts', 'BSCS', '8:00am-9:50am', 'TR', 'Spring', '2022', 3, 201100)53 self.assertFalse(ret)5455 #test removing course from system56 def testRemoveCourse(self):57 ret = self.adm.removeCourse(918026)58 self.assertTrue(ret)5960 #test incorrectly removing course from system61 def testRemoveFalseCourse(self):62 ret = self.adm.removeCourse(000000)63 self.assertTrue(ret)6465 @classmethod66 def tearDownClass(self):67 self.admin.removeAdmin(90287)68 self.instructor.removeInstructor(201100)697071class userTest(unittest.TestCase):72 @classmethod73 def setUpClass(self):74 self.user = user()75 self.inst = instructorController()76 self.course = courseController()7778 self.inst.createInstructor(201100, 'pword', 'Aaron', 'Carpenter', 'Assistant Professor', '2002', 'Electrical', 'acarpenter')79 self.course.createCourse(4011423, "Cyber-Physical Systems", "BSEE", "MWF", "1:00pm-2:50pm", "Spring", "2022", 3, 201100)8081 #test search course by CRN82 def testSearchCourseByCRN(self):83 self.assertTrue(self.user.searchCourseByCrn(4011423))8485 #test search course by invalid CRN86 def testSearchCourseByFalseCRN(self):87 self.assertFalse(self.user.searchCourseByCrn(0000000))8889 #test search course by name90 def testSearchCourseByName(self):91 self.assertTrue(self.user.searchCourseByName('Cyber-Physical Systems'))9293 #test search course by invalid name94 def testSearchCourseByFalseName(self):95 self.assertFalse(self.user.searchCourseByName('Course Name'))96 97 #test search course by days98 def testSearchCourseByDays(self):99 self.assertTrue(self.user.searchCourseByDay('MWF'))100101 #test search course by invalid days102 def testSearchCourseByFalseDays(self):103 self.assertFalse(self.user.searchCourseByDay('days'))104105 #test search course by time106 def testSearchCourseByTime(self):107 self.assertTrue(self.user.searchCourseByTime('1:00pm-2:50pm'))108109 #test search course by invalid time110 def testSearchCourseByFalseTime(self):111 self.assertFalse(self.user.searchCourseByTime('time'))112113 #test print course114 def testPrintCourse(self):115 self.assertTrue(self.user.printCourse())116117 @classmethod118 def tearDownClass(self):119 self.inst.removeInstructor(201100)120 self.course.removeCourse(4011423)121122class instructorTest(unittest.TestCase):123 @classmethod124 def setUpClass(self):125 self.inst = instructor()126 self.instructor = instructorController()127 self.course = courseController()128129 self.instructor.createInstructor(201100, 'pword', 'Aaron', 'Carpenter', 'Assistant Professor', '2002', 'Electrical', 'acarpenter')130 self.course.createCourse(4011422, "Cyber-Physical Systems", "BSEE", "MWF", "1:00pm-2:50pm", "Spring", "2022", 3, 201100)131132 #test login with incorrect credentials133 def testFalseLogin(self):134 self.assertFalse(self.inst.login(11111, 'pword'),135 "Expected error while login")136137 #test login with correct UID & password138 def testLogin(self):139 self.assertTrue(self.inst.login(201100, 'pword'), 140 "Expected successful login")141142 def testPrintSchedule(self):143 self.assertTrue(self.inst.printSchedule())144 145 def testPrintClassList(self):146 self.assertTrue(self.inst.printClassList(4011422))147 148 @classmethod149 def tearDownClass(self):150 self.instructor.removeInstructor(201100)151 self.course.removeCourse(4011422)152153154class studentTest(unittest.TestCase):155 @classmethod156 def setUpClass(self):157 self.stud = student()158159 self.studentCont = studentController()160 self.instructor = instructorController()161 self.course = courseController()162163 self.studentCont.createStudent(301823, "pword", "test", "student", "2023", "BSCO", "dylanbob")164 self.instructor.createInstructor(201100, 'pword', 'Aaron', 'Carpenter', 'Assistant Professor', '2002', 'Electrical', 'acarpenter')165 self.course.createCourse(4011422, "Cyber-Physical Systems", "BSEE", "MWF", "1:00pm-2:50pm", "Spring", "2022", 3, 201100)166167 #test login with incorrect credentials168 def testFalseLogin(self):169 self.assertFalse(self.stud.login(30182356, 'pword'),170 "Expected error while login")171172 #test login with correct UID & password173 def testLogin(self):174 ret = self.stud.login(301823, 'pword')175 self.assertTrue(ret, 176 "Expected successful login")177178 #test adding student to course179 def testAddClass(self):180 self.stud.login(301823, 'pword')181 ret = self.stud.addClass(4011422)182 self.assertTrue(ret)183184 #test adding student to invalid course185 def testAddClassInvalid(self):186 self.stud.login(301823, 'pword')187 ret = self.stud.addClass(401142223)188 self.assertFalse(ret)189190 #test removing student from course191 def testDropClass(self):192 self.stud.login(301823, 'pword')193 ret = self.stud.dropClass(4011422)194 self.assertTrue(ret)195196 #test removing student from invalid course197 def testDropClassInvalid(self):198 self.stud.login(301823, 'pword')199 ret = self.stud.dropClass(401142223)200 self.assertFalse(ret)201202 #test incorrectly removing course from system203 def testPrintSchedule(self):204 ret = self.stud.printSchedule()205 self.assertTrue(ret)206207 @classmethod208 def tearDownClass(self):209 self.studentCont.removeStudent(301823)210 self.instructor.removeInstructor(201100)211 self.course.removeCourse(4011422)212213214215if __name__ == '__main__':216 unittest.main()
...
Using AI Code Generation
1const fastCheck = require('fast-check');2console.log(fastCheck.t);3const fastCheck = require('fast-check');4console.log(fastCheck.t);5const fastCheck1 = require('fast-check');6console.log(fastCheck1.t);7const fastCheck2 = require('fast-check');8console.log(fastCheck2.t);
Using AI Code Generation
1const fc = require("fast-check");2fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b === b + a));3const fc = require("fast-check");4fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b === b + a));5const fc = require("fast-check");6fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b === b + a));7const fc = require("fast-check");8fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b === b + a));9const fc = require("fast-check");10fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b === b + a));11const fc = require("fast-check");12fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b === b + a));13const fc = require("fast-check");14fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b === b + a));15const fc = require("fast-check");16fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b === b + a));17const fc = require("fast-check");18fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b === b + a));19const fc = require("fast-check");20fc.assert(fc.property(fc.integer(), fc.integer(), (a, b) => a + b === b +
Using AI Code Generation
1const { t } = require('fast-check-monorepo');2const { t } = require('fast-check');3const { t } = require('fast-check-monorepo');4const { t } = require('fast-check');5const { t } = require('fast-check-monorepo');6const { t } = require('fast-check');7const { t } = require('fast-check-monorepo');8const { t } = require('fast-check');9const { t } = require('fast-check-monorepo');10const { t } = require('fast-check');11const { t } = require('fast-check-monorepo');12const { t } = require('fast-check');13const { t } = require('fast-check-monorepo');14const { t } = require('fast-check');15const { t } = require('fast-check-monorepo');16const { t } = require('fast-check');17const { t } = require('fast-check-monorepo');18const { t } = require('fast-check');19const { t } = require('fast-check-monorepo');
Using AI Code Generation
1var t = require('fast-check-monorepo').t;2t('test3', function () {3 t('test3a', function () {4 t('test3a1', function () {5 t('test3a1a', function () {6 t('test3a1a1', function () {7 t('test3a1a1a', function () {8 t('test3a1a1a1', function () {9 t('test3a1a1a1a', function () {10 t('test3a1a1a1a1', function () {11 t('test3a1a1a1a1a', function () {12 t('test3a1a1a1a1a1', function () {13 t('test3a1a1a1a1a1a', function () {14 t('test3a1a1a1a1a1a1', function () {15 t('test3a1a1a1a1a1a1a', function () {16 t('test3a1a1a1a1a1a1a1', function () {17 t('test3a1a1a1a1a1a1a1a', function () {18 t('test3a1a1a1a1a1a1a1a1', function () {19 t('test3a1a1a1a1a1a1a1a1a', function () {20 t('test3a1a1a1a1a1a1a1a1a1', function () {21 t('test3a1a1a1a1a1a1a1a1a1a', function () {22 t('test3a1a1a1a1a1a1a1a1a1a1', function () {23 t('test3a1a1a1a1a1a1a1a1a1a1a', function () {24 t('test3a1a1a1a1a1a1a1a1a1a1a1', function () {25 t('test3a1a1a1a1a1a1a1a1a1a1a
Using AI Code Generation
1const { t } = require("fast-check");2t.describe("My first property-based test", () => {3 t.it("should always pass", () => {4 t.property(t.nat(), t.nat(), (a, b) => {5 return a + b >= a;6 });7 });8});9type Foo = {10 readonly bar: number;11};12type Bar = {13 readonly foo: number;14};15type Baz = {16 readonly foo: Foo;17 readonly bar: Bar;18};19function doSomething(baz: Baz): Baz {20 return {21 foo: {22 },23 bar: {24 },25 };26}27import * as fc from "fast-check";28import { doSomething } from "./doSomething";29test("doSomething", () => {30 fc.assert(31 fc.property(32 fc.record({33 foo: fc.record({ bar: fc.nat() }),34 bar: fc.record({ foo: fc.nat() }),35 }),36 (baz) => {37 const result = doSomething(baz);38 expect(result.foo.bar).toBe(baz.foo.bar + baz.bar.foo);39 expect(result.bar.foo).toBe(baz.foo.bar + baz.bar.foo);40 }41 );42});
Using AI Code Generation
1var t = require('fast-check-monorepo/test3.js');2t('test3.js');3var t = require('fast-check-monorepo/test3.js');4t('test3.js');5var t = require('fast-check-monorepo/test4.js');6t('test4.js');7var t = require('fast-check-monorepo/test4.js');8t('test4.js');9var t = require('fast-check-monorepo/test5.js');10t('test5.js');11var t = require('fast-check-monorepo/test5.js');12t('test5.js');13var t = require('fast-check-monorepo/test6.js');14t('test6.js');15var t = require('fast-check-monorepo/test6.js');16t('test6.js');17var t = require('fast-check-monorepo/test7.js');18t('test7.js');19var t = require('fast-check-monorepo/test7.js');20t('test7.js');21var t = require('fast-check-monorepo/test8.js');22t('test8.js');23var t = require('fast-check-monorepo/test8.js');24t('test8.js');25var t = require('fast-check-monorepo/test9.js');26t('test9.js');27var t = require('fast-check-monorepo/test9.js');28t('test9.js');
Using AI Code Generation
1const { t } = require('fast-check')2t('test', () => {3 console.log('hello world')4})5const { t } = require('fast-check')6t('test', () => {7 console.log('hello world')8})9const { t } = require('fast-check')10t('test', () => {11 console.log('hello world')12})13const { t } = require('fast-check')14t('test', () => {15 console.log('hello world')16})17const { t } = require('fast-check')18t('test', () => {19 console.log('hello world')20})21const { t } = require('fast-check')22t('test', () => {23 console.log('hello world')24})25const { t } = require('fast-check')26t('test', () => {27 console.log('hello world')28})29const { t } = require('fast-check')30t('test', () => {31 console.log('hello world')32})33const { t } = require('fast-check')34t('test', () => {35 console.log('hello world')36})37const { t } = require('fast-check')38t('test', () => {39 console.log('hello world')40})41const { t } = require('fast-check')42t('test', () => {43 console.log('hello world')44})45const { t
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!