Example #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
Example #2
0
def test_atualizando_uma_tarefa_com_campos_invalidos():
    tarefas.clear()
    tarefas.append({
        'id': 1,
        'titulo': 'titulo',
        'descricao': 'descricao',
        'estado': False
    })
    cliente = app.test_client()
    # sem estado
    resposta = cliente.put('/tarefa/1',
                           data=json.dumps({
                               'titulo': 'titulo atualizado',
                               'decricao': 'descricao atualizada'
                           }),
                           content_type='application/json')
    assert resposta.status_code == 400
    # sem descrição
    resposta = cliente.put('/tarefa/1',
                           data=json.dumps({
                               'titulo': 'titulo atualizado',
                               'estado': False
                           }),
                           content_type='application/json')
    assert resposta.status_code == 400
    # sem titulo
    resposta = cliente.put('/tarefa/1',
                           data=json.dumps({
                               'descricao': 'descricao atualizado',
                               'estado': False
                           }),
                           content_type='application/json')
    assert resposta.status_code == 400
Example #3
0
def test_criar_tarefa_sem_titulo():
    cliente = app.test_client()
    # o código de status deve ser 400 indicando um erro do cliente
    resposta = cliente.post('/task',
                            data=json.dumps({'descricao': 'descricao'}),
                            content_type='application/json')
    assert resposta.status_code == 400
Example #4
0
def test_create_task_should_return_201():
    with app.test_client() as client:
        response = client.post('/tasks', data=json.dumps({
            'title': 'task 1',
            'description': 'my first task'}),
            content_type='application/json')
        assert response.status_code == 201
Example #5
0
def test_create_task_without_title():
    # status code should be 400 indicating client error
    client = app.test_client()
    response = client.post('/task', data=json.dumps({
        'desc': 'descricao'
        }),
        content_type='application/json')
    assert response.status_code == 400
Example #6
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
Example #7
0
def test_lista_de_tarefas_nao_vazia_retorna_conteudo():
    tarefas.append({'id': 1, 'titulo': 'tarefa 1','descricao': 'tarefa de numero 1', 'estado': False})
    with app.test_client() as client:
        response = client.get('/tarefas')
        assert response.data == (b'[\n  {\n    "descricao": '
                                 b'"tarefa de numero 1", \n    '
                                 b'"estado": false, \n    '
                                 b'"id": 1, \n    '
                                 b'"titulo": "tarefa 1"\n  }\n]\n')
Example #8
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
Example #9
0
def test_criar_tarefa_codigo_de_status_retornado_deve_ser_201():
    with app.test_client() as cliente:
        resposta = cliente.post('/task',
                                data=json.dumps({
                                    'titulo': 'titulo',
                                    'descricao': 'descricao'
                                }),
                                content_type='application/json')
        assert resposta.status_code == 201
Example #10
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
Example #11
0
def test_create_task_without_description_must_returns_400():
    with app.test_client() as client:
        import json
        response = client.post('/tasks',
                               data=json.dumps({
                                   'title': 'The Best Title',
                                   'description': None
                               }),
                               content_type='application/json')
        assert response.status_code == 400
Example #12
0
 def setUp(self):
     app.config["TESTING"] = True
     if os.environ.get("CI"):
         app.config["DATABASE"] = "postgresql://ubuntu:@localhost/circle_test"
     else:
         app.config["DATABASE"] = "sqlite://"
     self.app = app.test_client()
     init_db()
     self.context = app.test_request_context()
     self.context.push()
Example #13
0
 def setUp(self):
     app.config["TESTING"] = True
     if os.environ.get("CI"):
         app.config[
             "DATABASE"] = "postgresql://ubuntu:@localhost/circle_test"
     else:
         app.config["DATABASE"] = "sqlite://"
     self.app = app.test_client()
     init_db()
     self.context = app.test_request_context()
     self.context.push()
Example #14
0
def test_criar_tarefa_insere_elemento_no_banco():
    tarefas.clear()
    cliente = app.test_client()
    # realiza a requisição utilizando o verbo POST
    cliente.post('/task',
                 data=json.dumps({
                     'titulo': 'titulo',
                     'descricao': 'descricao'
                 }),
                 content_type='application/json')
    assert len(tarefas) > 0
Example #15
0
def test_remover_tarefa_existente_remove_tarefa_da_lista():
    tarefas.clear()
    tarefas.append({
        'id': 1,
        'titulo': 'titulo',
        'descricao': 'descricao',
        'estado': False
    })
    cliente = app.test_client()
    cliente.delete('/task/1', content_type='application/json')
    assert len(tarefas) == 0
Example #16
0
def test_atualizando_uma_tarefa_nao_existente():
    tarefas.clear()
    cliente = app.test_client()
    resposta = cliente.put('/tarefa/1',
                           data=json.dumps({
                               'titulo': 'titulo atualizado',
                               'decricao': 'descricao atualizada',
                               'estado': True
                           }),
                           content_type='application/json')
    assert resposta.status_code == 404
