async def test_enter_room_with_wrong_password(client): async with client.app.app_context(): # Create a room room = Room() room.set_name('My password-protected room') room.set_password('cat') db.session.add(room) db.session.commit() # Attempt to enter the room response = await client.post(f'/room/{room.slug}', json={ 'password': '******' }) assert response.status_code == 401 data = await response.get_data() assert b'react-root' not in data
async def index(): create_room_form = CreateRoomForm() if create_room_form.validate_on_submit(): form = create_room_form name = form.room_name.data password = form.password.data is_public = form.public.data guest_limit = form.guest_limit.data try: room = Room(guest_limit=guest_limit, is_public=is_public) room.set_name(name) if password: room.set_password(password) db.session.add(room) commit_database(reraise=True) return redirect('/room/{}'.format(room.slug), code=307) except sqlalchemy.exc.IntegrityError: await flash('The room name "{}" is not available'.format(name)) return await render_template('chat.html', create_room_form=create_room_form)
async def test_room_authentication(): room = Room() room.set_password('cat') assert room.authenticate('cat')
async def test_room_failed_authentication(): room = Room() room.set_password('cat') assert not room.authenticate() assert not room.authenticate('dog')
async def test_room_set_password(): room = Room() room.set_password('cat') assert room.password_hash is not None