vendredi 30 mars 2018

Patterns for save data between tests in a sequence of test

Which patterns can I use for API testing when I need to get some data and use it in other requests?

Next case for example:

def test_item_get():
    r = get_json('/item')
    assert r.status_code == 200


def test_item_update():
    r = get_json('/item')
    assert r.status_code == 200

    item_uuid = r.json[0]['uuid']
    assert is_uuid(item_uuid)

    r = put_json('/item/{}'.format(item_uuid), {'description': 'New desc'})
    assert r.status_code == 200


def test_item_manager():
    r = get_json('/item')
    assert r.status_code == 200

    item_uuid = r.json[0]['uuid']
    assert is_uuid(item_uuid)

    r = put_json('/item/{}'.format(item_uuid), {'description': 'New desc'})
    assert r.status_code == 200

    r = get_json('/item/{}'.format(item_uuid))
    assert r.status_code == 200
    assert r.json['description'] = 'New desc'

    r = delete_json('/item/{}'.format(item_uuid))
    assert r.status_code == 200
    assert r.json['result'] == True

    r = delete_json('/item/{}'.format(item_uuid))
    assert r.status_code == 404

It looks like I should to divide the test_item_manager into smaller parts, but I'm not sure which way to choose.

Perfectly, if there are ways with pytest or unittest, but other testing modules or even a link to the source code with the solution of similar tasks will be nice.

Aucun commentaire:

Enregistrer un commentaire