def test_add_user(self): owner = User(name="joe") room = Room(owner=owner) user = User(name="james") room.add_user(user) self.assertIn( user._id, Room(_id=room._id)._object['users'] )
def test_draft(self): owner = User(name="joe") room = Room(owner=owner) for name in ['john','carl','james']: user = User(name=name) room.add_user(user) self.assertIn( room.draft(), Room(_id=room._id)._object['users'] )
def test_remove_inexistent_user(self): owner = User(name="joe") room = Room(owner=owner) user = User(name="james") room.add_user(user) room.remove_user(user) self.assertNotIn( user._id, Room(_id=room._id)._object['users'] )
def test_add_user_twice(self): owner = User(name="joe") room = Room(owner=owner) user = User(name="james") room.add_user(user) room.add_user(user) self.assertEqual( Room(_id=room._id)._object['users'].count(user._id), 1 )
def edit_property(): from database import Property, Room informations = request.get_json() if 'id' in informations: property = Property.query.filter_by(id=informations['id'], owner_id=g.user.id).first() if not property: return jsonify({'error': 'Property not existing or not yours'}) else: if 'name' in informations: if informations[ 'name'] != property.name and Property.query.filter_by( name=informations['name']).count() == 0: property.name = informations['name'] if 'city' in informations: property.city = informations['city'] if 'type' in informations: property.type = informations['type'] if 'description' in informations: property.description = informations['description'] if 'address' in informations: property.address = informations['address'] if 'rooms' in informations: for room in informations['rooms']: if 'action' in room: if room['action'] == 'add': var = Room() var.property_id = property.id if 'area' in room: var.area = room['area'] else: var.area = None if 'description' in room: var.description = room['description'] else: var.description = "" db.session.add(var) elif room['action'] == 'delete' and 'id' in room: var = Room.query.filter_by(id=room['id']).first() db.session.delete(var) elif room['action'] == 'edit' and 'id' in room: var = Room.query.filter_by(id=room['id']).first() if 'area' in room: var.area = room['area'] if 'description' in room: var.description = room['description'] db.session.commit() final_property = Property.query.filter_by( id=informations['id']).first() return jsonify(final_property.serialize) else: return jsonify({'error': 'ID of property missing'})
def add_property(): from database import Property, Room informations = request.get_json() if 'name' in informations and 'city' in informations: if Property.query.filter_by(name=informations['name'], owner_id=g.user.id).first() is None: property = Property() property.name = informations['name'] property.city = informations['city'] property.owner_id = g.user.id if 'type' in informations: property.type = informations['type'] else: property.type = "" if 'description' in informations: property.description = informations['description'] else: property.description = "" if 'address' in informations: property.address = informations['address'] else: property.address = "" db.session.add(property) db.session.commit() if 'rooms' in informations: property_id = Property.query.filter_by( name=informations['name'], owner_id=g.user.id).first().id for room in informations['rooms']: var = Room() var.property_id = property_id if 'area' in room: var.area = room['area'] else: var.area = None if 'description' in room: var.description = room['description'] else: var.description = "" db.session.add(var) db.session.commit() final_property = Property.query.filter_by( name=informations['name'], owner_id=g.user.id).first() return jsonify(final_property.serialize) else: return jsonify({'error': 'Name already existing'}) else: return jsonify({'error': 'City or name is missing'})
def create_test_api(): room = Room.query.filter_by(id=request.args.get('room_id', -1)).first() if room is None: room = Room('', request.args.get('password', '')) DB.session.add(room) DB.session.commit() room.description = request.args.get('description', '') if request.args.get('password') is not None: session[str(room.id)] = request.args.get('password') for key, case in json.loads(request.args.get('cases', '{}')).items(): tests = case.get("tests", "") expects = case.get("expects", "") id = case.get("id", 0) testdata = TestData(id, room.id, tests, expects) DB.session.add(testdata) DB.session.commit() return json.dumps({"url": '/edit/{}'.format(room.id), "room_id": room.id})
def write_new_room(database, numMafia): targets = Targets("", "", "") new_room = Room( generateGameRoomKey(), int(numMafia), 0, [], targets, "pre-game", "pre-game", True, uuid.uuid4().hex, [], [Message("Waiting for players", "Waiting for players")], [Message("Waiting for players", "Waiting for players")] ) database.append(new_room) return database, new_room
def create_test_room(): players = [ Player('alan', '12354', 'mafia', 'alive', False), Player('noob1', '42314', 'civilian', 'alive', False), Player('noob2', '22222', 'civilian', 'alive', False), Player('noob3', '33333', 'civilian', 'alive', False), Player('noob4', '44444', 'civilian', 'alive', False) ] targets = Targets('', '', '') gameMessages = [Message('Pre-Game', 'Waiting for players...')] observerMessages = [ Message('Pre-Game', 'Waiting for players...'), Message('Observer Message', 'Testing...') ] room = Room('0001', 2, 0, players, targets, 'pre-game', 'pre-game', True, '55555', [], gameMessages, observerMessages) database.append(room) LOG.info('Test room created..')
addr='zeiozrez') session.add(ch1) session.add(ch2) session.add(ch3) session.add(ch4) print("Checkouts Done :)") ################################### r1 = Room( title='Junior Suit', description= 'body="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essenti', price='400', mode='CLOSED', home_img='http://127.0.0.1:5000/static/img/room/r2/Room-1_1.jpg', img1_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_1.jpg', img2_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_1.jpg', img3_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_1.jpg', capacity='5') r2 = Room( title='Sinior Suit', description= 'body="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essenti', price='700', mode='CLOSED', home_img='http://127.0.0.1:5000/static/img/room/r2/Room-1_3.jpg', img1_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_3.jpg', img2_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_3.jpg', img3_url='http://127.0.0.1:5000/static/img/room/r2/Room-1_3.jpg',
def create(): # Get player id stored in a cookie player_id = request.cookies.get('uuid') # List of all players on the website player = Player.query.filter_by(uuid=player_id).first() # If user doesnt have a name and id assigned, redirect them to create one if not player_id or not player: return redirect('/name/create') if request.method == 'POST': # User has not accepted the use of cookies if not request.cookies.get('cookies'): return render_template( 'create.html', settings=settings_values, error='You must accept the use of cookies before proceeding.') # Validate recaptcha if not recaptcha.verify(): return render_template('create.html', settings=settings_values, error='ReCaptcha failed.') difficulty = Difficulty.query.filter_by( name=request.form.get('difficulty')).first() goal = Goal.query.filter_by(name=request.form.get('goal')).first() logic = Logic.query.filter_by(name=request.form.get('logic')).first() mode = Mode.query.filter_by(name=request.form.get('mode')).first() variation = Variation.query.filter_by( name=request.form.get('variation')).first() weapons = Weapons.query.filter_by( name=request.form.get('weapons')).first() settings = Settings(difficulty, bool(request.form.get('enemizer')), goal, logic, mode, bool(request.form.get('spoilers')), bool(request.form.get('tournament')), variation, weapons) settings_validate, settings_error = validation.validate_settings( settings) # Make certain that all selected settings exist if not settings_validate: return render_template('create.html', settings=settings, error=settings_error) seed = alttpr_api.generate_seed(settings.to_dict()) hash_code = seed['hash'] chat_url = chat.get_chat_room(hash_code) # Create a game room room = Room(settings=settings, chat_url=chat_url, creator=player, hash_code=hash_code) #db.session.add(settings) db.session.add(room) db.session.commit() # generate response that redirects to the game room just created response = make_response(redirect(f'/room/{room.hash_code}')) return response else: return render_template('create.html', settings=settings_values, error=None)
def test_delete_room(self): owner = User(name="joe") room = Room(owner=owner) room.delete() self.assertRaises(Exception,Room(_id=room._id))