Beispiel #1
0
def test_get(client):
    """
    tests get method for endpoint /api/v1/todos

    from file load dummy data and insert to test database
    and then test_client performs get request to endpoint
    assert response from endpoint is what is expected:
    response body is correct json content
    and that response status code is 200

    :param client: Flask test_client
    :type client: object
    """
    try:
        file = open('mock/todos.json', 'r')
    except FileNotFoundError:
        file = open('../mock/todos.json', 'r')

    data = json.loads(file.read())

    with db.atomic():
        Todo.insert_many(data).execute()

    rv = client.get('/api/v1/todos')
    json_data = rv.get_json()
    assert json_data == [{
        'id': 1,
        'name': 'clean the house'
    }, {
        'id': 2,
        'name': 'water the dog'
    }, {
        'id': 3,
        'name': 'feed the lawn'
    }, {
        'id': 4,
        'name': 'pay dem bills'
    }, {
        'id': 5,
        'name': 'run'
    }, {
        'id': 6,
        'name': 'swim'
    }]

    assert rv.status_code == 200