def test_add_review_by_id(): add_book("Test Book 1", "Test Author", date_shift='+0') add_review('1', '+3') reviews = list(Review.select().join(Book, on=(Review.book == Book.id))) assert len(reviews) == 1 assert reviews[0].date_of_review == datetime.date.today( ) + datetime.timedelta(3) assert reviews[0].book.name == "Test Book 1"
def test_remove_review(): add_book("Test Book 1", "Test Author", date_shift='+0') add_review('1', '+3') reviews = list(Review.select().join(Book, on=(Review.book == Book.id))) assert len(reviews) == 1 remove_review(1) reviews_after_remove = list(Review.select().join( Book, on=(Review.book == Book.id))) assert len(reviews_after_remove) == 0
def test_list_books_to_review_multiple_reviews_short(): add_book("Test Book 1", "Test Author", date_shift='-' + str(SPACED_REPETITION_INTERVALS[3] - 5)) add_review( "Test Book 1", '-' + str((SPACED_REPETITION_INTERVALS[3] - 5) - (SPACED_REPETITION_INTERVALS[0] + 1))) add_review( "Test Book 1", '-' + str((SPACED_REPETITION_INTERVALS[3] - 5) - (SPACED_REPETITION_INTERVALS[1] + 1))) books_to_review = list_books_to_review() assert len(books_to_review) == 0
def test_list_books_to_review_with_sort_multiple_reviews(): add_book("Test Book 2", "Test Author", date_shift='-' + str(SPACED_REPETITION_INTERVALS[2])) add_review( "Test Book 2", '-' + str(SPACED_REPETITION_INTERVALS[2] - (SPACED_REPETITION_INTERVALS[0] + 2))) add_book("Test Book 1", "Test Author", date_shift='-' + str(SPACED_REPETITION_INTERVALS[0] + 5)) books_to_review = list_books_to_review() assert len(books_to_review) == 2 assert books_to_review[0].name == "Test Book 2" assert books_to_review[1].name == "Test Book 1"
def test_list_reviews(): add_book("Test Book 1", "Test Author", date_shift='+0') add_book("Test Book 2", "Test Author", date_shift='+0') add_review("Test Book 1", '-3') add_review("Test Book 1", '-3') add_review("Test Book 2", '-3') assert len( list(Review.select().join(Book, on=(Review.book == Book.id)).where( Book.name == "Test Book 1"))) == 2 assert len( list(Review.select().join(Book, on=(Review.book == Book.id)).where( Book.name == "Test Book 2"))) == 1
if __name__ == '__main__': db.connect() db.create_tables([Book, Review]) arg_parser = create_argparser() cli_args = arg_parser.parse_args() if cli_args.command == 'add-book': add_book(cli_args.name, cli_args.author, cli_args.isbn, cli_args.date_shift) elif cli_args.command == 'remove-book': remove_book(cli_args.name) elif cli_args.command == 'list-books': print_books(list_books(cli_args.order_by, cli_args.asc_or_desc)) elif cli_args.command == 'add-review': add_review(cli_args.name, cli_args.date_shift) elif cli_args.command == 'remove-review': remove_review(cli_args.id) elif cli_args.command == 'list-reviews': print_reviews(list_reviews(cli_args.order_by, cli_args.asc_or_desc)) elif cli_args.command == 'send-mail': send_mail_with_reviews() else: print("\n") print("===================") print("‖ BOOKS TO REVIEW ‖") print("===================") print_books_to_review(list_books_to_review())