コード例 #1
0
def create_task():
    if 'user' not in session:
        return redirect(url_for('login'))
    connection = model.connect()
    user_id = session['user']['id']
    tasks_user = model.tasks_user(connection, user_id)
    try:
        task_do = int(request.cookies['task_do'])
    except:
        task_do = None
    list_task = model.tasks(connection)
    form = TasksForm(request.form)
    if form.validate_on_submit():
        try:
            connection = model.connect()
            date = datetime.datetime.now()
            task = {
                'id': None,
                'title': form.title.data,
                'description': form.description.data,
                'creation_date': date,
                'due_date': form.due_date.data,
                'id_user': user_id
            }
            model.insert_task(connection, task)
            return redirect('/liste')
        except Exception as exception:
            app.log_exception(exception)
    return render_template('liste.html',
                           form=form,
                           liste=list_task,
                           tasks_user=tasks_user,
                           task_do=task_do)
コード例 #2
0
def test_task_exception():
    connection = model.connect(":memory:")
    model.create_database(connection)
    model.fill_database(connection)
    with pytest.raises(Exception) as exception_info:
        model.task(connection, 1000)
    assert str(exception_info.value) == 'Task inconnu'
コード例 #3
0
def test_user_exception():
    connection = model.connect(":memory:")
    model.create_database(connection)
    model.fill_database(connection)
    with pytest.raises(Exception) as exception_info:
        model.user(connection, 1000)
    assert str(exception_info.value) == 'Équipe inconnue'
コード例 #4
0
def test_users_and_insert_user():
    connection = model.connect(":memory:")
    model.create_database(connection)
    users = data.users()
    model.insert_user(connection, users[1])
    model.insert_user(connection, users[0])
    assert model.users(connection) == [users[0], users[1]]
コード例 #5
0
def home():
    if 'user' not in session:
        return redirect(url_for('login'))
    connection = model.connect()
    user_id = session['user']['id']
    limitated_tasks_user = model.limitated_tasks_user(connection, user_id)
    return render_template('home.html',
                           limitated_tasks_user=limitated_tasks_user)
コード例 #6
0
def test_add_user_email_unique():
    connection = model.connect(":memory:")
    model.create_database(connection)
    model.create_database(connection)
    model.add_user(connection, '*****@*****.**', 'secret1')
    with pytest.raises(Exception) as exception_info:
        model.add_user(connection, '*****@*****.**', 'secret2')
    assert str(exception_info.value) == 'UNIQUE constraint failed: users.email'
コード例 #7
0
def test_change_password_old_password_check():
    connection = model.connect(":memory:")
    model.create_database(connection)
    model.add_user(connection, '*****@*****.**', 'secret1')
    with pytest.raises(Exception) as exception_info:
        model.change_password(connection, '*****@*****.**', 'secret2',
                              'secret1')
    assert str(exception_info.value) == 'Utilisateur inconnu'
コード例 #8
0
def test_add_and_get_user():
    connection = model.connect(":memory:")
    model.create_database(connection)
    model.add_user(connection, '*****@*****.**', 'secret1')
    model.add_user(connection, '*****@*****.**', 'secret2')
    user1 = model.get_user(connection, '*****@*****.**', 'secret1')
    user2 = model.get_user(connection, '*****@*****.**', 'secret2')
    assert user1 == {'id': 1, 'email': '*****@*****.**'}
    assert user2 == {'id': 2, 'email': '*****@*****.**'}
コード例 #9
0
def test_change_password():
    connection = model.connect(":memory:")
    model.create_database(connection)
    model.add_user(connection, '*****@*****.**', 'secret1')
    model.change_password(connection, '*****@*****.**', 'secret1', 'secret2')
    user = model.get_user(connection, '*****@*****.**', 'secret2')
    assert user == {'id': 1, 'email': '*****@*****.**'}
    with pytest.raises(Exception) as exception_info:
        model.get_user(connection, '*****@*****.**', 'secret1')
    assert str(exception_info.value) == 'Utilisateur inconnu'
コード例 #10
0
def test_tasks_and_insert_task():
    connection = model.connect(":memory:")
    model.create_database(connection)
    tasks = data.tasks()
    users = data.users()
    model.insert_user(connection, users[0])
    model.insert_user(connection, users[1])
    model.insert_task(connection, tasks[6])
    model.insert_task(connection, tasks[1])
    model.insert_task(connection, tasks[5])
    assert model.tasks(connection) == [tasks[1], tasks[5], tasks[6]]
コード例 #11
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        try:
            connection = model.connect()
            user = model.get_user(connection, form.email.data,
                                  form.password.data)
            session['user'] = user
            return redirect(url_for('home'))
        except Exception as exception:
            app.log_exception(exception)
    return render_template('login.html', form=form)
コード例 #12
0
def test_get_user_exception():
    connection = model.connect(":memory:")
    model.create_database(connection)
    model.add_user(connection, '*****@*****.**', 'secret')
    with pytest.raises(Exception) as exception_info:
        model.get_user(connection, '*****@*****.**', 'secret')
    assert str(exception_info.value) == 'Utilisateur inconnu'
    with pytest.raises(Exception) as exception_info:
        model.get_user(connection, '*****@*****.**', 'secret1')
    assert str(exception_info.value) == 'Utilisateur inconnu'
    with pytest.raises(Exception) as exception_info:
        model.get_user(connection, '*****@*****.**', 'secret1')
    assert str(exception_info.value) == 'Utilisateur inconnu'
コード例 #13
0
def test_delete_task():
    connection = model.connect(":memory:")
    model.create_database(connection)
    model.create_database(connection)
    model.fill_database(connection)
    model.delete_task(connection, 1)
    model.delete_task(connection, 4)
    model.delete_task(connection, 100)
    assert model.task(connection, 2) == {
        'id': 2,
        'title': 'faire la vaisselle',
        'description': 'je suis user 2',
        'creation_date': '2020-12-01 00:00:00',
        'due_date': '2020-12-07',
        'id_user': 2
    }
コード例 #14
0
def task_delete(task_id):
    if 'user' not in session:
        return redirect(url_for('login'))
    connection = model.connect()
    model.delete_task(connection, task_id)
    return redirect(url_for('create_task'))
コード例 #15
0
from flask_app import data
from flask_app import model

connection = model.connect()
model.create_database(connection)
model.fill_database(connection)
model.tasks(connection)
model.users(connection)
#liste = model.tasks(connection)
コード例 #16
0
def test_task():
    connection = model.connect(":memory:")
    model.create_database(connection)
    model.fill_database(connection)
    for task in data.tasks():
        assert model.task(connection, task['id']) == task
コード例 #17
0
def test_user():
    connection = model.connect(":memory:")
    model.create_database(connection)
    model.fill_database(connection)
    for user in data.users():
        assert model.user(connection, user['id']) == user
コード例 #18
0
def test_fill_database():
    connection = model.connect(":memory:")
    model.create_database(connection)
    model.fill_database(connection)
    assert model.users(connection) == data.users()
    assert model.tasks(connection) == data.tasks()