Exemplo n.º 1
0
def input_data1(rootdir, engine):
    # Batches: 2015 - CS
    # Semester: 1

    with open(os.path.join(rootdir, "tests/data/data.json")) as f:
        obj = json.load(f)

    db = Session(bind=engine)

    stu_list = [
        StudentReport(Name="X", Usn=usn).dict() for (usn) in obj["usn"]
    ]
    sub_list = [
        SubjectReport(Name="X",
                      Code=code,
                      MinExt=21,
                      MinTotal=40,
                      MaxTotal=100,
                      Credits=4).dict() for (code) in obj["subcode"]
    ]
    sco_list = [
        ScoreReport(Usn=usn,
                    SubjectCode=subcode,
                    Internals=inte,
                    Externals=exte).dict()
        for (usn, subcode, inte, exte, _) in obj["scores"]
    ]

    db.bulk_insert_mappings(Student, stu_list)
    db.bulk_insert_mappings(Subject, sub_list)
    db.bulk_insert_mappings(Score, sco_list)
    db.commit()

    db.close()
Exemplo n.º 2
0
def test_student_put(client: TestClient, usn: str, rescode: int,
                     iptobj: StudentReport):
    res = client.put("/student/{}".format(usn), json=iptobj.dict())
    data = res.json()
    assert res.status_code == rescode
    if rescode == 409:
        assert data == {"detail": "{} Already Exists".format(iptobj.Usn)}
    if rescode == 404:
        assert data == {"detail": "Student Does Not Exist"}
Exemplo n.º 3
0
def input_data(engine):

    db = Session(bind=engine)

    stu_data = [
        StudentReport(Usn=usn, Name=name)
        for (usn, name) in [
            ("1CR15CS101", "X"),
            ("1CR15CS102", "X"),
            ("1CR17TE102", "X"),
            ("1CR17CS102", "X"),
        ]
    ]
    student = [x.dict() for x in stu_data]
    db.bulk_insert_mappings(Student, student)

    subect_data = [
        SubjectReport(
            Code=code, Name=name, MinExt=minext, MinTotal=mintotal, Credits=credits
        )
        for (code, name, minext, mintotal, credits) in [
            ("15CS65", "X", 21, 35, 4),
            ("15CS64", "X", 21, 35, 4),
            ("15CS54", "X", 21, 35, 4),
            ("17MAT11", "X", 21, 35, 4),
            ("17CSL76", "X", 21, 35, 2),
            ("17CS55", "X", 21, 35, 4),
        ]
    ]
    subjects = [x.dict() for x in subect_data]
    db.bulk_insert_mappings(Subject, subjects)

    score_data = [
        ScoreReport(
            Usn=usn, SubjectCode=subcode, Internals=internals, Externals=externals
        )
        for (usn, subcode, internals, externals) in [
            ("1CR15CS101", "15CS65", 12, 42),
            ("1CR15CS101", "15CS64", 16, 15),
            ("1CR15CS102", "15CS54", 19, 29),
            ("1CR17TE102", "17MAT11", 19, 55),
            ("1CR17TE102", "17CSL76", 38, 26),
            ("1CR17CS102", "17CS55", 28, 20),
        ]
    ]
    scores = [x.dict() for x in score_data]
    db.bulk_insert_mappings(Score, scores)

    db.commit()
    db.close()
Exemplo n.º 4
0
def test_put_student_bulk(db: Session):
    ins_list = [
        StudentReport(Usn=usn, Name=name) for (usn, name) in [
            ("1CR15CS001", "X"),
            ("1CR15CS002", "X2"),
            ("1CR15CS101", "X3"),
        ]
    ]

    put_student_bulk(db, ins_list)
    assert is_student_exists(db, "1CR15CS001")
    assert is_student_exists(db, "1CR15CS002")

    res = get_student(db, "1CR15CS101")
    # No Change from Conftest
    assert res.Name == "X"
Exemplo n.º 5
0
def test_bulk_student(client: TestClient):
    data = [StudentReport(Name="XS", Usn="1CR16CS001").dict()]
    res = client.post("/bulk/student", json=data)

    assert res.status_code == 201
Exemplo n.º 6
0
def test_student_report():
    rep = StudentReport(Usn="1CR15CS401", Name="Some Random Name")
    assert rep.Batch == 2014
    assert rep.Department == "CS"
Exemplo n.º 7
0
def test_update_student(db: Session, usn: str, newusn: str, expectation):
    with expectation:
        update_student(db, usn, StudentReport(Usn=newusn, Name="XX"))
Exemplo n.º 8
0
def test_put_student(db: Session, usn: str, expectation):
    with expectation:
        put_student(db, StudentReport(Usn=usn, Name="XX"))
Exemplo n.º 9
0
def test_student_post(client: TestClient, rescode: int, iptobj: StudentReport):
    res = client.post("/student/", json=iptobj.dict())
    assert res.status_code == rescode
    data = res.json()
    if rescode == 409:
        assert data == {"detail": "{} Already Exists".format(iptobj.Usn)}
Exemplo n.º 10
0
def test_student_subjectcode(client: TestClient, usn: str, subcode: str,
                             rescode: int):
    res = client.get("/student/{}/subject/{}".format(usn, subcode))
    assert res.status_code == rescode

    data = res.json()
    if rescode == 200:
        validate(data, ScoreReciept.schema())
    elif rescode == 404:
        data == {"detail": "Student Does Not Exist"}


@pytest.mark.parametrize(
    ["rescode", "iptobj"],
    [
        (201, StudentReport(Usn="1CR17CS999", Name="Rush")),
        (409, StudentReport(Usn="1CR15CS101", Name="Heck")),
    ],
)
def test_student_post(client: TestClient, rescode: int, iptobj: StudentReport):
    res = client.post("/student/", json=iptobj.dict())
    assert res.status_code == rescode
    data = res.json()
    if rescode == 409:
        assert data == {"detail": "{} Already Exists".format(iptobj.Usn)}


@pytest.mark.parametrize(
    ["usn", "rescode", "iptobj"],
    [
        ("1CR15CS101", 201, StudentReport(Usn="1CR17CS999", Name="Rush")),