Пример #1
0
def client(app):
    with app.app_context():
        client = app.test_client()
        db.create_all()

        # Add Users
        password = generate_password_hash('Monday1')
        db.session.add(
            User(id=1,
                 first_name='TestA',
                 last_name='UserOne',
                 email='*****@*****.**',
                 password=password))
        db.session.add(
            User(id=2,
                 first_name='TestB',
                 last_name='UserTwo',
                 email='*****@*****.**',
                 password=password))
        db.session.commit()

        # Add some Characters db.session.add(Character(id=1, name='Paladin', is_dead=False))
        db.session.add(Character(id=2, name='Rogue', is_dead=False))
        db.session.add(Character(id=3, name='Fighter', is_dead=False))
        db.session.commit()

        # Set the current Character
        db.session.add(Setting(key='current_character', value='2'))
        db.session.commit()

        yield client
        db.drop_all()
Пример #2
0
def client_loaded(app):
    with app.app_context():
        client_loaded = app.test_client()
        db.create_all()

        password = generate_password_hash('Monday1')
        db.session.add(
            User(id=1,
                 first_name='Test',
                 last_name='User',
                 email='*****@*****.**',
                 password=password))
        db.session.add(
            User(id=2,
                 first_name='John',
                 last_name='Smith',
                 email='*****@*****.**',
                 password=password))
        db.session.commit()

        db.session.add(
            Character(id=1, name='Paladin', is_dead=False, user_id=1))
        db.session.add(Character(id=2, name='Rogue', is_dead=False, user_id=1))
        db.session.add(
            Character(id=3, name='Fighter', is_dead=False, user_id=2))
        db.session.commit()

        data = dict(email='*****@*****.**',
                    password='******',
                    remember_me=False)
        client_loaded.post('/login', data=data)

        yield client_loaded
        db.drop_all()
Пример #3
0
def entry_client(app):
    """ Fixture with more test data in it """

    with app.app_context():
        entry_client = app.test_client()
        db.create_all()

        # Add some Characters
        db.session.add(Character(id=1, name='Paladin', is_dead=False))
        db.session.add(Character(id=2, name='Rogue', is_dead=False))
        db.session.add(Character(id=3, name='Fighter', is_dead=False))
        db.session.commit()

        # Set the current Character
        db.session.add(Setting(key='current_character', value='2'))
        db.session.commit()

        # Add some entries
        db.session.add(
            Entry(id=1,
                  game_session=1,
                  description='Wand',
                  amount=10.00,
                  character_id=2))
        db.session.add(
            Entry(id=2,
                  game_session=1,
                  description='Sword',
                  amount=20.00,
                  character_id=2))
        db.session.add(
            Entry(id=3,
                  game_session=2,
                  description='Potion',
                  amount=30.00,
                  character_id=2))
        db.session.add(
            Entry(id=4,
                  game_session=1,
                  description='Crossbow',
                  amount=40.00,
                  character_id=3))
        db.session.add(
            Entry(id=5,
                  game_session=2,
                  description='Spear',
                  amount=50.00,
                  character_id=3))
        db.session.add(
            Entry(id=6,
                  game_session=3,
                  description='Backpack',
                  amount=60.00,
                  character_id=3))
        db.session.commit()

        yield entry_client
        db.drop_all()
Пример #4
0
def client(app):
    with app.app_context():
        client = app.test_client()
        db.create_all()

        db.session.add(Player(
            first_name='Payton',
            last_name='Young',
            email='*****@*****.**',
            is_active=True)
        )

        db.session.add(Party(
            party_name='Adventure Inc',
            is_active=True
            )
        )

        db.session.add(Character(
            character_name='Milo Thorngage',
            character_class='Investigator',
            is_active=True,
            is_dead=False,
            player_id=1,
            party_id=1
        ))
        db.session.commit()

        yield client
        db.drop_all()
Пример #5
0
def client(app):
    """ Fixture with basic data in it """

    with app.app_context():
        client = app.test_client()
        db.create_all()

        # Add some Characters db.session.add(Character(id=1, name='Paladin', is_dead=False))
        db.session.add(Character(id=2, name='Rogue', is_dead=False))
        db.session.add(Character(id=3, name='Fighter', is_dead=False))
        db.session.commit()

        # Set the current Character
        db.session.add(Setting(key='current_character', value='2'))
        db.session.commit()

        yield client
        db.drop_all()
Пример #6
0
def add_character():
    """ Handle adding a new Character """
    form = AddCharacterForm()
    if form.validate_on_submit():
        new_character = Character(name=form.name.data,
                                  is_dead=form.is_dead.data,
                                  user_id=current_user.id)
        db.session.add(new_character)
        db.session.commit()

    return redirect(url_for('character_bp.character_list'))
Пример #7
0
def __init_test_db():
    db.create_all()

    # Add Users
    password = generate_password_hash('Monday1')
    db.session.add(
        User(id=1,
             first_name='TestA',
             last_name='UserOne',
             email='*****@*****.**',
             password=password))
    db.session.add(
        User(id=2,
             first_name='TestB',
             last_name='UserTwo',
             email='*****@*****.**',
             password=password))
    db.session.commit()

    db.session.add(Character(id=1, user_id=1, name='Paladin', is_dead=False))
    db.session.add(Character(id=2, user_id=1, name='Rogue', is_dead=False))
    db.session.add(Character(id=3, user_id=2, name='Fighter', is_dead=False))
    db.session.commit()
