frlp-utn-ingsoft / orderingg

Aplicación utilizada en la cursada 2018 de Ingenieria de Software. UTN-FRLP
4 stars 20 forks source link

Test de integración - Prod con cantidad negativa #77

Closed Alexissiminkowich closed 6 years ago

Alexissiminkowich commented 6 years ago

Buenas tardes

Estoy trabajando con el punto 1.c de mi actividad, el de cargar un prod con cantidad negativa. Corre bien y llega al assert y da error, osea que deja cargar con cantidad negativa, le falta algo?

Logre lo siguiente:

def test_solved_BUG_of_negative_quantity(self):
        # Inicio la Orden y cargo en la BD
        o = Order(id=1)
        db.session.add(o)

        # Inicio el Producto y cargo en la BD
        p = Product(id=1, name = 'Armario', price = 800)
        db.session.add(p)

        db.session.commit()

        #Abro el browser con la URL
        driver = self.driver
        driver.get(self.baseURL)

        #Clickeo en el boton para abrir el modal
        driver.find_element_by_xpath("/html/body/main/div[1]/div/button").click()

        #Selecciono el producto
        select_prod = driver.find_element_by_id('select-prod')
        select_prod.click()
        time.sleep(2)
        selecciono = driver.find_element_by_xpath('//*[@id="select-prod"]/option[2]')
        selecciono.click()
        time.sleep(2)

        #Asigno cantidad -5 al campo cantidad
        cant = driver.find_element_by_id('quantity')
        cant.clear()
        cant.send_keys('-5')
        time.sleep(2)

        #Corroboro que se cargo el producto con cantidad negativa
        guardar = driver.find_element_by_id('save-button')
        guardar.click()
        prod = Product.query.all()
        print(prod)
        self.assertEqual(len(prod), 0, "Se pudo ingresar un producto con cantidad negativa")

El resultado me da:

Equipo@Equipo-PC MINGW32 ~/Desktop/ING DE SOFTWARE/orderingg (dev) $ pytest ============================= test session starts ============================= platform win32 -- Python 3.4.0, pytest-3.5.1, py-1.5.3, pluggy-0.6.0 rootdir: C:\Users\Equipo\Desktop\ING DE SOFTWARE\orderingg, inifile: collected 5 items

test\test_e2e.py F [ 20%] test\test_unit.py .... [100%]

================================== FAILURES =================================== ____ Ordering.test_solved_BUG_of_negative_quantity ____

self =

def test_solved_BUG_of_negative_quantity(self):
    # Inicio la Orden y cargo en la BD
    o = Order(id=1)
    db.session.add(o)

    # Inicio el Producto y cargo en la BD
    p = Product(id=1, name = 'Armario', price = 800)
    db.session.add(p)

    db.session.commit()

    #Abro el browser con la URL
    driver = self.driver
    driver.get(self.baseURL)

    #Clickeo en el boton para abrir el modal
    driver.find_element_by_xpath("/html/body/main/div[1]/div/button").click(                         )

    #Selecciono el producto
    select_prod = driver.find_element_by_id('select-prod')
    select_prod.click()
    time.sleep(2)
    selecciono = driver.find_element_by_xpath('//*[@id="select-prod"]/option                         [2]')
    selecciono.click()
    time.sleep(2)

    #Asigno cantidad -5 al campo cantidad
    cant = driver.find_element_by_id('quantity')
    cant.clear()
    cant.send_keys('-5')
    time.sleep(2)

    #Corroboro que se cargo el producto con cantidad negativa
    guardar = driver.find_element_by_id('save-button')
    guardar.click()
    prod = Product.query.all()
    print(prod)
  self.assertEqual(len(prod), 0, "Se pudo ingresar un producto con cantida                         d negativa")

E AssertionError: 1 != 0 : Se pudo ingresar un producto con cantidad negat iva

