def test_update_observation_not_mine(requests_mock): """When we try to update the obs of another user, iNat returns an error 410 with 'obs does not longer exists'.""" requests_mock.put( f'{API_V0_BASE_URL}/observations/16227955.json', json={'error': 'Cette observation n’existe plus.'}, status_code=410, ) params = { 'ignore_photos': 1, 'description': 'updated description v2 !', } with pytest.raises(HTTPError) as excinfo: update_observation(16227955, access_token='valid token for another user', **params) assert excinfo.value.response.status_code == 410 assert excinfo.value.response.json() == { 'error': 'Cette observation n’existe plus.' }
def test_update_nonexistent_observation(requests_mock): """When we try to update a non-existent observation, iNat returns an error 410 with 'observation does not exist' """ requests_mock.put( f'{API_V0_BASE_URL}/observations/999999999.json', json={'error': 'Cette observation n’existe plus.'}, status_code=410, ) params = { 'ignore_photos': 1, 'description': 'updated description v2 !', } with pytest.raises(HTTPError) as excinfo: update_observation(999999999, access_token='valid token', **params) assert excinfo.value.response.status_code == 410 assert excinfo.value.response.json() == { 'error': 'Cette observation n’existe plus.' }
def test_update_observation(requests_mock): requests_mock.put( f'{API_V0_BASE_URL}/observations/17932425.json', json=load_sample_data('update_observation_result.json'), status_code=200, ) params = { 'ignore_photos': 1, 'description': 'updated description v2 !', } response = update_observation(17932425, access_token='valid token', **params) # If all goes well we got a single element representing the updated observation, enclosed in a list. assert len(response) == 1 assert response[0]['id'] == 17932425 assert response[0]['description'] == 'updated description v2 !'
def test_update_observation__with_sounds(put, mock_upload_sounds): update_observation(1234, access_token='token', sounds='photo.jpg') request_params = put.call_args[1]['json']['observation'] assert 'sounds' not in request_params mock_upload_sounds.assert_called_once()