def edit_api(id, label, url, description=None, tags=None): code = CRUD.editApi(id, label=label, url=url, description=description, tags=tags, commit=True) if code == 0: return { 'status': 'error', 'message': 'API #%d was not found' % id, 'id': id } elif code == -1: return { 'status': 'error', 'message': 'Oooops! Something went wrong while editing API #%d' % id, 'id': id } elif code > 0: return { 'status': 'ok', 'message': 'API #%d was successfully edited' % id, 'id': id }
def test_edit_api_by_id(mock_crud, context_api): print('\n=> Testing editing api by id') id = context_api.get('api_id') label = generate_random_string() url = generate_random_string() description = ' '.join([generate_random_string() for _ in range(5)]) tags = ' '.join([generate_random_string() for _ in range(5)]) code = CRUD.editApi( id, label=label, url=url, description=description, tags=tags ) assert code>0 api = CRUD.getApi(id) assert api.label == label assert api.url == url assert api.description == description assert set(tags.split()) == set([t.text for t in api.tags])