def test_add_book_category(self): prepare_db_file() db = book_category_database.BookCategoryDataBase('bcdb_test.json') self.assertFalse(db.is_book_cat_in_db("7")) bc = book_category.BookCategory("Test", "7") self.assertTrue(db.add_book_cat(bc)) self.assertTrue(db.is_book_cat_in_db("7")) remove_db_file()
def load_book_category(self): try: with open(self.load_directory, 'r') as file: # logger : loading data from file x = json.load(file) temp_dict = dict() for i in x: temp_dict[i] = bc.BookCategory(x[i]['name'], i) return temp_dict except FileNotFoundError: # logger : file does not exist return dict()
def add_category(stdscr, cat: bcb.BookCategoryDataBase): h, w = stdscr.getmaxyx() stdscr.clear() stdscr.addstr(0, w // 2 - len("Category name") // 2, "Category name") name = read_word(stdscr, h, w) cat_id = int(cat.get_max_id()) + 1 bcat = bc.BookCategory(name, str(cat_id)) if cat.add_book_cat(bcat): cat.save_book_cat() print_center(stdscr, "Success - press key to return") stdscr.getch() else: print_center(stdscr, "Error - press key to return") stdscr.getch()
def test_book_category_init(self): bc = book_category.BookCategory("TestCategory", "0") self.assertEqual(bc.name, "TestCategory") self.assertEqual(bc.id, "0")
def test_book_category_prepare_to_json(self): bc = book_category.BookCategory("TestCategory", "0") bc_str = bc.prepare_to_json() self.assertEqual(bc_str['name'], "TestCategory")