test\test_e2e.py:85: AssertionError ---------------------------- Captured stdout call ----------------------------- [Armario] ------------------------------ Captured log call ------------------------------ _internal.py 88 ERROR Error on request: Traceback (most recent call last): File "C:\Python34\lib\site-packages\werkzeug\serving.py", line 270, in run_wsg i execute(self.server.app) File "C:\Python34\lib\site-packages\werkzeug\serving.py", line 258, in execute application_iter = app(environ, start_response) File "C:\Python34\lib\site-packages\flask\app.py", line 1997, in call return self.wsgi_app(environ, start_response) File "C:\Python34\lib\site-packages\flask\app.py", line 1985, in wsgi_app response = self.handle_exception(e) File "C:\Python34\lib\site-packages\flask\app.py", line 1540, in handle_except ion reraise(exc_type, exc_value, tb) File "C:\Python34\lib\site-packages\flask_compat.py", line 33, in reraise raise value File "C:\Python34\lib\site-packages\flask\app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "C:\Python34\lib\site-packages\flask\app.py", line 1614, in full_dispatch _request rv = self.handle_user_exception(e) File "C:\Python34\lib\site-packages\flask\app.py", line 1517, in handle_user_e xception reraise(exc_type, exc_value, tb) File "C:\Python34\lib\site-packages\flask_compat.py", line 33, in reraise raise value File "C:\Python34\lib\site-packages\flask\app.py", line 1612, in full_dispatch _request rv = self.dispatch_request() File "C:\Python34\lib\site-packages\flask\app.py", line 1598, in dispatch_requ est return self.view_functionsrule.endpoint File "C:\Users\Equipo\Desktop\ING DE SOFTWARE\orderingg\app\routes.py", line 6 1, in addProductToOrder order = Order.query.get(pk) File "C:\Python34\lib\site-packages\sqlalchemy\orm\query.py", line 882, in get ident, loading.load_on_pk_identity) File "C:\Python34\lib\site-packages\sqlalchemy\orm\query.py", line 952, in _ge t_impl return db_load_fn(self, primary_key_identity) File "C:\Python34\lib\site-packages\sqlalchemy\orm\loading.py", line 247, in l oad_on_pk_identity return q.one() File "C:\Python34\lib\site-packages\sqlalchemy\orm\query.py", line 2884, in on e ret = self.one_or_none() File "C:\Python34\lib\site-packages\sqlalchemy\orm\query.py", line 2854, in on e_or_none ret = list(self) File "C:\Python34\lib\site-packages\sqlalchemy\orm\query.py", line 2925, in iter return self._execute_and_instances(context) File "C:\Python34\lib\site-packages\sqlalchemy\orm\query.py", line 2948, in _e xecute_and_instances result = conn.execute(querycontext.statement, self._params) File "C:\Python34\lib\site-packages\sqlalchemy\engine\base.py", line 948, in e xecute return meth(self, multiparams, params) File "C:\Python34\lib\site-packages\sqlalchemy\sql\elements.py", line 269, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File "C:\Python34\lib\site-packages\sqlalchemy\engine\base.py", line 1060, in _execute_clauseelement compiled_sql, distilled_params File "C:\Python34\lib\site-packages\sqlalchemy\engine\base.py", line 1200, in _execute_context context) File "C:\Python34\lib\site-packages\sqlalchemy\engine\base.py", line 1413, in _handle_dbapi_exception exc_info File "C:\Python34\lib\site-packages\sqlalchemy\util\compat.py", line 203, in r aise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=cause) File "C:\Python34\lib\site-packages\sqlalchemy\util\compat.py", line 186, in r eraise raise value.with_traceback(tb) File "C:\Python34\lib\site-packages\sqlalchemy\engine\base.py", line 1193, in _execute_context context) File "C:\Python34\lib\site-packages\sqlalchemy\engine\default.py", line 507, i n do_execute cursor.execute(statement, parameters) sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: order [SQL: 'SELECT "order".id AS order_id \nFROM "order" \nWHERE "order".id = ?'] [p arameters: ('1',)] (Background on this error at: http://sqlalche.me/e/e3q8) ===================== 1 failed, 4 passed in 27.54 seconds =====================

RodrigoJacznik commented 6 years ago

Lo que deberías controlar es que la orden no cargue el producto. Vos estas controlando que no exista el producto.

Alexissiminkowich commented 6 years ago

Gracias! Ahi me di cuenta, cambie

prod = Product.query.all() por: prod = OrderProduct.query.all()

Ahora si, no se carga el prod, por lo que el test no da error. Faltaría algo mas?

Saludos!

RodrigoJacznik commented 6 years ago

Lo mejor es

prod = o.products

Sólo agarras los productos de la orden. Como lo hiciste vos agarra todas las filas de la tabla.

Alexissiminkowich commented 6 years ago

Ahi lo probe, gracias!!