def test_order_by_description(db_session): db_session.add(TableShape(id=1, description="B", picture="pic")) db_session.add(TableShape(id=2, description="A", picture="pic")) db_session.commit() shapes = TableShape.query.order_by(TableShape.description).all() assert shapes[0].id == 2 assert shapes[1].id == 1
def test_filter_by_description(db_session): db_session.add(TableShape(id=1, description="B", picture="pic")) db_session.add(TableShape(id=2, description="A", picture="pic")) db_session.add(TableShape(id=3, description="BB", picture="pic")) db_session.commit() shapes = filter_by(TableShape.query, ["description=B"]).all() assert len(shapes) == 1 assert shapes[0].id == 1
def test_cannot_access_tables_from_other_locations(app, db_session): """User with Location Admin role cannot access the tables from a Location which is not owned by the company they work at""" company = Company(id=1, name="Foo Inc.", code="code1", address="addr") other = Company(id=2, name="Other Foo Inc.", code="code2", address="addr2") location = Location(id=1, name="name", code="123", company_id=other.id, country="US", region="region", city="city", address="address", longitude="123", latitude="123", type="type", status="status") floor = Floor(id=1, description="1st Floor", location_id=location.id) shape = TableShape(id=1, description="Round Table", picture="/path/to/file.jpg") table = Table(id=1, name="some table", floor_id=floor.id, x=40, y=50, width=320, height=150, status=1, max_capacity=12, multiple=False, playstation=False, shape_id=1) db_session.add(company) db_session.add(other) db_session.add(location) db_session.add(floor) db_session.add(shape) db_session.commit() db_session.add(table) user = Employee(id=1, first_name="Alice", last_name="Cooper", username="******", phone_number="1", birth_date=datetime.utcnow(), pin_code=3333, account_status="on", user_status="on", registration_date=datetime.utcnow(), company_id=company.id, email="*****@*****.**", password="******") flask.g.user = user db_session.add(user) db_session.commit() assert not has_privilege( method=Method.READ, resource="tables", id=table.id)
def test_new_table_shape(): id = 1 description = "Round table" picture = "/static/pictures/roundtable.png" new_table_shape = TableShape(id=id, description=description, picture=picture) assert (new_table_shape.id == id and new_table_shape.description == description and new_table_shape.picture == picture)
def test_filtered_list(client, db_session): db_session.add(TableShape(id=1, description="B", picture="pic")) db_session.add(TableShape(id=2, description="A", picture="pic")) db_session.add(TableShape(id=3, description="BB", picture="pic")) db_session.commit() response = client.get( flask.url_for('table_shape.list', filter_by=["description=B"])) assert response.status_code == HTTPStatus.OK # @todo #260:30min Lets encapsulate the way test checks for the returned table spaces. Currently all # the specifics on how to check the amount of returned table shapes and specific table shape details is exposed # directly in client code. There is a need to have a so called Page Object abstraction for the table_shapes.list # route that will encapsulate parsing, length and index access in a single entity, having a single place to fix in # case UI layout is changed. Please consider following draft client code as a reference: # table_shapes = TableShapes(client, filter_by=["description=B"] # assert len(table_shapes) == 1 # assert iter(table_shapes).next().id == 1 html = response.data.decode("utf-8") assert html.count("<article class=\"table_shape\">") == 1 assert html.count( "<a class=\"action\" href=\"/table_shapes/edit/1\">Edit</a>") == 1