def test_delete_user(self, test_app): with test_app.app_context(): user = UserDB.create(**TEST_USER_1) get_user = UserDB.get(TEST_USER_1['id']) assert get_user is not None # Make sure the user is retrieved deleted_user = UserDB.delete(TEST_USER_1['id']) assert user is deleted_user # Make sure the same object is referenced get_user = UserDB.get(TEST_USER_1['id']) assert get_user is None # Make sure the user is not retrieved
def create_quick(cls, quantity: int, item_id: int, user_id: int): """ Instantiate a Sale object with parameters from the database and store it in the database. :param quantity: Amount of the item to buy. :param item_id: Item ID. :param user_id: User ID. :return: The sale. """ item = ItemDB.get(item_id) user = UserDB.get(user_id) # Check if it is possible to create the sale correctly if item is None: raise NotInDatabaseException( "Item with id %d does not exist in database." % item_id) elif user is None: raise NotInDatabaseException( "User with id %d does not exist in database." % user_id) # Calculate total price and create and return the sale total_price = quantity * item.price return cls.create(quantity=quantity, total_price=total_price, item_id=item_id, item_name=item.name, user_id=user_id, user_s_number=user.s_number)
def test_get_user(self, test_app): with test_app.app_context(): user = UserDB.create(**TEST_USER_1) other_user = UserDB.get(TEST_USER_1['id']) assert user is other_user # Make sure both objects are the same instance