@@ -85,14 +85,20 @@ def test_parse_radius_2(radius):
8585
8686
8787def test_send_request_post (monkeypatch ):
88- def mock_post (url , data , timeout , headers = {}):
88+ def mock_post (url , data , timeout , headers = {}, status_code = 200 ):
8989 class SpecialMockResponse (object ):
9090
91- def __init__ (self , url , data , headers ):
91+ def __init__ (self , url , data , headers , status_code ):
9292 self .url = url
9393 self .data = data
9494 self .headers = headers
95- return SpecialMockResponse (url , data , headers = headers )
95+ self .status_code = status_code
96+
97+ def raise_for_status (self ):
98+ pass
99+
100+ return SpecialMockResponse (url , data , headers = headers ,
101+ status_code = status_code )
96102 monkeypatch .setattr (requests , 'post' , mock_post )
97103
98104 response = commons .send_request ('https://github.com/astropy/astroquery' ,
@@ -103,8 +109,10 @@ def __init__(self, url, data, headers):
103109
104110
105111def test_send_request_get (monkeypatch ):
106- def mock_get (url , params , timeout , headers = {}):
112+ def mock_get (url , params , timeout , headers = {}, status_code = 200 ):
107113 req = requests .Request ('GET' , url , params = params , headers = headers ).prepare ()
114+ req .status_code = status_code
115+ req .raise_for_status = lambda : None
108116 return req
109117 monkeypatch .setattr (requests , 'get' , mock_get )
110118 response = commons .send_request ('https://github.com/astropy/astroquery' ,
@@ -113,8 +121,10 @@ def mock_get(url, params, timeout, headers={}):
113121
114122
115123def test_quantity_timeout (monkeypatch ):
116- def mock_get (url , params , timeout , headers = {}):
124+ def mock_get (url , params , timeout , headers = {}, status_code = 200 ):
117125 req = requests .Request ('GET' , url , params = params , headers = headers ).prepare ()
126+ req .status_code = status_code
127+ req .raise_for_status = lambda : None
118128 return req
119129 monkeypatch .setattr (requests , 'get' , mock_get )
120130 response = commons .send_request ('https://github.com/astropy/astroquery' ,
0 commit comments