@@ -94,6 +94,117 @@ def test_hgs2hpc(client: TestClient):
9494 assert data ["detail" ][0 ]["loc" ][1 ] == "lat"
9595
9696
97+ def test_hgs2hpc_post (client : TestClient ):
98+ """
99+ Test POST /hgs2hpc endpoint with batch coordinate conversion
100+ """
101+ # Test valid batch request
102+ batch_data = {
103+ "coordinates" : [
104+ {"lat" : 0.0 , "lon" : 0.0 , "coord_time" : "2012-01-01T00:00:00Z" },
105+ {"lat" : 10.0 , "lon" : 20.0 , "coord_time" : "2012-01-01T00:00:00Z" },
106+ ],
107+ "target" : "2012-01-01T00:00:00Z" ,
108+ }
109+ response = client .post ("/hgs2hpc" , json = batch_data )
110+ assert response .status_code == 200
111+ data = response .json ()
112+ assert "coordinates" in data
113+ assert len (data ["coordinates" ]) == 2
114+ assert pytest .approx (data ["coordinates" ][0 ]["x" ], abs = 0.1 ) == 0
115+ assert pytest .approx (data ["coordinates" ][0 ]["y" ], abs = 50 ) == 49.558
116+ assert pytest .approx (data ["coordinates" ][1 ]["x" ], abs = 0.1 ) == 324.471
117+ assert pytest .approx (data ["coordinates" ][1 ]["y" ], abs = 50 ) == 212.902
118+
119+ # Test with differential rotation (target time different from coord_time)
120+ batch_data = {
121+ "coordinates" : [
122+ {"lat" : 0.0 , "lon" : 0.0 , "coord_time" : "2012-01-01T00:00:00Z" },
123+ ],
124+ "target" : "2012-01-01T01:00:00Z" ,
125+ }
126+ response = client .post ("/hgs2hpc" , json = batch_data )
127+ assert response .status_code == 200
128+ data = response .json ()
129+ assert len (data ["coordinates" ]) == 1
130+ # The x coordinate should move approximately 9 arcseconds
131+ assert 9 < data ["coordinates" ][0 ]["x" ] and data ["coordinates" ][0 ]["x" ] < 10
132+
133+ # Test missing coordinates field
134+ response = client .post ("/hgs2hpc" , json = {"target" : "2012-01-01T00:00:00Z" })
135+ assert response .status_code == 422
136+
137+ # Test missing target field
138+ response = client .post (
139+ "/hgs2hpc" ,
140+ json = {
141+ "coordinates" : [
142+ {"lat" : 0.0 , "lon" : 0.0 , "coord_time" : "2012-01-01T00:00:00Z" }
143+ ]
144+ },
145+ )
146+ assert response .status_code == 422
147+
148+ # Test invalid latitude (> 90)
149+ batch_data = {
150+ "coordinates" : [
151+ {"lat" : 90.1 , "lon" : 0.0 , "coord_time" : "2012-01-01T00:00:00Z" }
152+ ],
153+ "target" : "2012-01-01T00:00:00Z" ,
154+ }
155+ response = client .post ("/hgs2hpc" , json = batch_data )
156+ assert response .status_code == 422
157+ data = response .json ()
158+ assert data ["detail" ][0 ]["loc" ][- 1 ] == "lat"
159+
160+ # Test invalid latitude (< -90)
161+ batch_data = {
162+ "coordinates" : [
163+ {"lat" : - 90.1 , "lon" : 0.0 , "coord_time" : "2012-01-01T00:00:00Z" }
164+ ],
165+ "target" : "2012-01-01T00:00:00Z" ,
166+ }
167+ response = client .post ("/hgs2hpc" , json = batch_data )
168+ assert response .status_code == 422
169+ data = response .json ()
170+ assert data ["detail" ][0 ]["loc" ][- 1 ] == "lat"
171+
172+ # Test invalid time format
173+ batch_data = {
174+ "coordinates" : [{"lat" : 0.0 , "lon" : 0.0 , "coord_time" : "NotAValidTime" }],
175+ "target" : "2012-01-01T00:00:00Z" ,
176+ }
177+ response = client .post ("/hgs2hpc" , json = batch_data )
178+ assert response .status_code == 422
179+
180+ # Test empty coordinates array
181+ batch_data = {"coordinates" : [], "target" : "2012-01-01T00:00:00Z" }
182+ response = client .post ("/hgs2hpc" , json = batch_data )
183+ assert response .status_code == 200
184+ data = response .json ()
185+ assert len (data ["coordinates" ]) == 0
186+
187+ # Test multiple coordinates with different coord_times
188+ batch_data = {
189+ "coordinates" : [
190+ {"lat" : 11.0 , "lon" : 21.0 , "coord_time" : "2024-01-01T00:00:00" },
191+ {"lat" : 15.0 , "lon" : 26.0 , "coord_time" : "2025-01-01T00:00:00" },
192+ {"lat" : 11.0 , "lon" : 21.0 , "coord_time" : "2022-01-01T00:00:00" },
193+ ],
194+ "target" : "2024-01-02T00:00:00" ,
195+ }
196+ response = client .post ("/hgs2hpc" , json = batch_data )
197+ assert response .status_code == 200
198+ data = response .json ()
199+ assert len (data ["coordinates" ]) == 3
200+ # Verify all coordinates have x and y values
201+ for coord in data ["coordinates" ]:
202+ assert "x" in coord
203+ assert "y" in coord
204+ assert isinstance (coord ["x" ], (int , float ))
205+ assert isinstance (coord ["y" ], (int , float ))
206+
207+
97208def test_healthcheck (client : TestClient ):
98209 assert client .get ("/health-check" ).text == '"success"'
99210
@@ -145,7 +256,7 @@ def test_gse_errors(client: TestClient):
145256 assert response .status_code == 422
146257
147258 # Test invalid JSON
148- response = client .post ("/gse2frame" , data = b"invalid json" )
259+ response = client .post ("/gse2frame" , content = b"invalid json" )
149260 assert response .status_code == 422
150261
151262 # Test missing required field
0 commit comments