Esempio n. 1
0
def add_student():
    """
    Creates a new student with an html form,
    if form is valid, the function adds the student to the student table
    """

    student_fname = request.form.get('student_fname')
    student_lname = request.form.get('student_lname')
    student_email = request.form.get('student_email')
    private_teacher_email = request.form.get('private_teacher_email')
    program_name = request.form.get('program_name')
    instrument = request.form.get('instrument')
    student_password = request.form.get('student_password')
    student_phone = request.form.get('student_phone')

    # Get the student's teacher
    teacher = crud.get_teacher_by_email(private_teacher_email)
    # What happens if the teacher doesn't exist?
    assert teacher

    student = crud.create_student(student_fname, student_lname, student_email,
                                  program_name, instrument, student_password,
                                  student_phone, teacher.teacher_id)

    if student:
        return jsonify({
            'student_fname': student_fname,
            'student_lname': student_lname,
            'student_full_name': student.full_name
        })
    else:
        return jsonify({'status': 'error, registration credentials incorrect'})
Esempio n. 2
0
def add_student():
    """
    Creates a new student with an html form,
    if form is valid, the function adds the student to the student table
    """

    print('********' * 10, 'before forms')

    student_fname = request.form.get('student_fname')
    student_lname = request.form.get('student_lname')
    student_email = request.form.get('student_email')
    private_teacher_email = request.form.get('private_teacher_email')
    program_name = request.form.get('program_name')
    instrument = request.form.get('instrument')
    student_password = request.form.get('student_password')
    student_phone = request.form.get('student_phone')

    # check if student already exists
    student = db.session.query(Student).filter(
        Student.student_email == student_email).first()

    if student:
        return jsonify({'status': 'error- email already in use'})

    # verify that teacher exists:
    teacher = crud.get_teacher_by_email(private_teacher_email)
    if not teacher:
        return ({'status': 'error- no teacher in database'})

    # create the student
    student = crud.create_student(student_fname, student_lname, student_email,
                                  program_name, instrument,
                                  hash_input(student_password), student_phone,
                                  teacher.teacher_id)
    if not student:
        return jsonify({'status': 'error-please try again'})

    return jsonify({
        'status': 'ok',
        'full_name': student.full_name,
        'email': student.student_email,
        'pw': student.student_password
    })
Esempio n. 3
0
 def test_create_student_successfully(self, mock_input):
     student = crud.create_student()
     self.assertEqual("Test Test T12345678 True", str(student).strip())
Esempio n. 4
0
 def test_create_student_invalid_grade(self, mock_input):
     with self.assertRaises(ValueError):
         crud.create_student()
Esempio n. 5
0
 def test_create_student_duplicate_student_number(self, mock_input):
     crud.add_student()
     with self.assertRaises(ValueError):
         crud.create_student()
     crud.file_write([])
Esempio n. 6
0
def create_student(student: schema.Student, db: Session = Depends(get_db)):
    return crud.create_student(db=db, student=student)