def test_account8(self): ac = Account("user", "password", "Supervisor") ac.street_address = "street address" ac.email_address = "email address" ac.phone_number = "phone number" test7str = ac.__str__() self.assertEqual( test7str, "user, password, Supervisor, street address, email address, phone number" )
def add_account(self, entry: Account) -> bool: """ :param entry: a data validated Account object that will entered into the DB :return: a boolean if the process was successful """ self.__dbObject = open(self.db_path, "a+") if self.db_object is None or entry is None or not self.__isConnected: return False self.db_object.write(entry.__str__() + "\n") self.__dbObject.close() return True
def remove_account(self, entry: Account) -> bool: """ :param entry: a data validated Account object to be deleted from the DB :return: """ if not self.__isConnected: return False self.__dbObject = open(self.db_path, "r") search_entry = entry.__str__() + "\n" account_list = self.db_object.readlines() if entry is None or search_entry not in account_list: return False self.db_object.close() # The file has to be reopened in the same method to perform the write operations self.__dbObject = open(self.db_path, "a") # this truncate operation empties a file, # I can't do a line specific remove/insert self.db_object.truncate(0) for account in account_list: if account != search_entry: self.db_object.write(account.__str__() + "\n") self.db_object.close() return True