Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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())
Esempio n. 6
0
 def test30_save_to_xml_success(self, *ignore):
     book_collection = BookCollection(**self.valid_bookcoll_kwargs)
     self.assertTrue(book_collection.save_to_xml())
Esempio n. 7
0
 def test29_load_from_text_file_not_found_fail(self):
     book_collection = BookCollection(**self.valid_bookcoll_kwargs)
     self.assertFalse(book_collection.load_from_text())
Esempio n. 8
0
 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())
Esempio n. 9
0
 def test25_parse_text_empty_fail(self):
     book_collection = BookCollection(**self.valid_bookcoll_kwargs)
     self.assertEqual(book_collection._parse_text(''), [])
Esempio n. 10
0
 def test23_parse_text_success(self):
     book_collection = BookCollection(**self.valid_bookcoll_kwargs)
     self.assertNotEqual(book_collection._parse_text(self.valid_txt), [])
Esempio n. 11
0
 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] = []
Esempio n. 12
0
 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
Esempio n. 13
0
 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)
Esempio n. 14
0
 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)
Esempio n. 15
0
 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)
Esempio n. 16
0
 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)
Esempio n. 17
0
 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')
Esempio n. 18
0
 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]
Esempio n. 19
0
 def test24_parse_text_parse_error_fail(self):
     book_collection = BookCollection(**self.valid_bookcoll_kwargs)
     self.assertEqual(book_collection._parse_text(self.invalid_txt), [])
Esempio n. 20
0
 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))
Esempio n. 21
0
 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())
Esempio n. 22
0
 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)])
Esempio n. 23
0
 def test28_load_from_text_success(self, *ignore):
     book_collection = BookCollection(**self.valid_bookcoll_kwargs)
     self.assertTrue(book_collection.load_from_text())
Esempio n. 24
0
 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)
Esempio n. 25
0
 def test29_load_from_text_file_empty_fail(self, *ignore):
     book_collection = BookCollection(**self.valid_bookcoll_kwargs)
     self.assertFalse(book_collection.load_from_text())
Esempio n. 26
0
 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)
Esempio n. 27
0
 def test31_save_to_xml_fail(self, *ignore):
     book_collection = BookCollection(**self.valid_bookcoll_kwargs)
     self.assertFalse(book_collection.save_to_xml())
Esempio n. 28
0
 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)
Esempio n. 29
0
 def test33_load_from_xml_no_file_fail(self):
     book_collection = BookCollection(**self.valid_bookcoll_kwargs)
     self.assertFalse(book_collection.load_from_xml())
Esempio n. 30
0
 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)