Exemple #1
0
def test_update_task_with_invalide_fields():
        tasks.clear()
        tasks.append({
                'id': 1,
                'title': 'task 1',
                'description': 'my first task',
                'status': False
        })
        client = app.test_client()
        # without status
        response = client.put('/tasks/1', data=json.dumps({
                'title': 'updated title',
                'description': 'updated description'
                }
        ), content_type='application/json')
        assert response.status_code == 400
        # without title
        response = client.put('/tasks/1', data=json.dumps({
                'description': 'updated description',
                'status': True
                }
        ), content_type='application/json')
        assert response.status_code == 400
        # without description
        response = client.put('/tasks/1', data=json.dumps({
                'title': 'updated title',
                'status': True
                }
        ), content_type='application/json')
        assert response.status_code == 400
Exemple #2
0
def test_create_task_insert_entry_database():
    tasks.clear()
    client = app.test_client()
    client.post('/tasks', data=json.dumps({
            'title': 'task 1',
            'description': 'my first task'}),
            content_type='application/json')
    assert len(tasks) > 0
Exemple #3
0
def test_create_task_adds_to_database():
    tasks.clear()
    client = app.test_client()
    # realiza a requisição utilizando o verbo POST
    client.post('/task', data=json.dumps({
        'title': 'titulo',
        'desc': 'descricao'}),
        content_type='application/json')
    assert len(tasks) > 0
Exemple #4
0
def test_updating_nonexiting_task():
        tasks.clear()
        client = app.test_client()
        response = client.put('/tasks/1', data=json.dumps({
                'title': 'updated title',
                'description': 'updated description',
                'status': True
                }
        ), content_type='application/json')
        assert response.status_code == 404
Exemple #5
0
def test_create_task_returns_new_task():
    tasks.clear()
    client = app.test_client()
    response = client.post('/tasks', data=json.dumps({
        'title': 'task 1',
        'description': 'my first task'}),
        content_type='application/json')
    data = json.loads(response.data.decode('utf-8'))
    assert data['id'] == 1
    assert data['title'] == 'task 1'
    assert data['description'] == 'my first task'
    assert data['status'] is False
Exemple #6
0
def test_list_tasks_show_not_finished_first():
    tasks.clear()
    tasks.append({'id': 1, 'title': 'tarefa 1', 'desc': 'tarefa de numero 1',
                    'state': True})
    tasks.append({'id': 2, 'title': 'tarefa 2', 'desc': 'tarefa de numero 2',
                    'state': False})
    with app.test_client() as client:
        response = client.get('/task')
        data = json.loads(response.data.decode('utf-8'))
        primeira_task, segunda_task = data
        assert primeira_task['title'] == 'tarefa 2'
        assert segunda_task['title'] == 'tarefa 1'
Exemple #7
0
def test_create_task_return():
    tasks.clear()
    client = app.test_client()
    response = client.post('/task', data=json.dumps({
        'title': 'titulo',
        'desc': 'descricao'
        }),
        content_type='application/json')
    data = json.loads(response.data.decode('utf-8'))
    assert data['id'] == 1
    assert data['title'] == 'titulo'
    assert data['desc'] == 'descricao'
    assert data['state'] is False
    assert response.status_code == 201
Exemple #8
0
def test_detail_existing_task():
        tasks.clear()
        tasks.append({
                'id': 1,
                'title': 'task 1',
                'description': 'my first task',
                'status': False
        })
        client = app.test_client()
        response = client.get('/tasks/1', content_type='application/json')
        data = json.loads(response.data.decode('utf-8'))
        assert response.status_code == 200
        assert data['id'] == 1
        assert data['title'] == 'task 1'
        assert data['description'] == 'my first task'
        assert data['status'] is False
Exemple #9
0
def test_updating_exiting_task():
        tasks.clear()
        tasks.append({
                'id': 1,
                'title': 'task 1',
                'description': 'my first task',
                'status': False
        })
        client = app.test_client()
        response = client.put('/tasks/1', data=json.dumps({
                'title': 'updated title',
                'description': 'updated description',
                'status': True
                }
        ), content_type='application/json')
        data = json.loads(response.data.decode('utf-8'))
        assert response.status_code == 200
        assert data['id'] == 1
        assert data['title'] == 'updated title'
        assert data['description'] == 'updated description'
        assert data['status'] is True
Exemple #10
0
def test_detail_nonexisting_task():
        tasks.clear()
        client = app.test_client()
        response = client.get('/tasks/1', content_type='application/json')
        assert response.status_code == 404