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()
def test_subject_insert(client: TestClient, subcode: str, rescode: int): data = SubjectReport( Name="X", Code=subcode, MinExt=21, MinTotal=40, MaxTotal=100, Credits=4 ).dict() res = client.post("/subject/", json=data) assert res.status_code == rescode
def test_bulk_subject(client: TestClient): data = [ SubjectReport( Name="X", Code="15CS41", MinExt=21, MinTotal=40, MaxTotal=100, Credits=4 ).dict() ] res = client.post("/bulk/subject", json=data) assert res.status_code == 201
def test_put_subject_bulk(db: Session): ins_list = [ SubjectReport(Code=code, Name=name) for (code, name) in [ ("15CS81", "X"), ("15CS64", "X3"), ] # Last Shouldn't Shouldn't change ] put_subject_bulk(db, ins_list) assert is_subject_exist(db, "15CS81") res = get_subject(db, "15CS64") assert res.Name == "X"
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()
def test_subject_update( client: TestClient, subcode: str, subcodenew: str, rescode: int ): data = SubjectReport( Name="X", Code=subcodenew, MinExt=21, MinTotal=40, MaxTotal=100, Credits=4 ).dict() res = client.put("/subject/{}".format(subcode), json=data) assert res.status_code == rescode if rescode == 409: data = {"detail": "{} Already Exists".format(subcodenew)} if rescode == 404: data = {"detail": "Subject Does Not Exist"}
def test_subject_report(): rep = SubjectReport(Code="17MATDIP41", Name="Mathematics 4 DIP") assert rep.Semester == 4 assert rep.Scheme == 2017 assert rep.Department == "XX"
def test_update_student(db: Session, subcode: str, newsubcode: str, expectation) -> None: with expectation: update_subject(db, subcode, SubjectReport(Code=newsubcode, Name="EM11"))
def test_put_student(db: Session, subcode: str, expectation) -> None: with expectation: put_subject(db, SubjectReport(Code=subcode, Name="EM11"))