예제 #1
0
 def test_add_book(self):
     prepare_db_file()
     db = book_database.BookDataBase('bdb_test.json')
     self.assertFalse(db.is_book_in_db("422429"))
     bc = my_book.MyBook("2", "TestTitle", "422429", "2", )
     self.assertTrue(db.add_book(bc))
     self.assertTrue(db.is_book_in_db("422429"))
     remove_db_file()
예제 #2
0
 def test_my_book_init_default_params(self):
     bk = my_book.MyBook("0", "BooksTitle", "123456", "2")
     self.assertEqual(bk.author, "0")
     self.assertEqual(bk.title, "BooksTitle")
     self.assertEqual(bk.isbn, "123456")
     self.assertEqual(bk.category, "2")
     self.assertEqual(bk.owner, "0")
     self.assertEqual(bk.is_available, True)
예제 #3
0
 def test_my_book_prepare_to_json(self):
     bk = my_book.MyBook("0", "BooksTitle", "123456", "2")
     dic = bk.prepare_to_json()
     self.assertEqual(dic['title'], "BooksTitle")
     self.assertEqual(dic['author'], "0")
     self.assertEqual(dic['isbn'], "123456")
     self.assertEqual(dic['owner'], "0")
     self.assertEqual(dic['availability'], True)
예제 #4
0
 def test_return_dict_by_category(self):
     prepare_db_file()
     db = book_database.BookDataBase('bdb_test.json')
     bc = my_book.MyBook("2", "TestTitle", "422429", "2", )
     db.add_book(bc)
     temp_dict = dict()
     temp_dict["0"] = ["FirstTitle"]
     temp_dict["2"] = ["SecondTitle", "TestTitle"]
     cat_dict = db.return_dict_by_category()
     self.assertEqual(temp_dict, cat_dict)
     self.assertEqual(len(cat_dict["0"]), 1)
     self.assertEqual(len(cat_dict["2"]), 2)
     remove_db_file()
예제 #5
0
 def load_books(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] = my_book.MyBook(author=x[i]['author'], title=x[i]['title'], isbn=i,
                                               category=x[i]['category'], owner=x[i]['owner'],
                                               avail=x[i]['availability'])
             return temp_dict
     except FileNotFoundError:
         # logger : file does not exist
         return dict()
예제 #6
0
def add_book(stdscr, bdb: bb.BookDataBase):
    h, w = stdscr.getmaxyx()

    stdscr.clear()
    stdscr.addstr(0, w // 2 - len("Title") // 2, "Title")
    title = read_word(stdscr, h, w)
    stdscr.clear()
    stdscr.addstr(0, w // 2 - len("Isbn") // 2, "Isbn")
    isbn = read_word(stdscr, h, w)
    stdscr.clear()
    stdscr.addstr(0, w // 2 - len("Category") // 2, "Category")
    category = read_word(stdscr, h, w)
    stdscr.clear()
    stdscr.addstr(0, w // 2 - len("Author id") // 2, "Author id")
    aut_id = read_word(stdscr, h, w)
    book = bk.MyBook(aut_id, title, isbn, category)
    if bdb.add_book(book):
        bdb.save_books()
        print_center(stdscr, "Success - press key to return")
        stdscr.getch()
    else:
        print_center(stdscr, "Error - press key to return")
        stdscr.getch()