def sale(): # quantity = request.form['quantity'] # item_id = request.form['item-id'] # user_id = session['user_id'] # TODO: remove the following test parameters and uncomment the block above quantity = 1 item_id = 13591 user_id = 347980 item = ItemDB.get(item_id) user = UserDB.get(user_id) sale = SaleDB.create_quick(quantity=quantity, item_id=item_id, user_id=user_id) try: sale = SaleDB.post_sale(sale.id) except Streeplijst2Warning as err: flash(str(err)) meta_folders = FOLDERS # The folder metas for all folders are loaded to display at top of the screen return render_template('checkout.jinja2', meta_folders=meta_folders, sale=sale, item=item, user=user)
def test_post_sale_timeout(self, test_app): with test_app.app_context(): with test_app.app_context(): sale = SaleDB.create(**TEST_SALE) with pytest.raises(Timeout) as err: SaleDB.post_sale(sale.id, timeout=0.001) assert sale.status == Sale.STATUS_TIMEOUT assert str(err.value) == sale.error_msg
def test_sale_delete(self, test_app): with test_app.app_context(): sale = SaleDB.create(**TEST_SALE) assert len(SaleDB.list_all()) == 1 deleted_sale = SaleDB.delete(sale.id) assert len(SaleDB.list_all()) == 0 assert sale is deleted_sale
def test_post_sale_incorrect_item(self, test_app): with test_app.app_context(): sale = SaleDB.create(**TEST_SALE) SaleDB.update(id=sale.id, item_id=1) # Set to nonexistent item id with pytest.raises(HTTPError) as err: SaleDB.post_sale(sale.id) assert '404' in str(err.value) assert sale.status == Sale.STATUS_HTTP_ERROR assert str(err.value) == sale.error_msg
def test_get_sale(self, test_app): with test_app.app_context(): sale = SaleDB.get( 1) # This sale does not exist so this shoudl return None assert sale is None sale = SaleDB.create(**TEST_SALE) gotten_sale = SaleDB.get(sale.id) assert sale is gotten_sale
def test_sale_list_all(self, test_app): with test_app.app_context(): sale1 = SaleDB.create(**TEST_SALE) sale2 = SaleDB.create( **TEST_SALE ) # This should create a new sale, not update the current one sale_list = SaleDB.list_all() assert len(sale_list) == 2 assert sale_list[0] is sale1 and sale_list[1] is sale2
def test_create_sale_existing(self, test_app): with test_app.app_context(): sale1 = SaleDB.create(**TEST_SALE) sale2 = SaleDB.create( **TEST_SALE ) # This should create a new sale, not update the current one assert sale1 is not sale2 assert sale1.id == 1 # The ID autoincrements, starting at 1 assert sale2.id == 2 # Next ID must be 2
def test_post_sale_no_sdd(self, test_app): with test_app.app_context(): sale = SaleDB.create(**TEST_SALE) SaleDB.update( id=sale.id, user_id=TEST_USER_NO_SDD['id']) # Set to no sdd user id with pytest.raises(api.UserNotSignedException) as err: SaleDB.post_sale(sale.id) assert '403' in str(err.value) and 'mandate' in str(err.value) assert sale.status == Sale.STATUS_SDD_NOT_SIGNED assert str(err.value) == sale.error_msg
def test_sale_get_by_item_id(self, test_app): with test_app.app_context(): sale1 = SaleDB.create(**TEST_SALE) sale2 = SaleDB.create(**TEST_SALE_2) sale3 = SaleDB.create( **TEST_SALE ) # This should create a new sale, not update the first one sale_list = SaleDB.get_by_item_id(TEST_SALE['item_id']) assert len(sale_list) == 2 assert sale_list[0] is sale1 and sale_list[1] is sale3 assert sale2 not in sale_list
def test_create_sale(self, test_app): with test_app.app_context(): sale = SaleDB.create(**TEST_SALE) for (key, value) in TEST_SALE.items( ): # Make sure all fields are stored correctly assert sale.__getattribute__(key) == value assert sale.id == 1 # The ID autoincrements, starting at 1 assert sale.status == Sale.STATUS_NOT_POSTED # Test the status assert sale.api_id is None and sale.api_created is None and sale.error_msg is None # Test None fields
def test_create_quick_sale(self, test_app): with test_app.app_context(): item = ItemDB.create(**TEST_ITEM) user = UserDB.create(**TEST_USER) sale = SaleDB.create_quick(quantity=1, item_id=item.id, user_id=user.id) for (key, value) in TEST_SALE.items( ): # Make sure all fields are stored correctly assert sale.__getattribute__(key) == value assert sale.id == 1 # The ID autoincrements, starting at 1 assert sale.status == Sale.STATUS_NOT_POSTED # Test the status assert sale.api_id is None and sale.api_created is None and sale.error_msg is None # Test None fields
def test_post_sale(self, test_app): with test_app.app_context(): sale = SaleDB.create(**TEST_SALE) SaleDB.post_sale(sale.id)