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')
import csv
from tools.inventory import inventory
from config import etc

reader=csv.reader(open('/home/woodenshoe/Documents/inventory/inventory2009/film.csv'))
writer=csv.writer(open('/home/woodenshoe/Documents/inventory/inventory2009/faulty isbns.csv', 'w'))

inv=inventory()

for isbn, location, quantity in reader:
    item=0
    try:
        item=inventory.lookup_by_isbn(isbn)
        #inventory.addToInventory(publisher=item['publisher'], price=float(str(item['list_price']).lstrip('$')), title=item['title'], categories=item['categories_as_string'].split(","), authors=item['authors'], known_title=item['known_title'], owner=etc.default_owner, status='STOCK', kind_name='film', quantity=quantity, isbn=isbn, location=location)
    except Exception:
        #print "in exception"
	#print isbn, location, quantity
	writer.writerow((isbn, location, quantity))


 def test_lookup_by_isbn13_is_invalid(self):
     random_item=random.sample(list(Title.select('isbn RLIKE \'[0-9]{9}[0-9xX]\'')), 1)[0]
     converted_isbn=isbn.convert(random_item.isbn)
     wrong_isbn=converted_isbn[0:12] + str((int(converted_isbn[12]) + 1) % 10)
     result=inventory.lookup_by_isbn(wrong_isbn)
     self.assertEqual(random_item.isbn, result['isbn'], 'inventory.lookup_by_isbn returned wrong isbn for invalid isbn13')
 def test_lookup_by_isbn13_has_extra_hyphens(self):
     random_item=random.sample(list(Title.select('isbn RLIKE \'[0-9]{9}[0-9xX]\'')), 1)[0]
     converted_isbn=isbn.convert(random_item.isbn)
     converted_isbn=converted_isbn[0:3]+'-'+converted_isbn[3:8]+'-'+converted_isbn[8:]
     result=inventory.lookup_by_isbn(converted_isbn)
     self.assertEqual(random_item.isbn, result['isbn'], 'inventory.lookup_by_isbn returned wrong isbn for random isbn in database')
 def test_lookup_by_isbn13_is_valid(self):
     random_item=random.sample(list(Title.select('isbn RLIKE \'[0-9]{9}[0-9xX]\'')), 1)[0]
     converted_isbn=isbn.convert(random_item.isbn)
     result=inventory.lookup_by_isbn(converted_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_dont_have(self):
     isbn_we_will_never_have='0060723467'      #Dick Cheney's autobiography
     result= inventory.lookup_by_isbn( isbn_we_will_never_have )
     self.assertEqual(isbn_we_will_never_have, result['isbn'] )
 def test_lookup_by_isbn10_have_it(self):
     random_item= random.sample(list(Title.select('isbn RLIKE \'[0-9]{9}[0-9xX]\'')), 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 isbn10 in database')