def test_add_item_to_inventory_that_we_dont_have_returns_object(self):
     random_item=random.sample(list(Book.selectBy(status='STOCK')), 1)[0]
     fakeargs=dict(title=random_item.title.booktitle, authors=random_item.title.authors_as_string(), publisher=random_item.title.publisher, distributor=random_item.distributor, owner='woodenshoe', listprice=random_item.listprice, ourprice=random_item.ourprice, isbn=random_item.title.isbn, categories=random_item.title.categories_as_string(), location=random_item.location, quantity=1, known_title=True, types=random_item.title.type, kind_name=random_item.title.kind.kindName)
     response=self._my_app.post('/admin/add_item_to_inventory', fakeargs)
     today=mx.DateTime.now().strftime('%Y-%m-%d')
     confirm=Book.selectBy(titleID=random_item.titleID).filter('inventoried_when=%s' % today)
     self.assertTrue(confirm, "test_add_item_to_inventory does not add item to inventory")
 def test_addToInventory_have_title(self):
     random_item=random.sample(list(Book.selectBy(status='STOCK')), 1)[0]
     fakeargs=dict(title=random_item.title.booktitle, authors=random_item.title.authors_as_string(), publisher=random_item.title.publisher, distributor=random_item.distributor, owner='woodenshoe', listprice=random_item.listprice, ourprice=random_item.ourprice, isbn=random_item.title.isbn, categories=random_item.title.categories_as_string(), location=random_item.location.locationName, quantity=1, known_title=True, types=random_item.title.type, kind_name=random_item.title.kind.kindName)
     inventory.addToInventory( **fakeargs )
     today=mx.DateTime.now().strftime('%Y-%m-%d')
     confirm=Book.selectBy(titleID=random_item.titleID).filter( Book.q.inventoried_when == today)
     try:
         self.assertTrue(confirm, "inventory.addToInventory of title that we have does not add item to inventory")
     finally:
         print "confirm: ", list(confirm), confirm[-1]
         confirm[-1].destroySelf()
 def test_check_out_sells_book(self):
     random_item=random.sample(list(Book.selectBy(status='STOCK')), 1)[0]
     item={"department":"Book","isInventoried":"True","isTaxable":"True","booktitle":random_item.title.booktitle,"isbn":random_item.title.isbn,"bookID":random_item.id,"titleID":random_item.titleID,"ourprice":random_item.ourprice}
     self._my_app.post('/register/add_item_to_cart', {'item':json.dumps(item)})
     self._my_app.post('/register/check_out')
     confirm=random_item.status
     self.assertEqual(confirm, 'SOLD', '/register/checkout failed mark book \'SOLD\'')
 def test_remove_item_from_cart_functional(self):
     random_item=random.sample(list(Book.selectBy(status='STOCK')), 1)[0]
     item={"department":"Book","isInventoried":"True","isTaxable":"True","booktitle":random_item.title.booktitle,"isbn":random_item.title.isbn,"bookID":random_item.id,"titleID":random_item.titleID,"ourprice":random_item.ourprice}
     self._my_app.post('/register/add_item_to_cart', {'item':json.dumps(item)})
     self._my_app.post('/register/remove_item_from_cart', {'index':0})
     confirm=self._my_app.get('/register/get_cart').json[0]['items']
     self.assertEqual(confirm, [], "/register/remove_item_from_cart failed.")
 def test_void_cart(self):
     random_item_list=random.sample(list(Book.selectBy(status='STOCK')), 3)
     for random_item in random_item_list:
         item={"department":"Book","isInventoried":"True","isTaxable":"True","booktitle":random_item.title.booktitle,"isbn":random_item.title.isbn,"bookID":random_item.id,"titleID":random_item.titleID,"ourprice":random_item.ourprice}
         self._my_app.post('/register/add_item_to_cart', {'item':json.dumps(item)})
     self._my_app.post('/register/void_cart')
     confirm=self._my_app.get('/register/get_cart').json[0]
     self.assertEqual(confirm, {}, '/register/void_cart failed to destroy cart')
 def test_add_item_to_cart_functional(self):
     random_item=random.sample(list(Book.selectBy(status='STOCK')), 1)[0]
     item={"department":"Book","isInventoried":"True","isTaxable":"True","booktitle":random_item.title.booktitle,"isbn":random_item.title.isbn,"bookID":random_item.id,"titleID":random_item.titleID,"ourprice":random_item.ourprice}
     result=self._my_app.post('/register/add_item_to_cart', {'item':json.dumps(item)})
     confirm=self._my_app.get('/register/get_cart')
     print "confirm is", confirm
     print "test_add_inventoried", confirm.json[0]['items'][0]
     confirm=confirm.json[0]['items'][0]
     self.assertEqual(item, confirm, '/register/add_item_to_cart returned error in function test')
 def test_check_out_records_transaction(self):
     random_item=random.sample(list(Book.selectBy(status='STOCK')), 1)[0]
     item={"department":"Book","isInventoried":"True","isTaxable":"True","booktitle":random_item.title.booktitle,"isbn":random_item.title.isbn,"bookID":random_item.id,"titleID":random_item.titleID,"ourprice":random_item.ourprice}
     self._my_app.post('/register/add_item_to_cart', {'item':json.dumps(item)})
     cart_id=self._my_app.get('/register/get_cart').json[0]['uuid']        
     self._my_app.post('/register/check_out')
     transaction=Transaction.selectBy(cartID=cart_id)
     #print transaction
     self.assertEqual('SOLD', 'SOLD', '/register/checkout failed mark book \'SOLD\'')