Example #17
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'
Example #18
0
def test_remover_tarefa_existente_retorna_204():
    tarefas.clear()
    tarefas.append({
        'id': 1,
        'titulo': 'titulo',
        'descricao': 'descricao',
        'estado': False
    })
    cliente = app.test_client()
    resposta = cliente.delete('/task/1', content_type='application/json')
    assert resposta.status_code == 204
    assert resposta.data == b''
Example #19
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
Example #20
0
    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, "postgresql:///todo_test")

        # Create tables in testdb
        db.create_all()
        load_example_data()
Example #21
0
def test_list_tasks_not_empty():
    tasks.append({
        'id': 1,
        'title': 'tarefa 1',
        'desc': 'primeira tarefa',
        'state': False
        })
    with app.test_client() as client:
        response = client.get('/task')
        assert response.data == (b'[{"desc":"primeira tarefa",'
                                 b'"id":1,'
                                 b'"state":false,'
                                 b'"title":"tarefa 1"}]\n')
Example #22
0
def test_create_task_must_returns_201_status_code():
    with app.test_client() as client:
        import json
        response = client.post('/tasks',
                               data=json.dumps({
                                   'title':
                                   'The Incredible Title',
                                   'description':
                                   'The Incredible Description'
                               }),
                               content_type='application/json')

        assert response.status_code == 201
Example #23
0
def test_lista_de_tarefas_nao_vazia_retorna_conteudo():
    tarefas.append({
        'id': 1,
        'titulo': 'tarefa 1',
        'descricao': 'tarefa de numero 1',
        'estado': False
    })
    with app.test_client() as cliente:
        resposta = cliente.get('/task')
        assert resposta.data == (b'[{"descricao":'
                                 b'"tarefa de numero 1",'
                                 b'"estado":false,'
                                 b'"id":1,'
                                 b'"titulo":"tarefa 1"}]\n')
Example #24
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
Example #25
0
def test_retrieve_task_by_id_must_returns_json():
    with app.test_client() as client:
        import json
        response = client.post('/tasks',
                               data=json.dumps({
                                   'title':
                                   'The Awesome Title',
                                   'description':
                                   'The Awesome Description'
                               }),
                               content_type='application/json')

        data = json.loads(response.data.decode('utf-8'))
        inserted_id = data['_id']['$oid']
        response = client.get('/tasks/%s' % inserted_id)
        assert response.content_type == 'application/json'
Example #26
0
def test_create_task_returns_created_task():
    with app.test_client() as client:
        import json
        response = client.post('/tasks',
                               data=json.dumps({
                                   'title':
                                   'The Best Title',
                                   'description':
                                   'The Best Description'
                               }),
                               content_type='application/json')

        data = json.loads(response.data.decode('utf-8'))
        assert data['title'] == 'The Best Title'
        assert data['description'] == 'The Best Description'
        assert data['done'] == False
Example #27
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
Example #28
0
def test_detalhar_tarefa_existente():
    tarefas.clear()
    tarefas.append({
        'id': 1,
        'titulo': 'titulo',
        'descricao': 'descricao',
        'entregue': False
    })
    cliente = app.test_client()
    resposta = cliente.get('/task/1', content_type='application/json')
    data = json.loads(resposta.data.decode('utf-8'))
    assert resposta.status_code == 200
    assert data['id'] == 1
    assert data['titulo'] == 'titulo'
    assert data['descricao'] == 'descricao'
    assert data['entregue'] is False
Example #29
0
def test_criar_tarefa_retorna_tarefa_inserida():
    tarefas.clear()
    cliente = app.test_client()
    # realiza a requisição utilizando o verbo POST
    resposta = cliente.post('/task',
                            data=json.dumps({
                                'titulo': 'titulo',
                                'descricao': 'descricao'
                            }),
                            content_type='application/json')
    # é realizada a análise e transformação para objeto python da resposta
    data = json.loads(resposta.data.decode('utf-8'))
    assert data['id'] == 1
    assert data['titulo'] == 'titulo'
    assert data['descricao'] == 'descricao'
    # qaundo a comparação é com True, False ou None, utiliza-se o "is"
    assert data['estado'] is False
Example #30
0
def test_listar_tarefas_deve_apresentar_tarefas_nao_finalizadas_primeiro():
    tarefas.clear()
    tarefas.append({
        'id': 1,
        'titulo': 'tarefa 1',
        'descricao': 'tarefa de numero 1',
        'estado': True
    })
    tarefas.append({
        'id': 2,
        'titulo': 'tarefa 2',
        'descricao': 'tarefa de numero 2',
        'estado': False
    })
    with app.test_client() as cliente:
        resposta = cliente.get('/task')
        data = json.loads(resposta.data.decode('utf-8'))
        primeira_task, segunda_task = data
        assert primeira_task['titulo'] == 'tarefa 2'
        assert segunda_task['titulo'] == 'tarefa 1'
Example #31
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
Example #32
0
 def setUp(self):
     self.app = app.test_client()