def test_lookup_by_orig_isbn_is_invalid(self):
     random_item = random.sample(list(Title.select("isbn RLIKE '^[0-9]{13}$'")), 1)[
         0
     ]
     wrong_isbn = random_item.isbn[0:12] + str((int(random_item.isbn[12]) + 1) % 10)
     print(random_item.isbn, wrong_isbn)
     with self.assertRaises((isbnlib.NotValidISBNError, isbnlib._exceptions.NotValidISBNError)):
         inventory.lookup_by_isbn(wrong_isbn)
 def test_lookup_by_orig_isbn_is_valid(self):
     random_item = random.sample(list(Title.select("isbn RLIKE '^[0-9]{13}$'")), 1)[
         0
     ]
     result = inventory.lookup_by_isbn(random_item.isbn)
     self.assertEqual(
         random_item.isbn,
         result["isbn"],
         "inventory.lookup_by_isbn returned wrong isbn for random isbn in database",
     )
 def test_lookup_by_isbn_is_wsr(self):
     random_item = random.sample(
         list(Title.select("isbn RLIKE 'wsr [0-9]{3,5}'")), 1
     )[0]
     result = inventory.lookup_by_isbn(random_item.isbn)
     self.assertEqual(
         random_item.isbn,
         result["isbn"],
         "inventory.lookup_by_isbn returned wrong isbn for random isbn (wsr) in database",
     )
 def test_lookup_by_orig_isbn_has_extra_hyphens(self):
     random_item = random.sample(list(Title.select("isbn RLIKE '^[0-9]{13}$'")), 1)[
         0
     ]
     prepared_isbn = (
         random_item.isbn[0:3]
         + "-"
         + random_item.isbn[3:8]
         + "-"
         + random_item.isbn[8:]
     )
     result = inventory.lookup_by_isbn(prepared_isbn)
     self.assertEqual(
         random_item.isbn,
         result["isbn"],
         "inventory.lookup_by_isbn returned wrong isbn for random isbn in database",
     )
 def test_lookup_by_isbn10_is_invalid(self):
     # translation table of checkdigits to wrong ones (digit plus 1)
     tr_table = dict(
         list(
             zip(
                 ["x", "X"] + list(map(str, list(range(9, -1, -1)))),
                 ["0", "0", "x"] + list(map(str, list(range(9, 0, -1)))),
             )
         )
     )
     random_item = random.sample(list(Title.select("isbn RLIKE '^[0-9]{13}$'")), 1)[
         0
     ]
     wrong_isbn = isbnlib.to_isbn10(random_item.isbn)
     wrong_isbn = wrong_isbn[0:9] + tr_table[wrong_isbn[9]]
     with self.assertRaises((isbnlib.NotValidISBNError, isbnlib._exceptions.NotValidISBNError)):
         result = inventory.lookup_by_isbn(wrong_isbn)
 def test_lookup_by_isbn10_dont_have(self):
     isbn_we_will_never_have = "0060723467"  # Dick Cheney's autobiography
     result = inventory.lookup_by_isbn(isbn_we_will_never_have)
     print("RESULT IS:", result)
     isbn_we_will_never_have = isbnlib.to_isbn13(isbn_we_will_never_have)
     self.assertEqual(isbn_we_will_never_have, result["isbn"])