def test_add_and_delete_owned_section(self): student = Student(name='test', umail_address='test', facebook_id='test', fb_auth_token='test', fb_profile_link='test', fb_picture_link='test') section2 = Section(ta='test', lecture=None, name='test', title='test', department='test', location='test', days='test', time='test', max_spots='test', space='test') section1 = Section(ta='test', lecture=None, name='test', title='test', department='test', location='test', days='test', time='test', max_spots='test', space='test') swapblock = Swapblock(student) db.session.add(student) db.session.add(section2) db.session.add(section1) db.session.add(swapblock) db.session.commit() params = {} params['student_id'] = student.id params['class_type'] = 'section' params['class_id'] = section1.id params['have_class'] = True api.add_class_to_swapblock(**params) self.assertEqual(len(student.swapblock.first().owned_sections), 1) params['class_id'] = section2.id api.add_class_to_swapblock(**params) self.assertEqual(len(student.swapblock.first().owned_sections), 2) api.delete_class_from_swapblock(**params) self.assertEqual(len(student.swapblock.first().owned_sections), 1)
def test_add_owned_lab(self): student = Student(name='test', umail_address='test', facebook_id='test', fb_auth_token='test', fb_profile_link='test', fb_picture_link='test') lab2 = Lab(instructor='test', name='test', title='test', department='test', location='test', days='test', time='test', max_spots='test', space='test') lab1 = Lab(instructor='test', name='test', title='test', department='test', location='test', days='test', time='test', max_spots='test', space='test') swapblock = Swapblock(student) db.session.add(student) db.session.add(lab2) db.session.add(lab1) db.session.add(swapblock) db.session.commit() params = {} params['student_id'] = student.id params['class_type'] = 'lab' params['class_id'] = lab2.id params['have_class'] = True api.add_class_to_swapblock(**params) self.assertEqual(len(student.swapblock.first().owned_labs), 1) params['class_id'] = lab1.id api.add_class_to_swapblock(**params) self.assertEqual(len(student.swapblock.first().owned_labs), 2) api.delete_class_from_swapblock(**params) self.assertEqual(len(student.swapblock.first().owned_labs), 1)
def test_add_and_wanted_lecture(self): student = Student(name='test', umail_address='test', facebook_id='test', fb_auth_token='test', fb_profile_link='test', fb_picture_link='test') lecture2 = Lecture(professor='test', name='test', title='test', department='test', location='test', days='test', time='test', max_spots='test', space='test') lecture1 = Lecture(professor='test', name='test', title='test', department='test', location='test', days='test', time='test', max_spots='test', space='test') swapblock = Swapblock(student) db.session.add(student) db.session.add(lecture2) db.session.add(lecture1) db.session.add(swapblock) db.session.commit() params = {} params['student_id'] = student.id params['class_type'] = 'lecture' params['class_id'] = lecture1.id params['have_class'] = False api.add_class_to_swapblock(**params) self.assertEqual(len(student.swapblock.first().wanted_lectures), 1) params['class_id'] = lecture2.id api.add_class_to_swapblock(**params) self.assertEqual(len(student.swapblock.first().wanted_lectures), 2) api.delete_class_from_swapblock(**params) self.assertEqual(len(student.swapblock.first().wanted_lectures), 1)
def delete_from_swapblock(): params = json.loads(request.form['params']) try: api.delete_class_from_swapblock(**params) except api.DbNotFoundError: abort(404) resp = jsonify(message='success!') resp.status_code = 201 return resp