def test_retrieving_author_by_search_text_single_letter(self): self.assertEqual(booksdatasource.authors(None, k), [{ 'id': 16, 'last_name': 'Murakami', 'first_name': 'Haruki', 'birth_year': 1949, 'death_year': NULL }, { 'id': 20, 'last_name': 'Jemisen', 'first_name': 'N.K.', 'birth_year': 1972, 'death_year': NULL }, { 'id': 21, 'last_name': 'Jerome', 'first_name': 'Jerome K.', 'birth_year': 1859, 'death_year': 1927 }, { 'id': 23, 'last_name': 'Dickens', 'first_name': 'Charles', 'birth_year': 1812, 'death_year': 1870 }])
def test_retrieving_author_by_start_year_middle_year(self): self.assertEqual(booksdatasource.authors(start_year=1949), [{ 'id': 5, 'last_name': 'Gaiman', 'first_name': 'Neil', 'birth_year': 1960, 'death_year': NULL }, { 'id': 12, 'last_name': 'Bujold', 'first_name': 'McMaster', 'birth_year': 1949, 'death_year': NULL }, { 'id': 16, 'last_name': 'Marukami', 'first_name': 'Haruki', 'birth_year': 1949, 'death_year': NULL }, { 'id': 18, 'last_name': 'Alderman', 'first_name': 'Naomi', 'birth_year': 1974, 'death_year': NULL }, { 'id': 20, 'last_name': 'Jemisen', 'first_name': 'N.K.', 'birth_year': 1972, 'death_year': NULL }])
def test_retrieving_author_multiple_input2(self): self.assertEqual( booksdatasource.authors(start_year=1930, end_year=1950), [{ 'id': 0, 'last_name': 'Willis', 'first_name': 'Connie', 'birth_year': 1945, 'death_year': NULL }, { 'id': 2, 'last_name': 'Morrison', 'first_name': 'Toni', 'birth_year': 1931, 'death_year': NULL }, { 'id': 6, 'last_name': 'Pratchett', 'first_name': 'Terry', 'birth_year': 1948, 'death_year': 2015 }, { 'id': 9, 'last_name': 'Márquez', 'first_name': 'Gabriel García', 'birth_year': 1927, 'death_year': 2014 }, { 'id': 11, 'last_name': 'Rushdie', 'first_name': 'Salman', 'birth_year': 1947, 'death_year': NULL }, { 'id': 12, 'last_name': 'Bujold', 'first_name': 'Lois McMaster', 'birth_year': 1949, 'death_year': NULL }, { 'id': 16, 'last_name': 'Murakami', 'first_name': 'Haruki', 'birth_year': 1949, 'death_year': NULL }, { 'id': 19, 'last_name': 'DuMaurie', 'first_name': 'Daphne', 'birth_year': 1907, 'death_year': 1989 }, { 'id': 24, 'last_name': 'Carré', 'first_name': 'John Le', 'birth_year': 1931, 'death_year': NULL }])
def test_retrieving_author_by_book_id_single_author_edge_case(self): self.assertEqual(booksdatasource.authors(search_text=38), [{ 'id': 20, 'last_name': 'Jemisen', 'first_name': 'N.K.', 'birth_year': 1972, 'death_year': NULL }])
def test_retrieving_author_by_end_year_earliest_year(self): self.assertEqual( booksdatasource.authors(end_year=1775), { 'id': 4, 'last_name': 'Austen', 'first_name': 'Jane', 'birth_year': 1775, 'death_year': 1817 })
def test_retrieving_author_multiple_input3(self): self.assertEqual(booksdatasource.authors(author_id=15, end_year=1848), [{ 'id': 15, 'last_name': 'Brontë', 'first_name': 'Emily', 'birth_year': 1818, 'death_year': 1848 }])
def test_retrieving_author_by_start_year_latest_year(self): self.assertEqual(booksdatasource.authors(start_year=1974), [{ 'id': 18, 'last_name': 'Alderman', 'first_name': 'Naomi', 'birth_year': 1974, 'death_year': NULL }])
def test_retrieving_author_multiple_input8(self): self.assertEqual( booksdatasource.authors(start_year=1775, end_year=1776), [{ 'id': 4, 'last_name': 'Austen', 'first_name': 'Jane', 'birth_year': 1775, 'death_year': 1817 }])
def test_retrieving_author_multiple_input1(self): self.assertEqual( booksdatasource.authors(author_id=11, start_year=1930), [{ 'id': 11, 'last_name': 'Rushdie', 'first_name': 'Salman', 'birth_year': 1947, 'death_year': NULL }])
def test_retrieving_author_by_book_id_multiple_authors_edge_case(self): self.assertEqual(booksdatasource.authors(author_id=6), [{ 'id': 5, 'last_name': 'Gaiman', 'first_name': 'Neil', 'birth_year': 1960, 'death_year': NULL }, { 'id': 6, 'last_name': 'Pratchett', 'first_name': 'Terry', 'birth_year': 1948, 'death_year': 2015 }])
def test_retrieving_author_by_end_year_middle_year(self): self.assertEqual( booksdatasource.authors(end_year=1820), { 'id': 4, 'last_name': 'Austen', 'first_name': 'Jane', 'birth_year': 1775, 'death_year': 1817 }, { 'id': 7, 'last_name': 'Brontë', 'first_name': 'Charlotte', 'birth_year': 1816, 'death_year': 1855 }, { 'id': 13, 'last_name': 'Melville', 'first_name': 'Herman', 'birth_year': 1819, 'death_year': 1891 }, { 'id': 14, 'last_name': 'Brontë', 'first_name': 'Ann', 'birth_year': 1820, 'death_year': 1849 }, { 'id': 15, 'last_name': 'Brontë', 'first_name': 'Emily', 'birth_year': 1818, 'death_year': 1848 }, { 'id': 22, 'last_name': 'Eliot', 'first_name': 'George', 'birth_year': 1819, 'death_year': 1880 }, { 'id': 23, 'last_name': 'Dickens', 'first_name': 'Charles', 'birth_year': 1812, 'death_year': 1870 })
def test_retrieving_author_by_search_text_same_last_name3(self): self.assertEqual(booksdatasource.authors(search_text=brontë), [{ 'id': 7, 'last_name': 'Brontë', 'first_name': 'Charlotte', 'birth_year': 1816, 'death_year': 1855 }, { 'id': 14, 'last_name': 'Brontë', 'first_name': 'Ann', 'birth_year': 1820, 'death_year': 1849 }, { 'id': 15, 'last_name': 'Brontë', 'first_name': 'Emily', 'birth_year': 1818, 'death_year': 1848 }])
import booksdatasource import unittest booksdatasource = booksdatasource.BooksDataSource("books.csv", "authors.csv", "books_authors.csv") #print(booksdatasource.authors()) print(booksdatasource.authors(sort_by="last_name")) #print(booksdatasource.authors(book_id=0, search_text='Willis',start_year=1900, end_year=3000)) # print(booksdatasource.book(4)) # print(booksdatasource.author(4)) # print(booksdatasource.books(author_id=3)) # print(booksdatasource.authors(end_year=1900, sort_by="birth_year")) # author_connie_willis = {'id': 0, 'last_name': 'Willis', 'first_name': 'Connie', # 'birth_year': 1945, 'death_year': None} # print(book == author_connie_willis) # class BooksDataSourceTest(unittest.TestCase): # def setUp(self): # self.booksdatasource = booksdatasource.BooksDataSource("test_books.csv", "test_authors.csv", "test_books_authors.csv") # # def tearDown(self): # pass # # def test_authors_all_args(self): # author_connie_willis = [{'id': 0, 'last_name': 'Willis', 'first_name': 'Connie', 'birth_year': 1945, 'death_year': None}] # self.assertEqual(self.booksdatasource.authors(book_id=0, search_text='Willis', start_year=1900, end_year=3000), author_connie_willis) #
def test_retrieving_author_multiple_input5(self): elf.assertEqual(booksdatasource.authors(end_year=1600), [])
def test_retrieving_author_multiple_input4(self): self.assertEqual( booksdatasource.authors(author_id=15, start_year=2000), [])
def test_retrieving_author_by_start_year_too_late(self): self.assertEqual(booksdatasource.authors(start_year=2000), [])
def test_retrieving_author_by_end_year_too_early(self): self.assertEqual(booksdatasource.authors(end_year=1700), [])