Exemple #1
0
def user_fx():
    return User(False,
                None,
                True,
                "unit_test",
                "unit_test[bot]",
                "unit_test",
                "unittest.rats.fuelrats.com",
                "potatobot"
                )
Exemple #2
0
async def test_user_eq(data: dict, monkeypatch, bot_fx):
    """
    verifies building a User from a full IRC reply when said user exists
    """

    monkeypatch.setattr(bot_fx, 'users', {data['nickname'].casefold(): data})

    user_alpha = await User.from_pydle(bot_fx, data['nickname'])
    user_beta = User(**data)

    assert user_alpha == user_beta
Exemple #3
0
def load_user(user_id):
    #returns the User object assigned to this id
    engine = sqlite3.connect(db_address)
    con = engine.cursor()
    user_details = con.execute(
        'SELECT username,password FROM users WHERE user_id=? LIMIT 1',
        (int(user_id), )).fetchall()
    current_user = None
    if user_details:
        username = user_details[0][0]
        password = user_details[0][1]
        current_user = User(username=username,
                            password=password,
                            id=int(user_id))
    return current_user
Exemple #4
0
def test_user_constructor(data: dict):
    """
    Tests the User constructor
    """
    my_user = User(
        away=data['away'],
        away_message=data['away_message'],
        identified=data['identified'],
        account=data['account'],
        nickname="unit_test",
        username=data['username'],
        hostname=data['hostname'],
        realname=data['realname'],
    )

    assert data['away'] == my_user.away
    assert data['away_message'] == my_user.away_message
    assert data['identified'] == my_user.identified
    assert data['account'] == my_user.account
    assert "unit_test" == my_user.nickname
    assert data['hostname'] == my_user.hostname
    assert data['username'] == my_user.username
    assert data['realname'] == my_user.realname
Exemple #5
0
def registration():
    #serve the reg form
    if request.method == 'GET':
        return render_template('registration.html')

    #get new user details
    elif request.method == 'POST':

        #if already registered, bypass the form to login page
        if request.form['submit'] == 'login':
            username = request.form['username']
            password = request.form['password']
            new_user_id = m.authenticate_user(username=username,
                                              password=password)
            if not new_user_id:
                flash('Username or password invalid')
                return redirect(url_for('registration'))
            else:  #i.e. user is in db
                id = new_user_id[0][0]  #get int value
                new_user = User(username=username, password=password, id=id)
                login_user(new_user)
                session['SUUID'] = unicode(uuid4())
                session[
                    'has_compared'] = False  #update when compared to enable feedback
                #update db with this session
                session_row = {
                    'suuid': session['SUUID'],
                    'user_id': int(id),
                    'start_time': unicode(datetime.now())
                }
                m.write_session_row(session_row)
                return redirect(url_for('instructions'))

        #take in new user and add to user table
        elif request.form['submit'] == 'register':
            username = request.form['username']
            password = request.form['password']
            driver_status = request.form['driver_status']
            print driver_status
            if driver_status == 'Yes':
                license = True
            elif driver_status == 'No':
                license = False
            else:
                flash(
                    'Please indicate whether you have a driving license when registering'
                )
                return redirect(url_for('registration'))
            m.register_user(username, password, license)

            #login the new usr
            new_user_id = m.authenticate_user(username=username,
                                              password=password)
            id = new_user_id[0][0]  #get int value
            new_user = User(username=username, password=password, id=id)
            login_user(new_user)
            session['SUUID'] = unicode(uuid4())
            session[
                'has_compared'] = False  #update when compared to enable feedback
            #update db with this session
            session_row = {
                'suuid': session['SUUID'],
                'user_id': int(id),
                'start_time': unicode(datetime.now())
            }
            m.write_session_row(session_row)
            return redirect(url_for('instructions'))
Exemple #6
0
def test_process_vhost_garbage(garbage: str):
    """
    Verifies result of throwing garbage at `User.process_vhost()`
    """
    assert User.process_vhost(garbage) is None
Exemple #7
0
def test_process_vhost_orange():
    """
    Asserts vhost processing works for Orange, as he has a special vhost
    (that can't be tested in the parametrize)
    """
    assert User.process_vhost("i.see.all") == "i.see.all"
Exemple #8
0
def test_process_vhost(prefix: str, expected_host: str):
    """
    Asserts vhost processing functions as expected
    """
    mixed_host = f"{prefix}{expected_host}"
    assert User.process_vhost(mixed_host) == expected_host