def test_undo_empty(self): """ Test undoing the last transaction when there isn't one. """ # Try to undo it self.app.post('/user/john/buy', data=dict(barcode=app.config['UNDO_BARCODE']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User('john').debt() == 0.0
def test_picture(self): """ Test uploading a product picture through the admin interface. """ self.add_product(self.TESTPRODUCT1, 1) # Test the default picture with app.test_request_context(): app.preprocess_request() new_picture = streck.models.product.Product( self.TESTPRODUCT1['barcode']).picture() assert new_picture == '../img/NoneProduct.png' # Update a user rv = self.app.post('/admin/product/%s/update' % self.TESTPRODUCT1['barcode'], data=dict(picture=(StringIO(unhexlify(self.IMAGE)), 'picture.png')), buffered=True, follow_redirects=True) with app.test_request_context(): app.preprocess_request() new_picture = streck.models.product.Product( self.TESTPRODUCT1['barcode']).picture() assert new_picture != '../img/NoneProduct.png' # Compare the resulting picture rv = self.app.get('/images/%s' % new_picture) assert rv.status_code == 200
def test_create_product(self): """ Test creating products through the admin interface. """ # Create product rv = self.add_product(self.TESTPRODUCT1, 1) assert b'Produkten "%s" tillagd.' % self.TESTPRODUCT1[ 'name'] in rv.data with app.test_request_context(): app.preprocess_request() product = streck.models.product.Product( self.TESTPRODUCT1['barcode']) assert product.exists() assert product.price() == self.TESTPRODUCT1['price'] assert product.category() == (self.CATEGORIES[1]).decode('utf-8') # Create another product rv = self.add_product(self.TESTPRODUCT2, 2) assert b'Produkten "%s" tillagd.' % self.TESTPRODUCT2[ 'name'] in rv.data with app.test_request_context(): app.preprocess_request() product = streck.models.product.Product( self.TESTPRODUCT2['barcode']) assert product.exists() assert product.price() == self.TESTPRODUCT2['price'] assert product.category() == (self.CATEGORIES[2]).decode('utf-8') # Create already existing product rv = self.add_product(self.TESTPRODUCT1, 1) assert b'Produktens ID är ej unikt!' in rv.data # Create already existing product with different category rv = self.add_product(self.TESTPRODUCT1, 2) assert b'Produktens ID är ej unikt!' in rv.data
def test_create_product(self): """ Test creating products through the admin interface. """ # Create product rv = self.add_product(self.TESTPRODUCT1, 1) assert b'Produkten "%s" tillagd.' % self.TESTPRODUCT1['name'] in rv.data with app.test_request_context(): app.preprocess_request() product = streck.models.product.Product(self.TESTPRODUCT1['barcode']) assert product.exists() assert product.price() == self.TESTPRODUCT1['price'] assert product.category() == (self.CATEGORIES[1]).decode('utf-8') # Create another product rv = self.add_product(self.TESTPRODUCT2, 2) assert b'Produkten "%s" tillagd.' % self.TESTPRODUCT2['name'] in rv.data with app.test_request_context(): app.preprocess_request() product = streck.models.product.Product(self.TESTPRODUCT2['barcode']) assert product.exists() assert product.price() == self.TESTPRODUCT2['price'] assert product.category() == (self.CATEGORIES[2]).decode('utf-8') # Create already existing product rv = self.add_product(self.TESTPRODUCT1, 1) assert b'Produktens ID är ej unikt!' in rv.data # Create already existing product with different category rv = self.add_product(self.TESTPRODUCT1, 2) assert b'Produktens ID är ej unikt!' in rv.data
def setUp(self): """ Set up test case. Inserts a product and a user into the database """ GenericStreckTestCase.setUp(self) with app.test_request_context(): app.preprocess_request() streck.models.product.Product.add('0012345678905', 'The Product', 5.0, 1, '../img/NoneProduct.png') streck.models.user.User.add('john', 'User 1', '../img/NoneUser.png') streck.models.user.User.add('jane', 'User 2', '../img/NoneUser.png').disable()
def test_buy_disabled(self): """ Test buying something using a disabled user. """ # Make sure we can't buy the product self.app.post('/user/jane/buy', data=dict(barcode='0012345678905'), follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User('jane').debt() == 0.0 # Make sure it appears on the user page rv = self.app.get('/user/jane', follow_redirects=True) assert b'The Product' not in rv.data
def setUp(self): """ Set up test case. Inserts two products into the database and sets the allowed jobbmat category """ GenericStreckTestCase.setUp(self) with app.test_request_context(): app.preprocess_request() streck.models.product.Product.add(self.TESTPRODUCT_GOOD['barcode'], self.TESTPRODUCT_GOOD['name'], self.TESTPRODUCT_GOOD['price'], 2, '../img/NoneProduct.png') streck.models.product.Product.add(self.TESTPRODUCT_BAD['barcode'], self.TESTPRODUCT_BAD['name'], self.TESTPRODUCT_BAD['price'], 1, '../img/NoneProduct.png') app.config['ALLOWED_JOBBMAT_CATEGORIES'] = [(self.CATEGORIES[2]).decode('utf-8')]
def test_buy_allowed(self): """ Test booking something allowed as jobbmat. """ # Make sure we can buy the product self.app.post('/user/%s/buy' % app.config['JOBBMAT_BARCODE'], data=dict(barcode=self.TESTPRODUCT_GOOD['barcode']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User(app.config['JOBBMAT_BARCODE']).debt() == self.TESTPRODUCT_GOOD['price'] # Make sure it appears on the user page rv = self.app.get('/user/%s' % app.config['JOBBMAT_BARCODE'], follow_redirects=True) assert self.TESTPRODUCT_GOOD['name'] in rv.data
def test_remove_not_allowed(self): """ Test removing something disallowed as jobbmat. """ # Make sure we can't remove the product self.app.post('/user/%s/buy' % app.config['REMOVE_JOBBMAT_BARCODE'], data=dict(barcode=self.TESTPRODUCT_BAD['barcode']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User(app.config['JOBBMAT_BARCODE']).debt() == 0.0 # Make sure it appears on the user page rv = self.app.get('/user/%s' % app.config['JOBBMAT_BARCODE'], follow_redirects=True) assert self.TESTPRODUCT_BAD['name'] not in rv.data
def test_remove_allowed(self): """ Test removing some jobbmat. """ # Make sure we can remove the product self.app.post('/user/%s/buy' % app.config['REMOVE_JOBBMAT_BARCODE'], data=dict(barcode=self.TESTPRODUCT_GOOD['barcode']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() # Note negative sign. Removing even if there was no initial purchase is allowed by design assert streck.models.user.User(app.config['JOBBMAT_BARCODE']).debt() == -self.TESTPRODUCT_GOOD['price'] # Make sure it appears on the user page rv = self.app.get('/user/%s' % app.config['JOBBMAT_BARCODE'], follow_redirects=True) assert self.TESTPRODUCT_GOOD['name'] in rv.data
def test_create_user(self): """ Test creating users through the admin interface. """ # Create user rv = self.add_user(self.TESTUSER) assert b'Användaren "%s" tillagd.' % self.TESTUSER['name'] in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.user.User(self.TESTUSER['barcode']).exists() # Create already existing user rv = self.add_user(self.TESTUSER) assert b'Användarens ID är ej unikt!' in rv.data
def test_create_user(self): """ Test creating users through the admin interface. """ # Create user rv = self.add_user(self.TESTUSER) assert b'Användaren "%s" tillagd.' % self.TESTUSER[ 'name'] in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.user.User(self.TESTUSER['barcode']).exists() # Create already existing user rv = self.add_user(self.TESTUSER) assert b'Användarens ID är ej unikt!' in rv.data
def test_top_user_debt(self): """ Tests :meth:Stats.top_user_debt and :meth:Stats.toplist_user_now. """ self.do_transactions(20, self.U_J, self.P_A) # Jobbmat, not counted self.do_transactions(2, self.U_B, self.P_B) self.do_transactions(10, self.U_A, self.P_A) # Make sure the top user is correct with app.test_request_context(): app.preprocess_request() assert streck.models.stats.Stats.top_user_debt().id() == self.U_B.id() toplist = streck.models.stats.Stats.toplist_user_now() assert [u.id() for u in toplist] == [self.U_B.id(), self.U_A.id()] assert [u.debt() for u in toplist] == [18.0, 10.0]
def test_top_product(self): """ Tests :meth:Stats.top_product. """ self.do_transactions(20, self.U_J, self.P_A) # Jobbmat, not counted self.do_transactions(2, self.U_A, self.P_A) self.do_transactions(10, self.U_A, self.P_B) # Make sure the top product is correct with app.test_request_context(): app.preprocess_request() expect_name = self.P_B.name() top_name, count = streck.models.stats.Stats.top_product() assert top_name == expect_name assert count == 10
def test_undo_disabled(self): """ Test undoing a transaction using a disabled user. """ # Hack a product into the database so we have something to undo with app.test_request_context(): app.preprocess_request() streck.models.transaction.Transaction('jane', '0012345678905', 5.0).perform() assert streck.models.user.User('jane').debt() == 5.0 # Try to undo it self.app.post('/user/jane/buy', data=dict(barcode=app.config['UNDO_BARCODE']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User('jane').debt() == 5.0
def test_paid_disabled(self): """ Test resetting the debt of a disabled user. """ # Make sure we have a debt with app.test_request_context(): app.preprocess_request() streck.models.transaction.Transaction('jane', '0012345678905', 5.0).perform() streck.models.transaction.Transaction('jane', '0012345678905', 5.0).perform() assert streck.models.user.User('jane').debt() == 10.0 # Test paying off the debt self.app.post('/user/jane/buy', data=dict(barcode=app.config['PAID_BARCODE']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User('jane').debt() == 0.0
def test_top_user_debt(self): """ Tests :meth:Stats.top_user_debt and :meth:Stats.toplist_user_now. """ self.do_transactions(20, self.U_J, self.P_A) # Jobbmat, not counted self.do_transactions(2, self.U_B, self.P_B) self.do_transactions(10, self.U_A, self.P_A) # Make sure the top user is correct with app.test_request_context(): app.preprocess_request() assert streck.models.stats.Stats.top_user_debt().id( ) == self.U_B.id() toplist = streck.models.stats.Stats.toplist_user_now() assert [u.id() for u in toplist] == [self.U_B.id(), self.U_A.id()] assert [u.debt() for u in toplist] == [18.0, 10.0]
def setUp(self): """ Set up test case. Inserts two products, two users and some transactions """ GenericStreckTestCase.setUp(self) with app.test_request_context(): app.preprocess_request() self.P_A = streck.models.product.Product.add('BC_P_A', 'Prod. A', 1.0, 2, '') self.P_B = streck.models.product.Product.add('BC_P_B', 'Prod. B', 9.0, 1, '') self.P_N = streck.models.product.Product(None) self.U_A = streck.models.user.User.add('BC_U_A', 'User A', '') self.U_B = streck.models.user.User.add('BC_U_B', 'User B', '') self.U_J = streck.models.user.User(app.config['JOBBMAT_BARCODE'])
def test_remove_not_allowed(self): """ Test removing something disallowed as jobbmat. """ # Make sure we can't remove the product self.app.post('/user/%s/buy' % app.config['REMOVE_JOBBMAT_BARCODE'], data=dict(barcode=self.TESTPRODUCT_BAD['barcode']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User( app.config['JOBBMAT_BARCODE']).debt() == 0.0 # Make sure it appears on the user page rv = self.app.get('/user/%s' % app.config['JOBBMAT_BARCODE'], follow_redirects=True) assert self.TESTPRODUCT_BAD['name'] not in rv.data
def test_buy_allowed(self): """ Test booking something allowed as jobbmat. """ # Make sure we can buy the product self.app.post('/user/%s/buy' % app.config['JOBBMAT_BARCODE'], data=dict(barcode=self.TESTPRODUCT_GOOD['barcode']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User(app.config['JOBBMAT_BARCODE']).debt( ) == self.TESTPRODUCT_GOOD['price'] # Make sure it appears on the user page rv = self.app.get('/user/%s' % app.config['JOBBMAT_BARCODE'], follow_redirects=True) assert self.TESTPRODUCT_GOOD['name'] in rv.data
def test_remove_allowed(self): """ Test removing some jobbmat. """ # Make sure we can remove the product self.app.post('/user/%s/buy' % app.config['REMOVE_JOBBMAT_BARCODE'], data=dict(barcode=self.TESTPRODUCT_GOOD['barcode']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() # Note negative sign. Removing even if there was no initial purchase is allowed by design assert streck.models.user.User(app.config['JOBBMAT_BARCODE']).debt( ) == -self.TESTPRODUCT_GOOD['price'] # Make sure it appears on the user page rv = self.app.get('/user/%s' % app.config['JOBBMAT_BARCODE'], follow_redirects=True) assert self.TESTPRODUCT_GOOD['name'] in rv.data
def setUp(self): """ Set up test case. Inserts two products, two users and some transactions """ GenericStreckTestCase.setUp(self) with app.test_request_context(): app.preprocess_request() self.P_A = streck.models.product.Product.add( 'BC_P_A', 'Prod. A', 1.0, 2, '') self.P_B = streck.models.product.Product.add( 'BC_P_B', 'Prod. B', 9.0, 1, '') self.P_N = streck.models.product.Product(None) self.U_A = streck.models.user.User.add('BC_U_A', 'User A', '') self.U_B = streck.models.user.User.add('BC_U_B', 'User B', '') self.U_J = streck.models.user.User(app.config['JOBBMAT_BARCODE'])
def test_undo_after_paid(self): """ Test undoing a transaction when the last one was a debt reset. """ # Make sure we have a debt, and that it's paid with app.test_request_context(): app.preprocess_request() streck.models.transaction.Transaction('john', '0012345678905', 5.0).perform() streck.models.transaction.Transaction('john', '0012345678905', 5.0).perform() streck.models.transaction.Transaction('john', paid=True).perform() assert streck.models.user.User('john').last_paid_id() != -1 assert streck.models.user.User('john').debt() == 0.0 # Try to undo self.app.post('/user/john/buy', data=dict(barcode=app.config['UNDO_BARCODE']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User('john').debt() == 10.0 # by design apparently?
def test_undo(self): """ Test undoing something. """ # Hack a product into the database so we have something to undo with app.test_request_context(): app.preprocess_request() streck.models.transaction.Transaction('john', '0012345678905', 5.0).perform() assert streck.models.user.User('john').debt() == 5.0 # Make sure we can undo the transaction self.app.post('/user/john/buy', data=dict(barcode=app.config['UNDO_BARCODE']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User('john').debt() == 0.0 # Make sure it appears on the user page rv = self.app.get('/user/john', follow_redirects=True) assert b'The Product' not in rv.data
def setUp(self): """ Set up test case. Inserts two products into the database and sets the allowed jobbmat category """ GenericStreckTestCase.setUp(self) with app.test_request_context(): app.preprocess_request() streck.models.product.Product.add(self.TESTPRODUCT_GOOD['barcode'], self.TESTPRODUCT_GOOD['name'], self.TESTPRODUCT_GOOD['price'], 2, '../img/NoneProduct.png') streck.models.product.Product.add(self.TESTPRODUCT_BAD['barcode'], self.TESTPRODUCT_BAD['name'], self.TESTPRODUCT_BAD['price'], 1, '../img/NoneProduct.png') app.config['ALLOWED_JOBBMAT_CATEGORIES'] = [ (self.CATEGORIES[2]).decode('utf-8') ]
def test_update_user(self): """ Test updating users through the admin interface. """ new_user_name = 'Joe' self.add_user(self.TESTUSER) # Update a user rv = self.app.post('/admin/user/%s/update' % self.TESTUSER['barcode'], data=dict( name=new_user_name ), follow_redirects=True) assert new_user_name in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.user.User(self.TESTUSER['barcode']).name() == new_user_name # Update a nonexistent user rv = self.app.post('/admin/user/nobody/update', data=dict( name='Irrelevant' ), follow_redirects=True) assert b'Användaren existerar inte!' in rv.data
def test_update_user(self): """ Test updating users through the admin interface. """ new_user_name = 'Joe' self.add_user(self.TESTUSER) # Update a user rv = self.app.post('/admin/user/%s/update' % self.TESTUSER['barcode'], data=dict(name=new_user_name), follow_redirects=True) assert new_user_name in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.user.User( self.TESTUSER['barcode']).name() == new_user_name # Update a nonexistent user rv = self.app.post('/admin/user/nobody/update', data=dict(name='Irrelevant'), follow_redirects=True) assert b'Användaren existerar inte!' in rv.data
def test_undo_after_paid(self): """ Test undoing a transaction when the last one was a debt reset. """ # Make sure we have a debt, and that it's paid with app.test_request_context(): app.preprocess_request() streck.models.transaction.Transaction('john', '0012345678905', 5.0).perform() streck.models.transaction.Transaction('john', '0012345678905', 5.0).perform() streck.models.transaction.Transaction('john', paid=True).perform() assert streck.models.user.User('john').last_paid_id() != -1 assert streck.models.user.User('john').debt() == 0.0 # Try to undo self.app.post('/user/john/buy', data=dict(barcode=app.config['UNDO_BARCODE']), follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User( 'john').debt() == 10.0 # by design apparently?
def test_picture(self): """ Test uploading a product picture through the admin interface. """ self.add_product(self.TESTPRODUCT1, 1) # Test the default picture with app.test_request_context(): app.preprocess_request() new_picture = streck.models.product.Product(self.TESTPRODUCT1['barcode']).picture() assert new_picture == '../img/NoneProduct.png' # Update a user rv = self.app.post('/admin/product/%s/update' % self.TESTPRODUCT1['barcode'], data=dict( picture=(StringIO(unhexlify(self.IMAGE)), 'picture.png') ), buffered=True, follow_redirects=True) with app.test_request_context(): app.preprocess_request() new_picture = streck.models.product.Product(self.TESTPRODUCT1['barcode']).picture() assert new_picture != '../img/NoneProduct.png' # Compare the resulting picture rv = self.app.get('/images/%s' % new_picture) assert rv.status_code == 200
def test_top_user_total(self): """ Tests :meth:Stats.top_user_total and :meth:Stats.toplist_user_alltime. """ self.do_transactions(20, self.U_J, self.P_A) # Jobbmat, not counted self.do_transactions(2, self.U_B, self.P_A) self.do_transactions(10, self.U_A, self.P_A) # Make sure the total top user is correct with app.test_request_context(): app.preprocess_request() expect_name = self.U_A.name() top_name, total = streck.models.stats.Stats.top_user_total() assert expect_name == top_name assert total == 10.0 toplist = streck.models.stats.Stats.toplist_user_alltime() assert [v[0] for v in toplist] == [self.U_J.name(), self.U_A.name(), self.U_B.name()] assert [v[1] for v in toplist] == [20, 10, 2] assert [v[2] for v in toplist] == [20.0, 10.0, 2.0] # Make sure it's still correct after a debt payment with app.test_request_context(): app.preprocess_request() self.do_transactions(1, self.U_A, self.P_N, notes='paid', price=-self.U_A.debt()) self.do_transactions(1, self.U_B, self.P_N, notes='paid', price=-self.U_B.debt()) with app.test_request_context(): app.preprocess_request() expect_name = self.U_A.name() top_name, total = streck.models.stats.Stats.top_user_total() assert expect_name == top_name assert total == 10.0 toplist = streck.models.stats.Stats.toplist_user_alltime() assert [v[0] for v in toplist] == [self.U_J.name(), self.U_A.name(), self.U_B.name()] assert [v[1] for v in toplist] == [20, 10, 2] assert [v[2] for v in toplist] == [20.0, 10.0, 2.0] # And after more transactions self.do_transactions(10, self.U_B, self.P_A) self.do_transactions(1, self.U_A, self.P_A) with app.test_request_context(): app.preprocess_request() expect_name = self.U_B.name() top_name, total = streck.models.stats.Stats.top_user_total() assert expect_name == top_name assert total == 12.0 toplist = streck.models.stats.Stats.toplist_user_alltime() assert [v[0] for v in toplist] == [self.U_J.name(), self.U_B.name(), self.U_A.name()] assert [v[1] for v in toplist] == [20, 12, 11] assert [v[2] for v in toplist] == [20.0, 12.0, 11.0]
def test_user_disabling(self): """ Test disabling and enabling users through the admin interface. """ self.add_user(self.TESTUSER) # Disable a user rv = self.app.get('/admin/user/%s/disable' % self.TESTUSER['barcode'], follow_redirects=True) assert b'Användaren är nu avstängd!' in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.user.User(self.TESTUSER['barcode']).disabled() # Disable a user again rv = self.app.get('/admin/user/%s/disable' % self.TESTUSER['barcode'], follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User(self.TESTUSER['barcode']).disabled() # Enable a user rv = self.app.get('/admin/user/%s/enable' % self.TESTUSER['barcode'], follow_redirects=True) assert b'Användaren är inte längre avstängd!' in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.user.User(self.TESTUSER['barcode']).enabled() # Enable a user again rv = self.app.get('/admin/user/%s/enable' % self.TESTUSER['barcode'], follow_redirects=True) with app.test_request_context(): app.preprocess_request() assert streck.models.user.User(self.TESTUSER['barcode']).enabled() # Disable a nonexistent user rv = self.app.get('/admin/user/nobody/disable', follow_redirects=True) assert b'Användaren existerar inte!' in rv.data # Enable a nonexistent user rv = self.app.get('/admin/user/nobody/enable', follow_redirects=True) assert b'Användaren existerar inte!' in rv.data
def test_update_product(self): """ Test updating products through the admin interface. """ new_name = 'Cheaper Product' new_price = 0.5 self.add_product(self.TESTPRODUCT1, 1) # Update product name rv = self.app.post('/admin/product/%s/update' % self.TESTPRODUCT1['barcode'], data=dict(name=new_name), follow_redirects=True) assert new_name in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.product.Product( self.TESTPRODUCT1['barcode']).name() == new_name # Update product price rv = self.app.post('/admin/product/%s/update' % self.TESTPRODUCT1['barcode'], data=dict(price=new_price), follow_redirects=True) assert str(new_price) in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.product.Product( self.TESTPRODUCT1['barcode']).price() == new_price # Update product category rv = self.app.post('/admin/product/%s/update' % self.TESTPRODUCT1['barcode'], data=dict(category=2), follow_redirects=True) assert self.CATEGORIES[2] in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.product.Product( self.TESTPRODUCT1['barcode']).category() == ( self.CATEGORIES[2]).decode('utf-8') # Update a nonexistent product rv = self.app.post('/admin/product/nothing/update', data=dict(name='Irrelevant'), follow_redirects=True) assert b'Produkten existerar inte!' in rv.data
def test_update_product(self): """ Test updating products through the admin interface. """ new_name = 'Cheaper Product' new_price = 0.5 self.add_product(self.TESTPRODUCT1, 1) # Update product name rv = self.app.post('/admin/product/%s/update' % self.TESTPRODUCT1['barcode'], data=dict( name=new_name ), follow_redirects=True) assert new_name in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.product.Product(self.TESTPRODUCT1['barcode']).name() == new_name # Update product price rv = self.app.post('/admin/product/%s/update' % self.TESTPRODUCT1['barcode'], data=dict( price=new_price ), follow_redirects=True) assert str(new_price) in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.product.Product(self.TESTPRODUCT1['barcode']).price() == new_price # Update product category rv = self.app.post('/admin/product/%s/update' % self.TESTPRODUCT1['barcode'], data=dict( category=2 ), follow_redirects=True) assert self.CATEGORIES[2] in rv.data with app.test_request_context(): app.preprocess_request() assert streck.models.product.Product(self.TESTPRODUCT1['barcode']).category() == (self.CATEGORIES[2]).decode('utf-8') # Update a nonexistent product rv = self.app.post('/admin/product/nothing/update', data=dict( name='Irrelevant' ), follow_redirects=True) assert b'Produkten existerar inte!' in rv.data
def test_top_user_total(self): """ Tests :meth:Stats.top_user_total and :meth:Stats.toplist_user_alltime. """ self.do_transactions(20, self.U_J, self.P_A) # Jobbmat, not counted self.do_transactions(2, self.U_B, self.P_A) self.do_transactions(10, self.U_A, self.P_A) # Make sure the total top user is correct with app.test_request_context(): app.preprocess_request() expect_name = self.U_A.name() top_name, total = streck.models.stats.Stats.top_user_total() assert expect_name == top_name assert total == 10.0 toplist = streck.models.stats.Stats.toplist_user_alltime() assert [v[0] for v in toplist ] == [self.U_J.name(), self.U_A.name(), self.U_B.name()] assert [v[1] for v in toplist] == [20, 10, 2] assert [v[2] for v in toplist] == [20.0, 10.0, 2.0] # Make sure it's still correct after a debt payment with app.test_request_context(): app.preprocess_request() self.do_transactions(1, self.U_A, self.P_N, notes='paid', price=-self.U_A.debt()) self.do_transactions(1, self.U_B, self.P_N, notes='paid', price=-self.U_B.debt()) with app.test_request_context(): app.preprocess_request() expect_name = self.U_A.name() top_name, total = streck.models.stats.Stats.top_user_total() assert expect_name == top_name assert total == 10.0 toplist = streck.models.stats.Stats.toplist_user_alltime() assert [v[0] for v in toplist ] == [self.U_J.name(), self.U_A.name(), self.U_B.name()] assert [v[1] for v in toplist] == [20, 10, 2] assert [v[2] for v in toplist] == [20.0, 10.0, 2.0] # And after more transactions self.do_transactions(10, self.U_B, self.P_A) self.do_transactions(1, self.U_A, self.P_A) with app.test_request_context(): app.preprocess_request() expect_name = self.U_B.name() top_name, total = streck.models.stats.Stats.top_user_total() assert expect_name == top_name assert total == 12.0 toplist = streck.models.stats.Stats.toplist_user_alltime() assert [v[0] for v in toplist ] == [self.U_J.name(), self.U_B.name(), self.U_A.name()] assert [v[1] for v in toplist] == [20, 12, 11] assert [v[2] for v in toplist] == [20.0, 12.0, 11.0]