class DatabaseInterfaceTest(unittest.TestCase): def setUp(self): self.con = Connection(":memory:", ":memory:") def tearDown(self): self.con.close() def testWriteStudent(self): courses = [] courses.append(Course("CSC", 110, "PROGRAMMING", 1.50, "A+", 9)) courses.append(Course("MATH", 100, "CALCULUS:I", 1.50, "A+", 9)) term = Term("WINTER", 2008, 2009, courses) terms = [term] student = Student("Bob", "V00123456", terms, REQ_SATISFIED, 3.5, "y") write_student(student, self.con) cur = self.con.get_main_con().cursor() cur.execute("SELECT COUNT(*) AS count FROM Students") studentCount = int(cur.fetchone()["count"]) self.assertEqual(studentCount, 1) cur.execute("SELECT sid, currCumulativeGpa, englishReq FROM Students") fetch = cur.fetchone() currCumulativeGpa = float(fetch["currCumulativeGpa"]) englishReq = fetch["englishReq"] self.assertEqual(currCumulativeGpa, 3.5) self.assertEqual(englishReq, REQ_SATISFIED) cur.execute("SELECT COUNT(*) AS count FROM Terms") termCount = int(cur.fetchone()["count"]) self.assertEqual(termCount, 1) cur.execute("SELECT COUNT(*) AS count FROM Courses") courseCount = int(cur.fetchone()["count"]) self.assertEqual(courseCount, 2)
def setUp(self): self.con = Connection(":memory:", ":memory:")