def test_joinClass(self): print 'Running test_joinClass' joinEmail = '*****@*****.**' password = '******' httpOrigin = 'localhost:1111' activationId = usr.addUserAndSendEmail(httpOrigin, joinEmail, password, mail, dynamodb) usr.activate(activationId, dynamodb) teacherEmail = '*****@*****.**' activationId = usr.addUserAndSendEmail(httpOrigin, teacherEmail, password, mail, dynamodb) usr.activate(activationId, dynamodb) classData = {'title': 'title', 'description': 'desc'} teacherRole = 'teacher' classCtrl.createClass(dynamodb, classData, teacherEmail, teacherRole) res = classCtrl.getPublicClassList(dynamodb, joinEmail) #confirm response can be created from classSet flaskRes = createResponse(res, 200) classes = res.payload['classes'] allClassCodes = set() for c in classes: code = c['code'] allClassCodes.add(code) joinData = {'code': code} res = usr.joinClass(joinData, dynamodb, joinEmail, teacherRole) self.assertFalse(res.hasErrors()) self.assertEqual(res.payload['code'], code) joined = classCtrl.getClassCodesFromUser(dynamodb, joinEmail) missing = joined - allClassCodes #confirm empty set, meaning that all classes have been joined self.assertFalse(missing) joinEmail2 = '*****@*****.**' password = '******' activationId = usr.addUserAndSendEmail(httpOrigin, joinEmail2, password, mail, dynamodb) usr.activate(activationId, dynamodb) badJoinData = {'bad': 'data'} for c in classes: code = c['code'] res = usr.joinClass(badJoinData, dynamodb, joinEmail2, 'student') self.assertTrue(res.hasErrors()) joined = classCtrl.getClassCodesFromUser(dynamodb, joinEmail2) #confirm none joined self.assertFalse(joined)
def test_createMultipleClasses(self): print('Running createMultipleClasses test case') classData = { 'title': 'ENG', 'department': 'arts', 'section': '12', 'description': 'english' } classData2 = { 'title': 'PE', 'department': 'science', 'section': '1', 'description': 'physical education' } email = '*****@*****.**' userRole = 'teacher' class_ctrl.createClass(dynamodb, classData, email, userRole) class_ctrl.createClass(dynamodb, classData2, email, userRole) # check that teaching list was added to user classesTable = db.getTable('classes', dynamodb) usersTable = db.getTable('users', dynamodb) data = {'Key': {'email': email}} teacher = db.getItem(data, usersTable) self.assertTrue('Item' in teacher.keys()) self.assertTrue('teaching' in teacher['Item']) teachingSet = teacher['Item']['teaching'] self.assertEqual(len(teachingSet), 2) # check that classes were created in classes table class1Found = False class2Found = False for classCode in teachingSet: data = {'Key': {'code': classCode}} classItem = db.getItem(data, classesTable) self.assertTrue('Item' in classItem.keys()) if (classItem['Item']['title'] == 'ENG' and classItem['Item']['department'] == 'arts' and classItem['Item']['classSection'] == '12' and classItem['Item']['description'] == 'english'): class1Found = True elif (classItem['Item']['title'] == 'PE' and classItem['Item']['department'] == 'science' and classItem['Item']['classSection'] == '1' and classItem['Item']['description'] == 'physical education'): class2Found = True self.assertTrue(class1Found) self.assertTrue(class2Found)
def create_class(): status = 200 role = g.authenticatedUser['userRole'] if role != "teacher" and role != "admin" : res = ResponseCreation.ControllerResponse() res.addError('Role error', 'Only teachers can create classes') status = 403 else: dynamoDBInstance = getDatabaseClient() res = class_ctrl.createClass(dynamoDBInstance, request.json) if res.hasErrors(): status = 400 return ResponseCreation.createResponse(res, status)
def test_createClassWrongRole(self): print('Running creatClassWrongRole test case') classData = { 'title': 'LING', 'department': 'science', 'section': '44', 'description': 'Linguistics' } email = '*****@*****.**' userRole = 'student' response = class_ctrl.createClass(dynamodb, classData, email, userRole) # check response message self.assertTrue(response.hasErrors) #check that user does not have teaching list usersTable = db.getTable('users', dynamodb) data = {'Key': {'email': email}} teacher = db.getItem(data, usersTable) self.assertTrue('Item' in teacher.keys()) self.assertFalse('teaching' in teacher['Item'])
def test_createClass(self): print('Running creatClass test case') classData = { 'title': 'PSY', 'department': 'science', 'section': '25', 'description': 'How our brain works' } email = '*****@*****.**' userRole = 'teacher' response = class_ctrl.createClass(dynamodb, classData, email, userRole) # check response message self.assertEqual(response.payload, {'Success': 'Class Created'}) # check that teaching set was added to user classesTable = db.getTable('classes', dynamodb) usersTable = db.getTable('users', dynamodb) data = {'Key': {'email': email}} teacher = db.getItem(data, usersTable) self.assertTrue('Item' in teacher.keys()) self.assertTrue('teaching' in teacher['Item']) teachingList = list(teacher['Item']['teaching']) # check that class was created in classes table classCode = str(teachingList[0]) data = {'Key': {'code': classCode}} classItem = db.getItem(data, classesTable) self.assertTrue('Item' in classItem.keys()) self.assertEqual(classItem['Item']['title'], 'PSY') self.assertEqual(classItem['Item']['department'], 'science') self.assertEqual(classItem['Item']['classSection'], '25') self.assertEqual(classItem['Item']['description'], 'How our brain works')