Ejemplo n.º 1
0
    def test_add_user(self):
        with app.test_request_context():
            assert User.query.count() == 0

        cmd = AddUser(lambda: app.app_context(), app_bcrypt=openmoves.app_bcrypt)
        cmd.run(username='******')

        with app.test_request_context():
            assert User.query.count() == 1
            assert User.query.filter_by(username='******').one()

        with pytest.raises(AssertionError) as e:
            cmd.run(username='******')
        assert "user already exists" in str(e.value)

        cmd.run(username='******')
        with app.test_request_context():
            assert User.query.count() == 2
            assert User.query.filter_by(username='******').one() != User.query.filter_by(username='******').one()
Ejemplo n.º 2
0
    def test_add_user(self):
        with app.test_request_context():
            assert User.query.count() == 0

        cmd = AddUser(lambda: app.app_context(), app_bcrypt=openmoves.app_bcrypt)
        cmd.run(username='******')

        with app.test_request_context():
            assert User.query.count() == 1
            assert User.query.filter_by(username='******').one()

        with pytest.raises(AssertionError) as e:
            cmd.run(username='******')
        assert u"user already exists" in str(e.value)

        cmd.run(username='******')
        with app.test_request_context():
            assert User.query.count() == 2
            assert User.query.filter_by(username='******').one() != User.query.filter_by(username='******').one()
Ejemplo n.º 3
0
def command_app_context():
    app.config.update(SQLALCHEMY_ECHO=False)
    return app.app_context()


manager = Manager(init)

manager.add_option('-c',
                   '--config',
                   dest='configfile',
                   default='openmoves.cfg',
                   required=False)

manager.add_command("runserver", Server(use_debugger=True))
manager.add_command('db', MigrateCommand)
manager.add_command('add-user', AddUser(command_app_context, app_bcrypt))
manager.add_command('import-move', ImportMove(command_app_context))
manager.add_command('delete-move', DeleteMove(command_app_context))
manager.add_command('list-moves', ListMoves(command_app_context))


@app.errorhandler(404)
def error404(error):
    return render_template('_404.html'), 404


@app.route('/import', methods=['GET', 'POST'])
@login_required
def move_import():
    xmlfiles = request.files.getlist('files')
    imported_moves = []