Пример #8
0
def test_handle_character_no_entries(empty_client):
    """ confirm the application can start up correctly without any characters or entries in the db """
    with empty_client:
        # arrange
        empty_client.post('/login',
                          data=dict(email='*****@*****.**',
                                    password='******',
                                    remember_me=False))

        # Add some Characters
        db.session.add(Character(id=1, name='Paladin', is_dead=False))
        db.session.add(Character(id=2, name='Rogue', is_dead=False))
        db.session.add(Character(id=3, name='Fighter', is_dead=False))
        db.session.commit()

        # Set the current Character
        db.session.add(Setting(key='current_character', value='2'))
        db.session.commit()

        # act
        result = empty_client.get('/', follow_redirects=True)

        # assert
        assert b'Entries' in result.data
Пример #9
0
def add_character():
    form = AddCharacterForm()

    if form.validate_on_submit():
        new_character = Character(
            character_name=form.character_name.data,
            character_class=form.character_class.data,
            player_id=form.player_id.data.id,
            party_id=form.party_id.data.id,
            is_active=True,
            is_dead=False
        )
        db.session.add(new_character)
        db.session.commit()
        flash('Character Added', 'success')

    return redirect(url_for('character_bp.show_character_list_form'))
Пример #10
0
def get_current_character_id():
    """ Check the database for a previously set active character
    if one isn't set then set the 'first one in the database. """

    # A filtered query
    # current = db.session.query(Setting).filter(Setting.key == 'current_character').all()

    # or another, shorter way
    # current = db.session.query(Setting).filter_by(key='current_character').all()

    # Scalar value, single value if it exists or None
    # current = db.session.scalar(Setting).filter_by(key='current_character')
    # current = Setting.scalar(Setting).filter_by(key='current_character')

    # see if their is a character id in session
    if 'current_character' in session:
        return session['current_character']

    # See if there is a saved character id on the database, if so set it to current
    current_id = Setting.query.filter_by(key='current_character').first()
    char = Character()

    if current_id is None:
        # no current_id has been saved try and get the first Character on the Character table and use that.
        char = Character.query.first()
        if char is None:
            return None

    else:
        # Ok we have a character on the database, pull it up
        char = Character.query.filter_by(id=current_id.value).first()
        # now we can save the right data
        db.session.add(Setting(key='current_character', value=str(char.id)))
        db.session.commit

    # set the character we found up in session
    session['current_character'] = char.id
    return char.id
Пример #11
0
def __init_test_db():
    ''' Add mock db data '''
    db.create_all()

    # Add Users
    password = generate_password_hash('Monday1')
    db.session.add(
        User(id=1,
             first_name='TestA',
             last_name='UserOne',
             email='*****@*****.**',
             password=password))
    db.session.add(
        User(id=2,
             first_name='TestB',
             last_name='UserTwo',
             email='*****@*****.**',
             password=password))
    db.session.commit()

    # Add sessions
    db.session.add(Setting(id=1, user_id=1, key='test_session', value='42'))
    db.session.add(Setting(id=2, user_id=2, key='test_session', value='99'))

    # Add some Characters
    db.session.add(Character(id=1, user_id=1, name='Paladin', is_dead=False))
    db.session.add(Character(id=2, user_id=1, name='Rogue', is_dead=False))
    db.session.add(Character(id=3, user_id=2, name='Fighter', is_dead=False))
    db.session.commit()

    # Add some entries
    db.session.add(
        Entry(id=1,
              game_session=1,
              description='Wand',
              amount=10.00,
              character_id=1))
    db.session.add(
        Entry(id=2,
              game_session=1,
              description='Sword',
              amount=20.00,
              character_id=1))
    db.session.add(
        Entry(id=3,
              game_session=2,
              description='Potion',
              amount=30.00,
              character_id=1))
    db.session.add(
        Entry(id=4,
              game_session=1,
              description='Crossbow',
              amount=40.00,
              character_id=2))
    db.session.add(
        Entry(id=5,
              game_session=1,
              description='Spear',
              amount=50.00,
              character_id=2))
    db.session.add(
        Entry(id=6,
              game_session=2,
              description='Backpack',
              amount=60.00,
              character_id=2))
    db.session.commit()
Пример #12
0
def entry_client(app):
    with app.app_context():
        entry_client = app.test_client()
        db.create_all()

        # Add some Characters
        db.session.add(Character(id=1, name='Paladin', is_dead=False))
        db.session.add(Character(id=2, name='Rogue', is_dead=False))
        db.session.add(Character(id=3, name='Fighter', is_dead=False))
        db.session.commit()

        # Set the current Character
        db.session.add(Setting(key='current_character', value='2'))
        db.session.commit()

        # Add Users
        password = generate_password_hash('Monday1')
        db.session.add(
            User(id=1,
                 first_name='TestA',
                 last_name='UserOne',
                 email='*****@*****.**',
                 password=password))
        db.session.add(
            User(id=2,
                 first_name='TestB',
                 last_name='UserTwo',
                 email='*****@*****.**',
                 password=password))
        db.session.commit()

        # Add some entries
        db.session.add(
            Entry(id=1,
                  game_session=1,
                  description='Wand',
                  amount=10.00,
                  character_id=2))
        db.session.add(
            Entry(id=2,
                  game_session=1,
                  description='Sword',
                  amount=20.00,
                  character_id=2))
        db.session.add(
            Entry(id=3,
                  game_session=2,
                  description='Potion',
                  amount=30.00,
                  character_id=2))
        db.session.add(
            Entry(id=4,
                  game_session=1,
                  description='Crossbow',
                  amount=40.00,
                  character_id=3))
        db.session.add(
            Entry(id=5,
                  game_session=1,
                  description='Spear',
                  amount=50.00,
                  character_id=3))
        db.session.add(
            Entry(id=6,
                  game_session=2,
                  description='Backpack',
                  amount=60.00,
                  character_id=3))
        db.session.commit()

        yield entry_client
        db.drop_all()