diff --git a/librarian/tests/utils.py b/librarian/tests/utils.py index d87c9139..d71a2b1f 100644 --- a/librarian/tests/utils.py +++ b/librarian/tests/utils.py @@ -100,14 +100,17 @@ def create_library( # Query books for their ids. Note that this bit assumes that the only books # in the DB right now are those just-created. - books = session.query(Book.id, Book.isbn).all() - isbn_id_map = {isbn: book_id for book_id, isbn in books} + books = session.query(Book).all() + isbn_book_map = {book.isbn: book for book in books} library = {} # initialize the role fields for isbn in book_isbns: - library[isbn] = {} + library[isbn] = { + "title": isbn_book_map[isbn].title, + "publisher": isbn_book_map[isbn].publisher.name + } for role in roles: library[isbn][role.name.lower()] = [] @@ -120,10 +123,6 @@ def create_library( rand_role = random.choice(roles) _role = rand_role.name.lower() - # slightly uneconomical: keep reassigning the same value, over and over - library[rand_isbn]["title"] = rand_book.title - library[rand_isbn]["publisher"] = rand_book.publisher.name - # these bits are NOT repeated library[rand_isbn][_role].append(Person(lastname=rand_person.lastname, firstname=rand_person.firstname)) @@ -139,9 +138,8 @@ def create_library( for isbn in library.keys(): book = library[isbn] book["isbn"] = isbn - book["id"] = isbn_id_map[isbn] + book["id"] = isbn_book_map[isbn].id book["genre"] = "".join((random.choice(string.ascii_lowercase) for _ in range(8))) - app.logger.info("the book %s" % str(book)) library_list.insert(0, BookRecord(**book)) return library_list diff --git a/librarian/utils.py b/librarian/utils.py index a2e54f15..297c9628 100644 --- a/librarian/utils.py +++ b/librarian/utils.py @@ -150,8 +150,6 @@ def get_bookrecord(book_id): ).filter(Book.publisher_id == BookCompany.id) .filter(Book.genre_id == Genre.id) ).first() - app.logger.info("le book %s" % str(book)) - app.logger.info("listify? %s" % str(list(book))) # <3 duck typing book = list(book) @@ -162,9 +160,9 @@ def get_bookrecord(book_id): book.insert(4, None) # Role.name book.insert(5, None) - app.logger.info("Asking to assemble %s" % book) return BookRecord.assembler((book,), as_obj=False)[0] else: + app.logger.info("Still can't find anything for %s" % book_id) return None @classmethod