Exemple #1
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'
Exemple #2
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]]
Exemple #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'
Exemple #4
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'
Exemple #5
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'
Exemple #6
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': '*****@*****.**'}
Exemple #7
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'
Exemple #8
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]]
Exemple #9
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'
Exemple #10
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
    }
Exemple #11
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)
Exemple #12
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
Exemple #13
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
Exemple #14
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()