Example #8
0
 def test_add_item_to_cart_unit(self):
     random_item = random.sample(list(Book.selectBy(status="STOCK")), 1)[0]
     args = {
         "item": {
             "department": "Book",
             "isInventoried": "True",
             "isTaxable": "True",
             "booktitle": random_item.title.booktitle,
             "isbn": random_item.title.isbn,
             "bookID": random_item.id,
             "titleID": random_item.titleID,
             "ourprice": random_item.ourprice,
         }
     }
     result = self._my_class.add_item_to_cart(**args)
     self.assertTrue(
         result, "/register/add_item_to_cart returned error in unittest")
Example #9
0
 def test_remove_item_from_cart_functional(self):
     random_item = random.sample(list(Book.selectBy(status="STOCK")), 1)[0]
     item = {
         "department": "Book",
         "isInventoried": "True",
         "isTaxable": "True",
         "booktitle": random_item.title.booktitle,
         "isbn": random_item.title.isbn,
         "bookID": random_item.id,
         "titleID": random_item.titleID,
         "ourprice": random_item.ourprice,
     }
     self._my_app.post("/register/add_item_to_cart",
                       {"item": json.dumps(item)})
     self._my_app.post("/register/remove_item_from_cart", {"index": 0})
     confirm = self._my_app.get("/register/get_cart").json[0]["items"]
     self.assertEqual(confirm, [],
                      "/register/remove_item_from_cart failed.")
Example #10
0
 def test_check_out_sells_book(self):
     random_item = random.sample(list(Book.selectBy(status="STOCK")), 1)[0]
     item = {
         "department": "Book",
         "isInventoried": "True",
         "isTaxable": "True",
         "booktitle": random_item.title.booktitle,
         "isbn": random_item.title.isbn,
         "bookID": random_item.id,
         "titleID": random_item.titleID,
         "ourprice": random_item.ourprice,
     }
     self._my_app.post("/register/add_item_to_cart",
                       {"item": json.dumps(item)})
     self._my_app.post("/register/check_out")
     confirm = random_item.status
     self.assertEqual(confirm, "SOLD",
                      "/register/checkout failed mark book 'SOLD'")
Example #11
0
 def test_void_cart(self):
     random_item_list = random.sample(list(Book.selectBy(status="STOCK")),
                                      3)
     for random_item in random_item_list:
         item = {
             "department": "Book",
             "isInventoried": "True",
             "isTaxable": "True",
             "booktitle": random_item.title.booktitle,
             "isbn": random_item.title.isbn,
             "bookID": random_item.id,
             "titleID": random_item.titleID,
             "ourprice": random_item.ourprice,
         }
         self._my_app.post("/register/add_item_to_cart",
                           {"item": json.dumps(item)})
     self._my_app.post("/register/void_cart")
     confirm = self._my_app.get("/register/get_cart").json[0]
     self.assertEqual(confirm, {},
                      "/register/void_cart failed to destroy cart")
Example #12
0
 def test_check_out_records_transaction(self):
     random_item = random.sample(list(Book.selectBy(status="STOCK")), 1)[0]
     item = {
         "department": "Book",
         "isInventoried": "True",
         "isTaxable": "True",
         "booktitle": random_item.title.booktitle,
         "isbn": random_item.title.isbn,
         "bookID": random_item.id,
         "titleID": random_item.titleID,
         "ourprice": random_item.ourprice,
     }
     self._my_app.post("/register/add_item_to_cart",
                       {"item": json.dumps(item)})
     cart_id = self._my_app.get("/register/get_cart").json[0]["uuid"]
     self._my_app.post("/register/check_out")
     transaction = Transaction.selectBy(cartID=cart_id)
     # print transaction
     self.assertEqual("SOLD", "SOLD",
                      "/register/checkout failed mark book 'SOLD'")
