def submit_add(): form = AddBookForm() if form.validate_on_submit(): add_book(lookup_isbn(form.isbn.data)) flash('ISBN saved {}'.format(form.isbn.data)) form.isbn.data = None return render_template('add.html', form=form), 200
def add_book(): if request.method == "GET": return render_template("add_book.html") else: name = request.form["name"] length = request.form["length"] publication_year = request.form["publication_year"] author = request.form["author"] # Tarkistetaan vielä onko käyttäjä admin if not users.privileges: return render_template("error.html", message="Sä et ole admin??") books.add_book(name, length, publication_year, author) return render_template("add_book.html", message="Lisätty", last_log=users.last_log(id))
def run(self): print("Updating library...") with utilities.Chdir(self.directory): subprocess.check_call(["git", "fetch", "origin"]) subprocess.check_call( ["git", "rebase", "--autostash", "origin/main"]) new_book_path = None while True: try: new_book_path = interactive_books(directory=self.directory, selected_path=new_book_path) except AddBookInterrupt: new_book_path = books.add_book( directory=self.directory, search_callback=googlebooks.search) except ExitInterrupt: answer = input("Save? [Y/n] ") if answer.lower() == "y" or answer == "": print("Saving...") with utilities.Chdir(self.directory): subprocess.check_call(["git", "add", "."]) subprocess.check_call( ["git", "commit", "-m", "Updating reading list"]) subprocess.check_call(["git", "push"]) exit(0)
def test_add_book_basic(mocked_client): returned = books.add_book(MINIMAL) assert returned['title'] == MINIMAL['first']['title'] assert MINIMAL['first']['url'].endswith(returned['url']) assert 'http' not in returned['url'] mocked_client.key.assert_called_once_with('Book', '6666666666') mocked_client.put.assert_called_once_with(ANY)
def test_add_book_with_isbn_13(mocked_client): input = MINIMAL input['first']['identifiers'].update({'isbn_13': ['9871234567890']}) returned = books.add_book(input) assert returned['isbn13'] == '9871234567890' mocked_client.key.assert_called_once_with('Book', '6666666666') mocked_client.put.assert_called_once_with(ANY)
def test_add_book_with_subtitle(mocked_client): input = MINIMAL input['first'].update({'subtitle': 'the subtext returns'}) returned = books.add_book(input) assert returned['subtitle'] == 'the subtext returns' mocked_client.key.assert_called_once_with('Book', '6666666666') mocked_client.put.assert_called_once_with(ANY)
def test_add_book_with_authors(mocked_client): input = MINIMAL input['first'].update({ 'authors': [{ 'name': 'Some Juan', 'url': 'https://openlibrary.org/authors/6666666666/Some_Juan' }] }) returned = books.add_book(input) assert returned['authors'] == ['Some Juan'] mocked_client.key.assert_called_once_with('Book', '6666666666') mocked_client.put.assert_called_once_with(ANY)
def test_add_book_with_covers(mocked_client): input = MINIMAL input['first'].update({ 'cover': { 'large': 'https://covers.openlibrary.org/b/id/123456-L.jpg', 'medium': 'https://covers.openlibrary.org/b/id/123456-M.jpg', 'small': 'https://covers.openlibrary.org/b/id/123456-S.jpg' } }) returned = books.add_book(input) assert 3 == len(returned['covers']) assert 'covers.openlibrary.org/b/id/123456-M.jpg' in returned['covers'] mocked_client.key.assert_called_once_with('Book', '6666666666') mocked_client.put.assert_called_once_with(ANY)
def test_add_book_with_subjects(mocked_client): input = MINIMAL input['first'].update({ 'subjects': [{ 'name': 'Being Smart', 'url': 'https://openlibrary.org/subjects/being_smart' }, { 'name': 'Getting Good Grades', 'url': 'https://openlibrary.org/subjects/getting_good_grades' }] }) returned = books.add_book(input) assert 'Being Smart' in returned['subjects'] assert 'Getting Good Grades' in returned['subjects'] mocked_client.key.assert_called_once_with('Book', '6666666666') mocked_client.put.assert_called_once_with(ANY)
def POST(self, name): if name: return add_book(name) else: raise web.badrequest()