1+ import base64
2+
13import numpy as np
24import pytest
3- import scipy .integrate
45import requests
5- import base64
6-
6+ import scipy .integrate
77
88from rocketpy import Function , Motor
99
@@ -215,6 +215,7 @@ def test_load_from_rse_file(generic_motor):
215215 assert thrust_curve [- 1 ][0 ] == 2.2 # Last point of time
216216 assert thrust_curve [- 1 ][1 ] == 0.0 # Last thrust point
217217
218+
218219def test_load_from_thrustcurve_api (monkeypatch , generic_motor ):
219220 """
220221 Tests the GenericMotor.load_from_thrustcurve_api method with mocked ThrustCurve API responses.
@@ -224,7 +225,7 @@ def test_load_from_thrustcurve_api(monkeypatch, generic_motor):
224225 The pytest monkeypatch fixture for mocking.
225226 generic_motor : rocketpy.GenericMotor
226227 The GenericMotor object to be used in the tests.
227-
228+
228229 """
229230
230231 class MockResponse :
@@ -299,3 +300,57 @@ def mock_get(url, params=None):
299300 assert motor .thrust .y_array == pytest .approx (
300301 Function (points , "Time (s)" , "Thrust (N)" , "linear" , "zero" ).y_array
301302 )
303+
304+ # 1. No motor found
305+ def mock_get_no_motor (url , params = None ):
306+ if "search.json" in url :
307+ return MockResponse ({"results" : []})
308+ return MockResponse ({"results" : []})
309+
310+ monkeypatch .setattr (requests , "get" , mock_get_no_motor )
311+ with pytest .raises (ValueError , match = "No motor found" ):
312+ type (generic_motor ).load_from_thrustcurve_api ("NonexistentMotor" )
313+
314+ # 2. No .eng file found
315+ def mock_get_no_eng (url , params = None ):
316+ if "search.json" in url :
317+ return MockResponse (
318+ {
319+ "results" : [
320+ {
321+ "motorId" : "123" ,
322+ "designation" : "Fake" ,
323+ "manufacturer" : "Test" ,
324+ }
325+ ]
326+ }
327+ )
328+ elif "download.json" in url :
329+ return MockResponse ({"results" : []})
330+ return MockResponse ({})
331+
332+ monkeypatch .setattr (requests , "get" , mock_get_no_eng )
333+ with pytest .raises (ValueError , match = "No .eng file found" ):
334+ type (generic_motor ).load_from_thrustcurve_api ("FakeMotor" )
335+
336+ # 3. Empty .eng data
337+ def mock_get_empty_data (url , params = None ):
338+ if "search.json" in url :
339+ return MockResponse (
340+ {
341+ "results" : [
342+ {
343+ "motorId" : "123" ,
344+ "designation" : "Fake" ,
345+ "manufacturer" : "Test" ,
346+ }
347+ ]
348+ }
349+ )
350+ elif "download.json" in url :
351+ return MockResponse ({"results" : [{"data" : "" }]})
352+ return MockResponse ({})
353+
354+ monkeypatch .setattr (requests , "get" , mock_get_empty_data )
355+ with pytest .raises (ValueError , match = "Downloaded .eng data" ):
356+ type (generic_motor ).load_from_thrustcurve_api ("FakeMotor" )
0 commit comments