コード例 #1
0
def test_remove_user():
    user = users.add_user('test_remove_user_user',
                          'test_remove_user_user_password')
    assert user is not None
    assert user.username == 'test_remove_user_user'
    assert user.check_password('test_remove_user_user_password') is True

    users.remove_user('test_remove_user_user')
    assert users.get_user('test_remove_user_user') is None
コード例 #2
0
def login():
    form = forms.LoginForm()
    if form.validate_on_submit():
        user = users.get_user(form.data['username'])
        if user:
            if user.check_password(form.data['password']):
                login_user(user)
                return redirect('/')

    return render_template('admin.html', form=form)
コード例 #3
0
def test_remove_user():
    user = users.add_user(
        'test_remove_user_user',
        'test_remove_user_user_password'
    )
    assert user is not None
    assert user.username == 'test_remove_user_user'
    assert user.check_password('test_remove_user_user_password') is True

    users.remove_user('test_remove_user_user')
    assert users.get_user('test_remove_user_user') is None
コード例 #4
0
def test_load_users():
    with temp_file('testusers.dat'):
        with patch('manufactorum.users.USERS_FILE', 'testusers.dat'):
            assert users.load_users() == []

            users.add_user('test_load_users_user',
                           'test_load_users_user_password')

            assert len(users.load_users()) == 1
            assert users.user_exists('test_load_users_user') is True
            assert users.user_exists('Someone') is False

            user = users.get_user('test_load_users_user')
            assert user is not None
            assert user.username == 'test_load_users_user'
            assert user.check_password('test_load_users_user_password') is True

            users.remove_user('test_load_users_user')
コード例 #5
0
def test_add_user():
    test_file = 'test_users.tmp'
    try:
        os.remove(test_file)
    except FileNotFoundError:
        pass

    with patch('manufactorum.users.USERS_FILE', test_file):
        users.add_user('user', 'user')
        user = users.get_user('user')

        assert user is not None
        assert user.username == 'user'
        assert user.check_password('user') is True

        with pytest.raises(Exception):
            users.add_user('user', 'user')

        os.remove(test_file)
コード例 #6
0
def test_add_user():
    test_file = 'test_users.tmp'
    try:
        os.remove(test_file)
    except FileNotFoundError:
        pass

    with patch('manufactorum.users.USERS_FILE', test_file):
        users.add_user('user', 'user')
        user = users.get_user('user')

        assert user is not None
        assert user.username == 'user'
        assert user.check_password('user') is True

        with pytest.raises(Exception):
            users.add_user('user', 'user')

        os.remove(test_file)
コード例 #7
0
def test_load_users():
    with temp_file('testusers.dat'):
        with patch('manufactorum.users.USERS_FILE', 'testusers.dat'):
            assert users.load_users() == []

            users.add_user(
                'test_load_users_user',
                'test_load_users_user_password'
            )

            assert len(users.load_users()) == 1
            assert users.user_exists('test_load_users_user') is True
            assert users.user_exists('Someone') is False

            user = users.get_user('test_load_users_user')
            assert user is not None
            assert user.username == 'test_load_users_user'
            assert user.check_password('test_load_users_user_password') is True

            users.remove_user('test_load_users_user')