def setUp(self): try: self._my_class = Admin() except Exception as excp: pass try: self._my_app = webtest.TestApp(application) except: pass self._conn = tools.db.connectionForURI(tools.db.conn())
def setUp(self): try: self._my_class=Admin() except Exception as excp: pass try: self._my_app=webtest.TestApp(application) except: pass
class Test_Admin(unittest.TestCase ): def setUp(self): try: self._my_class=Admin() except Exception as excp: pass try: self._my_app=webtest.TestApp(application) except: pass def test_admin_class_instantiates(self): self.assertIsInstance(self._my_class, Admin, "Admin class did not instantiate properly") def test_kindedit_unit(self): code, error=tidylib.tidy_document(self._my_class.kindedit(), options={'show-errors':1,'show-warnings':0}) self.assertFalse(error, "method Admin.kindedit does not return valid html page") def test_kindedit_functional(self): response=self._my_app.get('/admin/kindedit') code, error=tidylib.tidy_document(response.body, options={'show-errors':1, 'show-warnings':0}) self.assertFalse(error, '/admin/kindedit did not return valid html page') def test_kindlist_unit(self): code, error=tidylib.tidy_document(self._my_class.kindlist(), options={'show-errors':1,'show-warnings':0}) self.assertFalse(error, "method Admin.kindlist does not return valid html page") def test_kindlist_functional(self): response=self._my_app.get('/admin/kindlist') code, error=tidylib.tidy_document(response.body, options={'show-errors':1, 'show-warnings':0}) self.assertFalse(error, '/admin/kindlist did not return valid html page') def test_locationedit_unit(self): code, error=tidylib.tidy_document(self._my_class.locationedit(), options={'show-errors':1,'show-warnings':0}) self.assertFalse(error, "method Admin.locationedit does not return valid html page") def test_locationedit_functional(self): response=self._my_app.get('/admin/locationedit') code, error=tidylib.tidy_document(response.body, options={'show-errors':1, 'show-warnings':0}) self.assertFalse(error, '/admin/locationedit did not return valid html page') def test_locationlist_unit(self): code, error=tidylib.tidy_document(self._my_class.locationlist(), options={'show-errors':1,'show-warnings':0}) self.assertFalse(error, "method Admin.locationlist does not return valid html page") def test_locationlist_functional(self): response=self._my_app.get('/admin/locationlist') code, error=tidylib.tidy_document(response.body, options={'show-errors':1, 'show-warnings':0}) self.assertFalse(error, '/admin/locationlist did not return valid html page') def test_add_to_inventory_unit(self): code, error=tidylib.tidy_document(self._my_class.add_to_inventory(), options={'show-errors':1,'show-warnings':0}) self.assertFalse(error, "method Admin.add_to_inventory does not return valid html page") def test_add_to_inventory_functional(self): response=self._my_app.get('/admin/add_to_inventory') code, error=tidylib.tidy_document(response.body, options={'show-errors':1, 'show-warnings':0}) self.assertFalse(error, '/admin/add_to_inventory did not return valid html page') def test_add_item_to_inventory_that_we_have_already_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_add_item_to_inventory_that_we_have_already_records_transaction(self): random_item=random.sample(list(Book.select()), 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) nowish=mx.DateTime.now().strftime('%Y-%m-%d %H:%M:%S') confirm=Transaction.select('date > %s' % nowish).filter('info RLIKE %s' % random_item.title.booktitle) self.assertTrue(confirm, "test_add_item_to_inventory does not add item to inventory") 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_add_item_to_inventory_that_we_dont_have_records_transaction(self): random_item=random.sample(list(Book.select()), 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) nowish=mx.DateTime.now().strftime('%Y-%m-%d %H:%M:%S') confirm=Transaction.select('date > %s' % nowish).filter('info RLIKE %s' % random_item.title.booktitle) self.assertTrue(confirm, "test_add_item_to_inventory does not add item to inventory") def test_search_isbn_that_we_have_unit(self): random_item=random.sample(list(Title.select()), 1)[0] result=self._my_class.search_isbn(**{'isbn':random_item.isbn})[0] self.assertEqual(result['isbn'], random_item.isbn, "method search_isbn doesn't return proper item for isbn10") def test_search_isbn_that_we_have_functional(self): random_item=random.sample(list(Title.select()), 1)[0] response=self._my_app.get('/admin/search_isbn', {'isbn':random_item.isbn}).json[0] self.assertEqual(response['isbn'], random_item.isbn, "/admin/search_isbn doesn't return proper item for isbn10") def test_search_isbn_that_we_dont_have_unit(self): random_item=random.sample(list(Title.select()), 1)[0] result=self._my_class.search_isbn(**{'isbn':random_item.isbn})[0] self.assertEqual(result['isbn'], random_item.isbn, "method search_isbn doesn't return proper item for isbn10") def test_search_isbn_that_we_dont_have_functional(self): random_item=random.sample(list(Title.select()), 1)[0] response=self._my_app.get('/admin/search_isbn', {'isbn':random_item.isbn}).json[0] self.assertEqual(response['isbn'], random_item.isbn, "/admin/search_isbn doesn't return proper item for isbn10")
from inventoryserver.server import SpecialOrders # cherrypy.config.update({'environment': 'embedded'}) if cherrypy.__version__.startswith("3.0") and cherrypy.engine.state == 0: cherrypy.engine.start(blocking=False) atexit.register(cherrypy.engine.stop) class Root(object): def index(self): return "Hello World!" index.exposed = True root = InventoryServer() root.admin = Admin() root.staffing = Staffing() root.notes = Noteboard() root.register = Register() root.specialorder = SpecialOrders() cherrypy_local_config_file = configuration.get("cherrypy_local_config_file") application = cherrypy.Application( root, script_name=None, config=cherrypy_local_config_file ) if __name__ == "__main__": cherrypy.quickstart(root, "/", cherrypy_local_config_file)
class Test_Admin(unittest.TestCase): def setUp(self): try: self._my_class = Admin() except Exception as excp: pass try: self._my_app = webtest.TestApp(application) except: pass self._conn = tools.db.connectionForURI(tools.db.conn()) def test_admin_class_instantiates(self): self.assertIsInstance(self._my_class, Admin, "Admin class did not instantiate properly") def test_kindedit_unit(self): code, error = tidylib.tidy_document(self._my_class.kindedit(), options={ "show-errors": 1, "show-warnings": 0 }) self.assertFalse( error, "method Admin.kindedit does not return valid html page") def test_kindedit_functional(self): response = self._my_app.get("/admin/kindedit") code, error = tidylib.tidy_document(response.body, options={ "show-errors": 1, "show-warnings": 0 }) self.assertFalse(error, "/admin/kindedit did not return valid html page") def test_kindlist_unit(self): code, error = tidylib.tidy_document(self._my_class.kindlist(), options={ "show-errors": 1, "show-warnings": 0 }) self.assertFalse( error, "method Admin.kindlist does not return valid html page") def test_kindlist_functional(self): response = self._my_app.get("/admin/kindlist") code, error = tidylib.tidy_document(response.body, options={ "show-errors": 1, "show-warnings": 0 }) self.assertFalse(error, "/admin/kindlist did not return valid html page") def test_locationedit_unit(self): code, error = tidylib.tidy_document( self._my_class.locationedit(), options={ "show-errors": 1, "show-warnings": 0 }, ) self.assertFalse( error, "method Admin.locationedit does not return valid html page") def test_locationedit_functional(self): response = self._my_app.get("/admin/locationedit") code, error = tidylib.tidy_document(response.body, options={ "show-errors": 1, "show-warnings": 0 }) self.assertFalse(error, "/admin/locationedit did not return valid html page") def test_locationlist_unit(self): code, error = tidylib.tidy_document( self._my_class.locationlist(), options={ "show-errors": 1, "show-warnings": 0 }, ) self.assertFalse( error, "method Admin.locationlist does not return valid html page") def test_locationlist_functional(self): response = self._my_app.get("/admin/locationlist") code, error = tidylib.tidy_document(response.body, options={ "show-errors": 1, "show-warnings": 0 }) self.assertFalse(error, "/admin/locationlist did not return valid html page") def test_get_next_unused_local_isbn(self): isbn = self._my_class.get_next_unused_local_isbn() self.assertRegex( isbn, "^199\d{10}$", "method get_next_unused_local_isbn doesn't return valid isbn", ) def test_add_to_inventory_unit(self): code, error = tidylib.tidy_document( self._my_class.add_to_inventory(), options={ "show-errors": 1, "show-warnings": 0 }, ) self.assertFalse( error, "method Admin.add_to_inventory does not return valid html page") def test_add_to_inventory_functional(self): response = self._my_app.get("/admin/add_to_inventory") code, error = tidylib.tidy_document(response.body, options={ "show-errors": 1, "show-warnings": 0 }) self.assertFalse( error, "/admin/add_to_inventory did not return valid html page") def test_add_item_to_inventory_that_we_have_already_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=random_item.title.kind.id, kind_name=random_item.title.kind.kindName, ) response = self._my_app.post("/admin/add_item_to_inventory", fakeargs) today = Now.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_add_item_to_inventory_that_we_have_already_records_transaction( self): random_item = random.sample(list(Book.select()), 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=random_item.title.kind.id, kind_name=random_item.title.kind.kindName, ) response = self._my_app.post("/admin/add_item_to_inventory", fakeargs) nowish = Now.now.strftime("%Y-%m-%d %H:%M:%S") confirm = Transaction.select("date > %s" % nowish).filter( "info RLIKE %s" % random_item.title.booktitle) self.assertTrue( confirm, "test_add_item_to_inventory does not add item to inventory") 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=random_item.title.kind.id, kind_name=random_item.title.kind.kindName, ) response = self._my_app.post("/admin/add_item_to_inventory", fakeargs) today = Now.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_add_item_to_inventory_that_we_dont_have_records_transaction(self): random_item = random.sample(list(Book.select()), 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=random_item.title.kind.id, kind_name=random_item.title.kind.kindName, ) response = self._my_app.post("/admin/add_item_to_inventory", fakeargs) nowish = Now.now.strftime("%Y-%m-%d %H:%M:%S") confirm = Transaction.select("date > %s" % nowish).filter( "info RLIKE %s" % random_item.title.booktitle) self.assertTrue( confirm, "test_add_item_to_inventory does not add item to inventory") def test_search_isbn_that_we_have_unit(self): random_item = random.sample(list(Title.select()), 1)[0] result = self._my_class.search_isbn(**{"isbn": random_item.isbn})[0] self.assertEqual( result["isbn"], random_item.isbn, "method search_isbn doesn't return proper item for isbn10", ) def test_search_isbn_that_we_have_functional(self): random_item = random.sample(list(Title.select()), 1)[0] response = self._my_app.get("/admin/search_isbn", { "isbn": random_item.isbn }).json[0] self.assertEqual( response["isbn"], random_item.isbn, "/admin/search_isbn doesn't return proper item for isbn10", ) def test_search_isbn_that_we_dont_have_unit(self): random_item = random.sample(list(Title.select()), 1)[0] result = self._my_class.search_isbn(**{"isbn": random_item.isbn})[0] print(result) self.assertEqual( result["isbn"], random_item.isbn, "method search_isbn doesn't return proper item for isbn10", ) def test_search_isbn_that_we_dont_have_functional(self): random_item = random.sample(list(Title.select()), 1)[0] response = self._my_app.get("/admin/search_isbn", { "isbn": random_item.isbn }).json[0] self.assertEqual( response["isbn"], random_item.isbn, "/admin/search_isbn doesn't return proper item for isbn10", ) def test_print_label_unit(self): random_item = random.sample( list(Title.select('WHERE title.isbn RLIKE "^978"')), 1)[0] result = self._my_class.print_label( isbn=random_item.isbn, booktitle=random_item.booktitle, authorstring=random_item.authors_as_string(), ) self.assertIsNone(result, "print_label doesn't return") def test_print_label_functional(self): random_item = random.sample( list(Title.select('WHERE title.isbn RLIKE "^978"')), 1)[0] response = self._my_app.post( "/admin/print_label", { "isbn": random_item.isbn, "booktitle": random_item.booktitle, "authorstring": random_item.authors_as_string(), }, ) print(response) self.assertIsNone(response, "print_label doesn't return") @unittest.skip("old method") def test_search_id(self): pass def test_select_item_for_isbn_search_functional(self): random_item = random.sample(list(Title.select()), 1)[0] response = self._my_app.get("/admin/select_item_for_isbn_search", {"isbn": random_item.isbn}) code, error = tidylib.tidy_document(response.body, options={ "show-errors": 1, "show-warnings": 0 }) self.assertFalse( error, "/admin/select_item_for_isbn_search did not return proper response" ) def test_select_item_for_isbn_search_unit(self): random_item = random.sample(list(Title.select()), 1)[0] code, error = tidylib.tidy_document( self._my_class.select_item_for_isbn_search( isbn=random_item.isbn, title=random_item.booktitle, author=random_item.authors_as_string(), ), options={ "show-errors": 1, "show-warnings": 0 }, ) self.assertEqual( error, "", "InventoryServer.select_item_for_isbn_search did not return proper response", )