Exemple #1
0
def sync_tables():
    """
    Periodic task for fetching and saving tables from Poster
    @todo #187:30min Set up scheduler for celery,
     docs - http://docs.celeryproject.org/en/
     latest/userguide/periodic-tasks.html#id5
     Also should make small refactoring: celery.py should situated in
     timelessis/celery.py not in timelessis/sync/celery.py
    """
    auth_data = PosterAuthData(
        application_id=os.environ.get("poster_application_id"),
        application_secret=os.environ.get("poster_application_secret"),
        redirect_uri=os.environ.get("poster_redirect_uri"),
        code=os.environ.get("poster_code"),
    )
    auth_token = Authenticated(auth_data=auth_data).auth()
    poster = Poster(auth_token=auth_token)
    for poster_table in poster.tables():
        table = DB.session(Table).query.filter_by(
            name=poster_table["name"],
            floor_id=poster_table["floor_id"]).first()

        if table:
            new_table = Table.merge_with_poster(table, poster_table)
            DB.session.add(new_table)
        else:
            new_table = Table.create_by_poster(poster_table)
            DB.session.merge(new_table)

        DB.session.commit()
def test_edit(client, db_session):
    table = Table(name="first name",
                  x=1,
                  y=2,
                  width=100,
                  height=75,
                  status=1,
                  max_capacity=4,
                  multiple=False,
                  playstation=True)
    db_session.add(table)
    db_session.commit()
    name = "updated name"
    response = client.post(url_for("table.edit", id=1),
                           data={
                               "name": name,
                               "x": 1,
                               "y": 2,
                               "width": 100,
                               "height": 75,
                               "status": 1,
                               "max_capacity": 4,
                               "multiple": False,
                               "playstation": True
                           })
    assert response.location.endswith(url_for('table.list_tables'))
    assert Table.query.count() == 1
    assert Table.query.get(1).name == name
Exemple #3
0
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_delete(client, db_session):
    table = Table(name="test name",
                  x=1,
                  y=2,
                  width=100,
                  height=75,
                  status=1,
                  max_capacity=4,
                  multiple=False,
                  playstation=True)
    db_session.add(table)
    db_session.commit()
    response = client.post(url_for("table.delete", id=1))
    assert response.location.endswith(url_for('table.list_tables'))
    assert Table.query.count() == 0
Exemple #5
0
def test_new_table():
    id = 42
    name = "Philosopher's Table"
    floor_id = 600,
    x = 40,
    y = 50,
    width = 320,
    height = 200,
    status = "available",
    max_capacity = 5,
    multiple = False,
    playstation = False,
    shape_id = 3
    created = datetime.utcnow
    updated = datetime.utcnow
    min_capacity = SchemeType()
    deposit_hour = SchemeType()

    new_table = Table(id=id,
                      name=name,
                      floor_id=floor_id,
                      x=x,
                      y=y,
                      width=width,
                      height=height,
                      status=status,
                      max_capacity=max_capacity,
                      multiple=multiple,
                      playstation=playstation,
                      shape_id=shape_id,
                      created=created,
                      updated=updated,
                      min_capacity=min_capacity.id,
                      deposit_hour=deposit_hour.id)
    assert (new_table.id == id and new_table.name == name
            and new_table.floor_id == floor_id and new_table.x == x
            and new_table.y == y and new_table.width == width
            and new_table.height == height and new_table.status == status
            and new_table.max_capacity == max_capacity
            and new_table.multiple == multiple
            and new_table.playstation == playstation
            and new_table.shape_id == shape_id, new_table.created == created,
            new_table.updated == updated
            and new_table.min_capacity == min_capacity.id
            and new_table.deposit_hour == deposit_hour.id)
def test_sync_table(db_session):
    port = free_port()
    poster_table_id = 10
    poster_table_name = "Round Table of The Knights"
    poster_table_floor_id = 5
    poster_table_x = 640
    poster_table_y = 480
    poster_table_width = 200
    poster_table_height = 200
    poster_table_status = "active"
    poster_table_max_capacity = 5
    poster_table_multiple = False
    poster_table_playstation = True
    poster_table_shape_id = 1
    poster_table_min_capacity = 1
    poster_table_created = datetime.utcnow
    poster_table_updated = datetime.utcnow
    start_server(port,
                 tables=[{
                     "id": poster_table_id,
                     "name": poster_table_name,
                     "floor_id": poster_table_floor_id,
                     "x": poster_table_x,
                     "y": poster_table_y,
                     "width": poster_table_width,
                     "height": poster_table_height,
                     "status": poster_table_status,
                     "max_capacity": poster_table_max_capacity,
                     "multiple": poster_table_multiple,
                     "playstation": poster_table_playstation,
                     "shape_id": poster_table_shape_id,
                     "min_capacity": poster_table_min_capacity,
                     "created": poster_table_created,
                     "updated": poster_table_updated
                 }])
    table_in_database = Table(id=10,
                              name="Table for Knights that Are Round",
                              floor_id=6,
                              x=800,
                              y=600,
                              width=400,
                              height=400,
                              status="inactive",
                              max_capacity=4,
                              multiple=True,
                              playstation=False,
                              shape_id=3,
                              min_capacity=2,
                              created=date.today() - timedelta(5),
                              updated=date.today() - timedelta(5))
    db_session.add(table_in_database)
    db_session.commit()
    synced_table = SyncedTable(table_in_database).sync(
        Poster(url=f"http://localhost:{port}"))
    row = db_session.query(Table).get(synced_table.id)
    assert row.id == poster_table_id
    assert row.name == poster_table_name
    assert row.floor_id == poster_table_floor_id
    assert row.x == poster_table_x
    assert row.y == poster_table_y
    assert row.width == poster_table_width
    assert row.height == poster_table_height
    assert row.status == poster_table_status
    assert row.max_capacity == poster_table_max_capacity
    assert row.multiple == poster_table_multiple
    assert row.playstation == poster_table_playstation
    assert row.shape_id == poster_table_shape_id
    assert row.min_capacity == poster_table_min_capacity
    assert row.created == poster_table_created
    assert row.updated == poster_table_updated