Beispiel #1
0
    def test_create_author(self):
        author_inserted = Author(**fake_author())
        self.assertEqual(author_inserted.save(), 1)

        author_selected = Author.get(
            Author.author_id == author_inserted.author_id)
        self.assertEqual(author_inserted, author_selected)
Beispiel #2
0
    def test_create_book_with_one_author(self):
        author = Author(**fake_author())
        author.save()

        book_inserted = Book(**fake_book())
        book_inserted.authors.add(author)
        book_inserted.save()

        book_selected = Book.get(Book.book_id == book_inserted.book_id)

        self.assertEqual(book_inserted, book_selected)
        self.assertEqual(book_selected.authors[0], author)
        self.assertEqual(author.books[0], book_selected)
Beispiel #3
0
 def test_preparing_authors_from_imported_cards_with_author_duplicates(
         self):
     catalog = fake_catalog_with_author_duplicates(CATALOG_PROPER_HEADER,
                                                   10)
     self.catalog._import_cards(catalog)
     self.catalog._prepare_authors()
     self.assertLess(Author.select().count(), 10)
Beispiel #4
0
 def test_preparing_books_from_imported_cards_without_duplicates(self):
     catalog = fake_catalog(CATALOG_PROPER_HEADER, 10)
     self.catalog._import_cards(catalog)
     self.catalog._prepare_authors()
     self.catalog._prepare_books()
     self.assertEqual(Book.select().count(), 10)
     self.assertEqual(Author.select().count(), 10)
     self.assertEqual(BookAuthors.select().count(), 10)
Beispiel #5
0
 def test_preparing_index_from_imported_cards_with_author_duplicates(self):
     catalog = fake_catalog_with_author_duplicates(CATALOG_PROPER_HEADER,
                                                   10)
     self.catalog._import_cards(catalog)
     self.catalog._prepare_authors()
     self.catalog._prepare_books()
     self.catalog._prepare_card_index()
     self.assertLess(Book.select().count(), 10)
     self.assertLess(Author.select().count(), 10)
     self.assertEqual(BookAuthors.select().count(), 10)
     self.assertEqual(CardIndex.select().count(), 10)
Beispiel #6
0
    def test_create_book_with_two_authors(self):
        author1 = Author(**fake_author())
        author2 = Author(**fake_author())
        author1.save()
        author2.save()

        book_inserted = Book(**fake_book())
        book_inserted.authors.add(author1)
        book_inserted.authors.add(author2)
        book_inserted.save()

        book_selected = Book.get(Book.book_id == book_inserted.book_id)

        self.assertEqual(book_inserted, book_selected)
        self.assertEqual(list(book_selected.authors), [author1, author2])
        self.assertEqual(author1.books[0], book_selected)
        self.assertEqual(author2.books[0], book_selected)
Beispiel #7
0
 def setUp(self):
     super().setUp()
     self.books = []
     for _ in range(5):
         book = Book(book_id=fake.random.randint(100, 1000000),
                     title=fake.sentence(),
                     subtitle=fake.sentence(),
                     year=fake.random.randint(1990, 2020),
                     series=fake.sentence(),
                     language="ru")
         author = Author(author_id=fake.random.randint(100, 1000000),
                         first_name=fake.first_name(),
                         last_name=fake.last_name())
         book.authors.add(author)
     self.response = SearchResponse(self.books)