class test_Library(unittest.TestCase): def setUp(self): self.d = Library(1, 'CRUX', 'Jacob', 'Student', 'William', 'Bob', '2077-02-22', 'Croatia') def test_get_ID(self): self.assertEqual(1, self.d.get_BookID()) def test_get_BookTitle(self): self.assertEqual('CRUX', self.d.get_BookTitle())
def add(self): lbr_obj = Library(self.txtBookID.get(), self.cboBookTitle.get(), self.txtAuthor.get(), self.cboMemberType.get(), self.txtFirstName.get(), self.txtSurname.get(), self.txtDateBorrowed.get(), self.txtAddress.get()) query = 'insert into management values(%s,%s,%s,%s,%s,%s,%s,%s);' values = (lbr_obj.get_BookID(), lbr_obj.get_BookTitle(), lbr_obj.get_Author(), lbr_obj.get_MemberType(), lbr_obj.get_FirstName(), lbr_obj.get_Surname(), lbr_obj.get_DateBorrowed(), lbr_obj.get_Address()) self.dbconnect.insert(query, values) messagebox.showinfo('Success', 'Data inserted successfully') self.fetch_data() self.clear()
def update(self): lbr_obj= Library(self.txtBookID.get(),self.cboBookTitle.get(),self.txtAuthor.get(), self.cboMemberType.get(),self.txtFirstName.get(),self.txtSurname.get(), self.txtDateBorrowed.get(),self.txtAddress.get()) query='update management set BookTitle=%s,Author=%s,MemberType=%s,' \ 'FirstName=%s, Surname=%s, DateBorrowed=%s, Address=%s where BookID=%s;' values=(lbr_obj.get_BookTitle(), lbr_obj.get_Author(), lbr_obj.get_MemberType(), lbr_obj.get_FirstName(), lbr_obj.get_Surname(),lbr_obj.get_DateBorrowed(), lbr_obj.get_Address(),lbr_obj.get_BookID()) self.dbconnect.update(query, values) messagebox.showinfo('Success','Data updated successfully') self.fetch_data() self.clear()