Example #13
0
 def test_add_item_to_cart_functional(self):
     random_item = random.sample(list(Book.selectBy(status="STOCK")), 1)[0]
     item = {
         "department": "Book",
         "isInventoried": "True",
         "isTaxable": "True",
         "booktitle": random_item.title.booktitle,
         "isbn": random_item.title.isbn,
         "bookID": random_item.id,
         "titleID": random_item.titleID,
         "ourprice": random_item.ourprice,
     }
     result = self._my_app.post("/register/add_item_to_cart",
                                {"item": json.dumps(item)})
     confirm = self._my_app.get("/register/get_cart")
     print(("confirm is", confirm))
     print(("test_add_inventoried", confirm.json[0]["items"][0]))
     confirm = confirm.json[0]["items"][0]
     self.assertEqual(
         item, confirm,
         "/register/add_item_to_cart returned error in function test")
 def test_add_item_to_cart_unit(self):
     random_item=random.sample(list(Book.selectBy(status='STOCK')), 1)[0]
     args={'item':{"department":"Book","isInventoried":"True","isTaxable":"True","booktitle":random_item.title.booktitle,"isbn":random_item.title.isbn,"bookID":random_item.id,"titleID":random_item.titleID,"ourprice":random_item.ourprice}}
     result=self._my_class.add_item_to_cart(**args)
     self.assertTrue(result, '/register/add_item_to_cart returned error in unittest')
 def test_get_item_by_isbn_in_stock(self):
     random_item=random.sample(list(Book.selectBy(status='STOCK')), 1)[0]
     result=self._my_class.get_item_by_isbn(**{'isbn':random_item.title.isbn})
     #print "isbn_stock", random_item, result
     self.assertTrue(result, "/register/get_item_by_isbn does not return item when it should")
 def test_select_item_search(self):
     random_item=random.sample(list(Book.selectBy(status='STOCK')), 1)[0]
     code, error=tidylib.tidy_document(self._my_class.select_item_search(title=random_item.title.booktitle), options={'show-errors':1,'show-warnings':0})
     self.assertFalse(error, "/register/select_item_search does not return valid html page")
from wsgiapp_local import application

try:
    _my_app=webtest.TestApp(application)
except Exception as excp:
    sys.exit(0)

oldstderr=sys.stderr
oldstdout=sys.stdout

sys.stderr = sys.stdout = open(os.devnull, 'w')
random_app_urls=['/notes/noteboard', '/report?what=&begin_date=2012-01-01&end_date=2012-01-08&query_made=yes&reportname=salesreport', '/admin/kindlist']    
assertion_errcount=0
for j in range(1, 5):
    for i in range(1, 10):
        random_item=random.sample(list(Book.selectBy(status='STOCK')), 1)[0]
        item={"department":"Book","isInventoried":"True","isTaxable":"True","booktitle":random_item.title.booktitle,"isbn":random_item.title.isbn,"bookID":random_item.id,"titleID":random_item.titleID,"ourprice":random_item.ourprice}
        result=_my_app.post('/register/add_item_to_cart', {'item':json.dumps(item)})
        for k in range(0, random.randint(0,5)):
            _my_app.get(random.choice(random_app_urls))
        confirm=_my_app.get('/register/get_cart').json[0]['items']
        #print "test_add_inventoried", result, confirm
        try:
            assert i == len(confirm), '/register/add_item_to_cart dropped item'
        except:
            print >> oldstdout, i, len(confirm)
            assertion_errcount = assertion_errcount +1
    _my_app.get('/register/void_cart')

sys.stdout=oldstdout
sys.stderr=oldstderr
except Exception as excp:
    sys.exit(0)

oldstderr = sys.stderr
oldstdout = sys.stdout

sys.stderr = sys.stdout = open(os.devnull, "w")
random_app_urls = [
    "/notes/noteboard",
    "/report?what=&begin_date=2012-01-01&end_date=2012-01-08&query_made=yes&reportname=salesreport",
    "/admin/kindlist",
]
assertion_errcount = 0
for j in range(1, 5):
    for i in range(1, 10):
        random_item = random.sample(list(Book.selectBy(status="STOCK")), 1)[0]
        item = {
            "department": "Book",
            "isInventoried": "True",
            "isTaxable": "True",
            "booktitle": random_item.title.booktitle,
            "isbn": random_item.title.isbn,
            "bookID": random_item.id,
            "titleID": random_item.titleID,
            "ourprice": random_item.ourprice,
        }
        result = _my_app.post("/register/add_item_to_cart",
                              {"item": json.dumps(item)})
        for k in range(0, random.randint(0, 5)):
            _my_app.get(random.choice(random_app_urls))
        confirm = _my_app.get("/register/get_cart").json[0]["items"]
Example #19
0
 if re.match('^[0-9]{13}$|^[0-9]{18}$', isbn):
     try:
         isbn, price = isbn[0:13], float(isbn[13, -1])
     except:
         isbn, price = isbn[0:13], 0.00
     titles = Title.selectBy(isbn=isbn)
     book = None
     if list(titles):
         for t1 in titles:
             ourprice = rlinput("price >> ", prefill=price)
             try:
                 float(ourprice)
             except:
                 continue
             books = Book.selectBy(titleID=t1.id,
                                   ourprice=float(ourprice),
                                   status='STOCK')
             if list(books):
                 ourprice = books[0].ourprice
                 listprice = books[0].listprice
                 book = books[0]
                 break
         if not book:
             listprice = Book.selectBy(titleID=t1.id).max(Book.q.listprice)
             book = Book(title=t1,
                         status='STOCK',
                         location=1,
                         owner='woodenshoe',
                         listprice=float(listprice),
                         ourprice=float(ourprice),
                         consignmentStatus='',