Exemplo 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)
Exemplo 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)
Exemplo 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)
Exemplo 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)
Exemplo 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())
Exemplo 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())
Exemplo 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())
Exemplo 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())
Exemplo n.º 9
0
 def test25_parse_text_empty_fail(self):
     book_collection = BookCollection(**self.valid_bookcoll_kwargs)
     self.assertEqual(book_collection._parse_text(''), [])
Exemplo 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), [])
Exemplo 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] = []
Exemplo 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
Exemplo 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)
Exemplo 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)
Exemplo 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)
Exemplo 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)
Exemplo 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')
Exemplo 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]
Exemplo 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), [])
Exemplo 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))
Exemplo 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())
Exemplo 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)])
Exemplo 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())
Exemplo 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)
Exemplo 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())
Exemplo 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)
Exemplo 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())
Exemplo 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)
Exemplo 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())
Exemplo 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)