def __init__(self): self.book_category_database = bcb.BookCategoryDataBase( 'book_category_db.json') self.user_database = ub.UserDataBase('users_db.json') self.author_database = ab.AuthorDataBase('author_db.json') self.book_database = bb.BookDataBase('book_db.json') self.history = self.load_history('history.json')
def test_add_user(self): prepare_db_file() db = users_database.UserDataBase('udb_test.json') self.assertFalse(db.is_user_in_db("7")) usr = user.User("7", "Test", "User") self.assertTrue(db.add_user(usr)) self.assertTrue(db.is_user_in_db("7")) remove_db_file()
def test_users_database_init(self): prepare_db_file() db = users_database.UserDataBase('udb_test.json') dic = ret_test_dic() for i in dic: self.assertEqual(db.user_dict[i].usr_id, i) self.assertEqual(db.user_dict[i].usr_name, dic[i]['name']) self.assertEqual(db.user_dict[i].usr_surname, dic[i]['surname']) remove_db_file()
def test_return_user_list(self): prepare_db_file() db = users_database.UserDataBase('udb_test.json') usr_list = db.return_list() temp_list = [ db.user_dict["0"].usr_name + " " + db.user_dict["0"].usr_surname, db.user_dict["1"].usr_name + " " + db.user_dict["1"].usr_surname ] self.assertEqual(usr_list, temp_list) remove_db_file()
def test_return_max_id(self): prepare_db_file() db = users_database.UserDataBase('udb_test.json') self.assertEqual("1", db.get_max_id()) remove_db_file()
def test_is_user_in_db(self): prepare_db_file() db = users_database.UserDataBase('udb_test.json') self.assertTrue(db.is_user_in_db("0")) self.assertFalse(db.is_user_in_db("7")) remove_db_file()
def test_users_database_init_no_db_file(self): remove_db_file() db = users_database.UserDataBase('udb_test.json') self.assertEqual(db.user_dict, dict())