Skip to content

Commit

Permalink
Deprecate astroquery.utils.commons.send_request
Browse files Browse the repository at this point in the history
It is deprecated in favour of `astroquery.query.BaseQuery._request()`.
  • Loading branch information
eerovaher committed Sep 29, 2021
1 parent 241d896 commit 910791c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion astroquery/utils/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import astropy.units as u
from astropy import coordinates as coord
from collections import OrderedDict
from astropy.utils import minversion
from astropy.utils import deprecated, minversion
import astropy.utils.data as aud
from astropy.io import fits, votable

Expand Down Expand Up @@ -60,6 +60,7 @@ def FK4CoordGenerator(*args, **kwargs):
ASTROPY_LT_4_3 = not minversion('astropy', '4.3')


@deprecated('0.4.4', alternative='astroquery.query.BaseQuery._request')
def send_request(url, data, timeout, request_type='POST', headers={},
**kwargs):
"""
Expand Down
22 changes: 14 additions & 8 deletions astroquery/utils/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import astropy.units as u
from astropy.table import Table
import astropy.utils.data as aud
from astropy.utils.exceptions import AstropyDeprecationWarning

from ...utils import chunk_read, chunk_report, class_or_instance, commons
from ...utils.process_asyncs import async_to_sync_docstr, async_to_sync
Expand Down Expand Up @@ -96,8 +97,9 @@ def raise_for_status(self):
status_code=status_code)
monkeypatch.setattr(requests, 'post', mock_post)

response = commons.send_request('https://github.com/astropy/astroquery',
data=dict(msg='ok'), timeout=30)
with pytest.warns(AstropyDeprecationWarning):
response = commons.send_request('https://github.com/astropy/astroquery',
data=dict(msg='ok'), timeout=30)
assert response.url == 'https://github.com/astropy/astroquery'
assert response.data == dict(msg='ok')
assert 'astroquery' in response.headers['User-Agent']
Expand All @@ -112,8 +114,9 @@ def mock_get(url, params, timeout, headers={}, status_code=200):
req.raise_for_status = lambda: None
return req
monkeypatch.setattr(requests, 'get', mock_get)
response = commons.send_request('https://github.com/astropy/astroquery',
dict(a='b'), 60, request_type='GET')
with pytest.warns(AstropyDeprecationWarning):
response = commons.send_request('https://github.com/astropy/astroquery',
dict(a='b'), 60, request_type='GET')
assert response.url == 'https://github.com/astropy/astroquery?a=b'


Expand All @@ -125,15 +128,18 @@ def mock_get(url, params, timeout, headers={}, status_code=200):
req.raise_for_status = lambda: None
return req
monkeypatch.setattr(requests, 'get', mock_get)
response = commons.send_request('https://github.com/astropy/astroquery',
dict(a='b'), 1 * u.min, request_type='GET')
with pytest.warns(AstropyDeprecationWarning):
response = commons.send_request('https://github.com/astropy/astroquery',
dict(a='b'), 1 * u.min,
request_type='GET')
assert response.url == 'https://github.com/astropy/astroquery?a=b'


def test_send_request_err():
with pytest.raises(ValueError):
commons.send_request('https://github.com/astropy/astroquery',
dict(a='b'), 60, request_type='PUT')
with pytest.warns(AstropyDeprecationWarning):
commons.send_request('https://github.com/astropy/astroquery',
dict(a='b'), 60, request_type='PUT')


col_1 = [1, 2, 3]
Expand Down

0 comments on commit 910791c

Please sign in to comment.