def class_teachers(class_url): """ covered by test 0_classes / `Can get the teachers of a class`""" dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT) try: class_obj = dbw.get_class_or_error(class_url) return jsonify(teachers=class_obj["teachers"]) except ClassDoesNotExistError as e: return jsonify({"error": "class not found!", "exception": str(e)}), 404
def class_students(class_url): """ civered by test 0_classes / `Can list students in a class` """ dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT) try: class_obj = dbw.get_class_or_error(class_url) return jsonify(students=class_obj["students"]) except ClassDoesNotExistError as e: return jsonify({"error": "class not found!", "exception": str(e)}), 404
def add_student(class_url): """ covered by test 0_classes / `Student can enroll in a class` """ json_data = get_json_data() student = json_data.get("username") dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT) try: dbw.add_student_to_class(class_url, student) except ClassDoesNotExistError as e: return jsonify({"error": "class not found!", "exception": str(e)}), 404 except UserDoesNotExistError as e: return jsonify({"error": "username not found!", "exception": str(e)}), 404 return jsonify(class_updated=dbw.get_class_or_error(class_url))
def add_teacher(class_url): """ covered by test 0_classes / `Teacher can add other teachers to class they own` """ json_data = get_json_data() teacher = json_data.get("username") dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT) try: dbw.add_teacher_to_class(class_url, teacher) except ClassDoesNotExistError as e: return jsonify({"error": "class not found!", "exception": str(e)}), 404 except UserDoesNotExistError as e: return jsonify({"error": "username not found!", "exception": str(e)}), 404 return jsonify(class_updated=dbw.get_class_or_error(class_url))
def get_class(class_url): dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT) return jsonify({"class": dbw.get_class_or_error(class_url)})