1
0
Fork 0

Require NORAD ID or Satellite ID for Telemetry API

Signed-off-by: Alfredos-Panagiotis Damkalis <fredy@fredy.gr>
spacecruft
Alfredos-Panagiotis Damkalis 2022-06-14 01:39:00 +03:00
parent 3b98e66dc8
commit a13e2a0392
2 changed files with 29 additions and 5 deletions

View File

@ -235,19 +235,24 @@ class LoginView(TestCase):
datum = None
def setUp(self):
# pagination is set to 25 per page
DemodDataFactory.create_batch(size=18)
self.datum = DemodDataFactory()
self.datum.save()
self.client.force_login(User.objects.get_or_create(username='testuser')[0])
def test_auth_telemetry_list_pg1(self):
def test_auth_telemetry_list_without_filter(self):
"""Test the Telemetry API listing and pagination with authentication"""
response = self.client.get('/api/telemetry/?page=1')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_auth_telemetry_list_with_satellite_filter(self):
"""Test the Telemetry API listing and pagination with authentication"""
norad_id = self.datum.satellite.satellite_entry.norad_cat_id
response = self.client.get('/api/telemetry/?page=1&satellite=' + str(norad_id))
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_auth_telemetry_list_pg2(self):
def test_auth_telemetry_list_with_sat_id_filter(self):
"""Test the Telemetry API listing and pagination with authentication"""
DemodDataFactory.create_batch(size=25)
response = self.client.get('/api/telemetry/?page=2&format=json')
sat_id = self.datum.satellite.satellite_identifier.sat_id
response = self.client.get('/api/telemetry/?page=1&sat_id=' + sat_id)
self.assertEqual(response.status_code, status.HTTP_200_OK)

View File

@ -527,6 +527,25 @@ class TelemetryViewSet( # pylint: disable=R0901,R0912,R0915
pagination_class = pagination.LinkedHeaderPageNumberPagination
def list(self, request, *args, **kwargs):
"""
Lists data from satellite if they are filtered by NORAD ID or Satellite ID. Also logs the
requests if it is set to do so.
"""
satellite = request.query_params.get('satellite', None)
sat_id = request.query_params.get('sat_id', None)
if not (satellite or sat_id):
data = {
'detail': (
'For getting data please use either satellite(NORAD ID) filter or'
'sat_id(Satellite ID) filter'
),
'results': None
}
response = Response(data, status=status.HTTP_400_BAD_REQUEST)
response.exception = True
return response
if settings.LOG_TELEMETRY_REQUESTS:
user_id = str(request.user.id)
remote_address = str(request.META.get("REMOTE_ADDR"))