예제 #1
0
파일: test_api.py 프로젝트: morav1/School
def test_course_success(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    create_course(flask_client, [str(id1), str(id2)])
예제 #2
0
파일: test_api.py 프로젝트: morav1/School
def test_duplicate_student(clean_db, flask_client):
    create_student(flask_client,
                   first_name='John',
                   second_name='Cleese',
                   email='*****@*****.**')
    res = flask_client.post(
        '/student',
        json=dict(first_name='John', second_name='Cleese', email='*****@*****.**'),
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_409_CONFLICT
예제 #3
0
파일: test_api.py 프로젝트: morav1/School
def test_add_grade(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id = create_course(flask_client, [str(id1), str(id2)])
    res = create_grade(flask_client, 70, course_id, id1)
    assert res._status_code == status.HTTP_201_CREATED
    res = create_grade(flask_client, 80, course_id, '44')
    assert res._status_code == status.HTTP_400_BAD_REQUEST
예제 #4
0
파일: test_api.py 프로젝트: morav1/School
def test_course_update(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id = create_course(flask_client, [str(id1), str(id2)])
    res = flask_client.put(
        f'/course/{course_id}',
        json=dict(name='history', students=','.join([str(id1)])),
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
예제 #5
0
파일: test_api.py 프로젝트: morav1/School
def test_delete_student(clean_db, flask_client):
    id = create_student(flask_client)
    res = flask_client.delete(
        f'/student/{id}',
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_204_NO_CONTENT
    id = create_student(flask_client)
    path = f'/student/{id+1}'
    res = flask_client.delete(
        path,
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_404_NOT_FOUND
예제 #6
0
파일: test_api.py 프로젝트: morav1/School
def test_best_student(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id = create_course(flask_client, [str(id1), str(id2)])
    create_grade(flask_client, 70, course_id, id1)
    create_grade(flask_client, 77, course_id, id2)
    res = flask_client.get(
        f'/best_student',
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
예제 #7
0
파일: test_api.py 프로젝트: morav1/School
def test_update_grade(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id = create_course(flask_client, [str(id1), str(id2)])
    res = create_grade(flask_client, 70, course_id, id1)
    assert res._status_code == status.HTTP_201_CREATED
    res = flask_client.put(
        '/grade',
        json=dict(grade=60, student=str(id1), course=course_id),
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
예제 #8
0
파일: test_api.py 프로젝트: morav1/School
def test_get_student(clean_db, flask_client):
    id = create_student(flask_client)
    res = flask_client.get(
        f'/student/{id}',
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
예제 #9
0
파일: test_api.py 프로젝트: morav1/School
def test_update_student(clean_db, flask_client):
    id = create_student(flask_client)
    res = flask_client.put(
        f'/student/{id}',
        json=dict(first_name='Jhn', second_name='Cleese', email='*****@*****.**'),
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
예제 #10
0
파일: test_api.py 프로젝트: morav1/School
def test_course_get_delete(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id = create_course(flask_client, [str(id1), str(id2)])
    res = flask_client.get(
        f'/course/{course_id}',
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
    res = flask_client.delete(
        f'/course/{course_id}',
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_204_NO_CONTENT
예제 #11
0
파일: test_api.py 프로젝트: morav1/School
def test_easy_course(clean_db, flask_client):
    id1 = create_student(flask_client)
    id2 = create_student(flask_client,
                         first_name='C',
                         second_name='D',
                         email='*****@*****.**')
    course_id1 = create_course(flask_client, [str(id1), str(id2)])
    course_id2 = create_course(flask_client, [str(id1), str(id2)],
                               name='history')
    create_grade(flask_client, 70, course_id1, id1)
    create_grade(flask_client, 77, course_id1, id2)
    create_grade(flask_client, 70, course_id2, id1)
    create_grade(flask_client, 76, course_id2, id2)
    res = flask_client.get(
        f'/easy_course',
        follow_redirects=True,
        headers={'Authorization': 'Basic ' + valid_credentials})
    assert res._status_code == status.HTTP_200_OK
    result = res.data.decode()
    course_name = json.loads(result)['name']
    assert course_name == 'history'