コード例 #1
0
ファイル: routes.py プロジェクト: bkalika/cursor
 def post(self):
     data = room_parser.parse_args()
     if not Room.query.filter_by(number=data["number"]).scalar():
         try:
             db.session.add(Room(**data))
             db.session.commit()
         except IntegrityError:
             db.session.rollback()
         return {"msg": f"Room {data['number']} was added"}
     abort(404, message="Room already exist!")
コード例 #2
0
ファイル: building.py プロジェクト: chrisnorman7/mwm
 def func(self, character, args, text):
     z = Zone(builder_id=character.id, name='New Zone #')
     s.add(z)
     s.commit()
     z.name = f'{z.name}{z.id}'
     character.notify(f'Created zone {z.name}.')
     r = Room(zone_id=z.id, name='The First Room')
     s.add(r)
     s.commit()
     character.notify(f'Created room {r}.')
     character.move(r)
     character.show_location()
コード例 #3
0
def create_session():
    if not verify_session_token():
        return failure_response("Session token expired.")

    body = json.loads(request.data)

    num_sessions = body.get("num_sessions")
    work_length = body.get("work_length")
    break_length = body.get("break_length")
    room_length = num_sessions * (work_length + break_length)

    user = users_dao.get_user_by_username(body.get("username")).first()

    if user is None:
        failure_response("User invalid")
    if num_sessions is None:
        failure_response("Must enter number of sessions")
    if work_length is None:
        failure_response("Must enter length of work periods")
    if break_length is None:
        failure_response("Must enter length of break periods")

    # Create new OpenTok session
    opentok_id = opentok.create_session().session_id
    token = opentok.generate_token(opentok_id,
                                   expire_time=int(time.time()) + room_length)

    # Create new Room Object
    body = json.loads(request.data)
    new_room = Room(opentok_id=opentok_id,
                    code=body.get('code'),
                    num_sessions=body.get('num_sessions'),
                    work_length=body.get('work_length'),
                    break_length=body.get('break_length'))

    # Add creator to Room Object
    new_room.users.append(user)

    # Push changes to database
    db.session.add(new_room)
    db.session.commit()

    # Give client parameters necessary to connect
    return success_response(
        {
            'key': api_key,
            'opentok_id': opentok_id,
            'token': token
        }, 201)
コード例 #4
0
ファイル: building.py プロジェクト: chrisnorman7/mwm
 def func(self, character, args, text):
     direction = args.direction
     title = args.title
     if not title:
         self.exit(message='Room titles cannot be blank.')
     d = character.location.match_direction(direction)
     if d is None:
         self.exit(message=f'Invalid exit: {direction}')
     direction = d.name
     if Exit.query(name=direction,
                   location_id=character.location_id).count():
         self.exit(message='There is already an exit in that direction.')
     x, y, z = d.coordinates_from(character.location.coordinates)
     r = Room.query(x=x, y=y, z=z).first()
     if r is None:
         r = Room(name=title,
                  x=x,
                  y=y,
                  z=z,
                  zone_id=character.location.zone_id)
         s.add(r)
         s.commit()
         msg = f'Created room {r}.'
     else:
         msg = f'Linking to room {r}.'
     character.notify(msg)
     x = Exit(name=direction,
              location_id=character.location_id,
              target_id=r.id)
     y = Exit(name=d.opposite.name,
              location_id=r.id,
              target_id=character.location.id)
     s.add_all([x, y])
     s.commit()
     for thing in [x, y]:
         character.notify(f'Created exit {thing} from {thing.location} to '
                          f'{thing.target}.')
コード例 #5
0
ファイル: db_test.py プロジェクト: chrisnorman7/mwm
"""Boring database tests."""

from db import (Room, Character, session, Exit, Object, Guild, GuildSecondary,
                Direction, Zone)

with session() as s:
    z = Zone(name='Test')
    s.add(z)
    s.commit()
    r = Room(name='Test Room', zone_id=z.id)
    c = Character(name='Test Player', location=r)
    s.add_all((c, r))
    s.commit()
    rid = r.id
    cid = c.id


def test_location_ids():
    c = Character.get(cid)
    assert c.location_id == rid


def test_stats():
    c = Character.get(cid)
    c.max_hitpoints = 50
    assert c.h == c.max_hitpoints
    c.h = 5
    assert c.h == 5
    assert c.max_hitpoints == 50
    c.h = c.max_hitpoints
    assert c.hitpoints is None