def test21_filter_success(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book1.isbn] = self.test_book1 book_collection[self.test_book2.isbn] = self.test_book2 self.assertEqual( book_collection.filter(key='isbn')[0], self.test_book1) self.assertEqual( book_collection.filter(key='genre')[0], self.test_book2)
def test12_bookcoll_delitem_success(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book2.isbn] = self.test_book2 self.assertEqual(book_collection[self.test_book2.isbn], self.test_book2) del book_collection[self.test_book2.isbn] self.assertFalse(self.test_book2.isbn in book_collection)
def test08_bookcoll_book_collection_wrong_element_type_fail(self): books_dict = dict() books_dict[self.test_book1.isbn] = self.test_book1 books_dict[self.test_book2.isbn] = [] self.valid_bookcoll_kwargs['book_collection'] = books_dict with self.assertRaises(AssertionError): BookCollection(**self.valid_bookcoll_kwargs)
def test07_bookcoll_book_collection_non_empty_success(self): books_dict = dict() books_dict[self.test_book1.isbn] = self.test_book1 books_dict[self.test_book2.isbn] = self.test_book2 self.valid_bookcoll_kwargs['book_collection'] = books_dict book_collection = BookCollection(**self.valid_bookcoll_kwargs) self.assertEqual(book_collection[self.test_book1.isbn], self.test_book1)
def test32_load_from_xml_success(self, data): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book1.isbn] = self.test_book1 self.assertTrue(book_collection.load_from_xml())
def test30_save_to_xml_success(self, *ignore): book_collection = BookCollection(**self.valid_bookcoll_kwargs) self.assertTrue(book_collection.save_to_xml())
def test29_load_from_text_file_not_found_fail(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) self.assertFalse(book_collection.load_from_text())
def test27_save_to_text_fail(self, *ignore): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book1.isbn] = self.test_book1 self.assertFalse(book_collection.save_to_text())
def test25_parse_text_empty_fail(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) self.assertEqual(book_collection._parse_text(''), [])
def test23_parse_text_success(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) self.assertNotEqual(book_collection._parse_text(self.valid_txt), [])
def test11_bookcoll_setitem_invalid_value_type_fail(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) with self.assertRaises(AssertionError): book_collection[self.test_book2.isbn] = []
def test10_bookcoll_setitem_invalid_key_type_fail(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) with self.assertRaises(AssertionError): book_collection['1234567890'] = self.test_book2
def test09_bookcoll_setitem_isbn_13_digits_success(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[1234567890123] = self.test_book2 self.assertTrue(book_collection[1234567890123], self.test_book2)
def test09_bookcoll_setitem_success(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book2.isbn] = self.test_book2 self.assertTrue(book_collection[self.test_book2.isbn], self.test_book2)
def test08_bookcoll_book_collection_wrong_type_fail(self): books_list = [self.test_book1, self.test_book2] self.valid_bookcoll_kwargs['book_collection'] = books_list with self.assertRaises(AssertionError): BookCollection(**self.valid_bookcoll_kwargs)
def test14_bookcoll_getitem_success(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book2.isbn] = self.test_book2 self.assertEqual(book_collection[self.test_book2.isbn], self.test_book2)
def test22_filter_attr_not_found_fail(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book1.isbn] = self.test_book1 with self.assertRaises(KeyError): book_collection.filter(key='invalid')
def test15_bookcoll_getitem_keyerror_fail(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) with self.assertRaises(KeyError): item = book_collection[self.test_book2.isbn]
def test24_parse_text_parse_error_fail(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) self.assertEqual(book_collection._parse_text(self.invalid_txt), [])
def test16_bookcoll_values_success(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book1.isbn] = self.test_book1 book_collection[self.test_book2.isbn] = self.test_book2 self.assertEqual(tuple(book_collection.values()), (self.test_book1, self.test_book2))
def test26_save_to_text_success(self, io_file): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book1.isbn] = self.test_book1 self.assertTrue(book_collection.save_to_text())
def test17_bookcoll_items_success(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book1.isbn] = self.test_book1 self.assertEqual(list(book_collection.items()), [(self.test_book1.isbn, self.test_book1)])
def test28_load_from_text_success(self, *ignore): book_collection = BookCollection(**self.valid_bookcoll_kwargs) self.assertTrue(book_collection.load_from_text())
def test18_bookcoll_pop_success(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book1.isbn] = self.test_book1 self.assertEqual(book_collection.pop(self.test_book1.isbn), self.test_book1)
def test29_load_from_text_file_empty_fail(self, *ignore): book_collection = BookCollection(**self.valid_bookcoll_kwargs) self.assertFalse(book_collection.load_from_text())
def test19_bookcoll_pop_not_found_success(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) self.assertFalse(book_collection.pop(self.test_book1.isbn, None), self.test_book1)
def test31_save_to_xml_fail(self, *ignore): book_collection = BookCollection(**self.valid_bookcoll_kwargs) self.assertFalse(book_collection.save_to_xml())
def test20_bookcoll_len_success(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) book_collection[self.test_book1.isbn] = self.test_book1 self.assertEqual(len(book_collection), 1)
def test33_load_from_xml_no_file_fail(self): book_collection = BookCollection(**self.valid_bookcoll_kwargs) self.assertFalse(book_collection.load_from_xml())
def test06_bookcoll_collection_name_too_short_fail(self): self.valid_bookcoll_kwargs['collection_name'] = 'o' with self.assertRaises(AssertionError): BookCollection(**self.valid_bookcoll_kwargs)