Exemplo n.º 1
0
def test_get_list_one_elem(one_goal_and_entry_in_db_client):
    """Test listing a database with one element"""

    expected = {
        'data': [{
            'id': 1,
            'goal_id': 1,
            'occurred_date': '2020-03-20'
        }]
    }
    rv = one_goal_and_entry_in_db_client.get('{}/'.format(
        pytest.path_to_goal_entry))

    expected = {
        'data': [{
            'id': 1,
            'name': 'goal1',
            'entries': [{
                'id': 1,
                'occurred_date': '2020-03-20'
            }]
        }]
    }
    rv = one_goal_and_entry_in_db_client.get('{}/'.format(pytest.path_to_goal))
    assert_200_json_response(rv, expected)
Exemplo n.º 2
0
def test_get_item_one_elem(one_goal_and_entry_in_db_client):
    """Test getting the one item of a db with one item"""

    expected = {'data': {'id': 1, 'goal_id': 1, 'occurred_date': '2020-03-20'}}

    rv = one_goal_and_entry_in_db_client.get('{}/1'.format(
        pytest.path_to_goal_entry))
    assert_200_json_response(rv, expected)
Exemplo n.º 3
0
def test_list_item_after_delete(one_in_db_client):
    """Ensure deleting item actually deletes the item"""
    expected_delete_response = {'data': 'success'}
    rv = one_in_db_client.delete('{}/1'.format(pytest.path_to_goal))
    assert_200_json_response(rv, expected_delete_response)

    expected_list_response = {'data': []}
    rv = one_in_db_client.get('{}/'.format(pytest.path_to_goal))
    assert_200_json_response(rv, expected_list_response)
Exemplo n.º 4
0
def test_get_item_after_update(one_in_db_client):
    """Ensure update item actually updates the item"""

    expected_update_response = {'data': 'success'}
    json_in = {'name': 'new'}
    rv = one_in_db_client.put('{}/1'.format(pytest.path_to_goal), json=json_in)
    assert_200_json_response(rv, expected_update_response)

    expected_get_response = {'data': {'id': 1, 'name': 'new', 'entries': []}}
    rv = one_in_db_client.get('{}/1'.format(pytest.path_to_goal))
    assert_200_json_response(rv, expected_get_response)
Exemplo n.º 5
0
def test_get_item_after_update(one_goal_and_entry_in_db_client):
    """Ensure update item actually updates the item"""

    expected_update_response = {'data': 'success'}
    json_in = {'occurred_date': '2020-03-19'}
    rv = one_goal_and_entry_in_db_client.put('{}/1'.format(
        pytest.path_to_goal_entry),
                                             json=json_in)
    assert_200_json_response(rv, expected_update_response)

    expected_get_response = {
        'data': {
            'id': 1,
            'goal_id': 1,
            'occurred_date': '2020-03-19'
        }
    }
    rv = one_goal_and_entry_in_db_client.get('{}/1'.format(
        pytest.path_to_goal_entry))
    assert_200_json_response(rv, expected_get_response)
Exemplo n.º 6
0
def test_get_list_empty_db(client):
    """Test a blank database."""

    expected = {'data': []}
    rv = client.get('{}/'.format(pytest.path_to_goal_entry))
    assert_200_json_response(rv, expected)
Exemplo n.º 7
0
def test_get_item_one_elem(one_in_db_client):
    """Test getting the one item of a db with one item"""

    expected = {'data': {'id': 1, 'name': 'item1', 'entries': []}}
    rv = one_in_db_client.get('{}/1'.format(pytest.path_to_goal))
    assert_200_json_response(rv, expected)
Exemplo n.º 8
0
def test_get_list_one_elem(one_in_db_client):
    """Test listing a database with one element"""

    expected = {'data': [{'id': 1, 'name': 'item1', 'entries': []}]}
    rv = one_in_db_client.get('{}/'.format(pytest.path_to_goal))
    assert_200_json_response(rv, expected)
Exemplo n.º 9
0
def test_insert_into_empty_db(client):
    """Test inserting an item into empty db"""

    expected = {'data': 'success'}
    rv = client.post('{}/'.format(pytest.path_to_goal), json={'name': 'item1'})
    assert_200_json_response(rv, expected)