149 lines
4.8 KiB
Python
149 lines
4.8 KiB
Python
"""SatNOGS DB API test suites"""
|
|
import pytest
|
|
from django.test import TestCase
|
|
from rest_framework import status
|
|
|
|
from db.base.tests import DemodDataFactory, ModeFactory, SatelliteFactory, TransmitterFactory
|
|
|
|
|
|
@pytest.mark.django_db(transaction=True)
|
|
class ModeViewApiTest(TestCase):
|
|
"""
|
|
Tests the Mode View API
|
|
"""
|
|
mode = None
|
|
|
|
def setUp(self):
|
|
self.mode = ModeFactory()
|
|
self.mode.save()
|
|
|
|
def test_list(self):
|
|
"""Test the API modes list"""
|
|
response = self.client.get('/api/modes/', format='json')
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
def test_retrieve(self):
|
|
"""Test the API mode retrieval"""
|
|
response = self.client.get('/api/modes/{0}/'.format(self.mode.id), format='json')
|
|
self.assertContains(response, self.mode.name)
|
|
|
|
|
|
@pytest.mark.django_db(transaction=True)
|
|
class SatelliteViewApiTest(TestCase):
|
|
"""
|
|
Tests the Satellite View API
|
|
"""
|
|
satellite = None
|
|
|
|
def setUp(self):
|
|
self.satellite = SatelliteFactory()
|
|
self.satellite.save()
|
|
|
|
def test_list(self):
|
|
"""Test the Satellite API listing"""
|
|
response = self.client.get('/api/satellites/', format='json')
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
def test_retrieve_with_norad_id(self):
|
|
"""Test the Satellite API retrieval with NORAD ID"""
|
|
response = self.client.get(
|
|
'/api/satellites/{0}/'.format(self.satellite.satellite_entry.norad_cat_id),
|
|
format='json'
|
|
)
|
|
self.assertContains(response, self.satellite.satellite_entry.name)
|
|
|
|
def test_retrieve_with_satellite_id(self):
|
|
"""Test the Satellite API retrieval with Satellite Identifier"""
|
|
response = self.client.get(
|
|
'/api/satellites/{0}/'.format(self.satellite.satellite_identifier.sat_id),
|
|
format='json'
|
|
)
|
|
self.assertContains(response, self.satellite.satellite_entry.name)
|
|
|
|
|
|
@pytest.mark.django_db(transaction=True)
|
|
class TransmitterViewApiTest(TestCase):
|
|
"""
|
|
Tests the Transmitter View API
|
|
"""
|
|
transmitter = None
|
|
|
|
def setUp(self):
|
|
self.transmitter = TransmitterFactory()
|
|
self.transmitter.uuid = 'test'
|
|
self.transmitter.save()
|
|
|
|
def test_list(self):
|
|
"""Test the Transmitter API listing"""
|
|
response = self.client.get('/api/transmitters/', format='json')
|
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
|
|
|
def test_retrieve(self):
|
|
"""Test the Transmitter API retrieval"""
|
|
response = self.client.get(
|
|
'/api/transmitters/{0}/'.format(self.transmitter.uuid), format='json'
|
|
)
|
|
self.assertContains(response, self.transmitter.description)
|
|
|
|
|
|
@pytest.mark.django_db(transaction=True)
|
|
@pytest.mark.usefixtures('celery_session_app')
|
|
@pytest.mark.usefixtures('celery_session_worker')
|
|
class TelemetryViewApiTest(TestCase):
|
|
"""
|
|
Tests the Telemetry View API
|
|
"""
|
|
datum = None
|
|
satellite = None
|
|
|
|
def setUp(self):
|
|
self.datum = DemodDataFactory()
|
|
self.datum.save()
|
|
self.satellite = SatelliteFactory()
|
|
self.satellite.save()
|
|
|
|
def test_list(self):
|
|
"""Test the Telemetry API listing"""
|
|
response = self.client.get('/api/telemetry/', format='json')
|
|
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
|
|
|
def test_retrieve(self):
|
|
"""Test the Telemetry API retrieval"""
|
|
response = self.client.get('/api/telemetry/{0}/'.format(self.datum.id), format='json')
|
|
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
|
|
|
def test_post(self):
|
|
"""Test the SiDS posting capability"""
|
|
norad = self.satellite.satellite_entry.norad_cat_id
|
|
frame = '60A060A0A46E609C8262A6A640E082A0A4A682A86103F02776261C6C201C5'
|
|
frame += '3495D41524953532D496E7465726E6174696F6E616C2053706163652053746174696F6E3D0D'
|
|
|
|
data = {
|
|
'frame': frame,
|
|
'locator': 'longLat',
|
|
'latitude': '06.12S',
|
|
'longitude': '59.34W',
|
|
'noradID': str(norad),
|
|
'source': 'T3ST',
|
|
'timestamp': '2021-03-15T13:14:04.940Z',
|
|
'version': '1.2.3'
|
|
}
|
|
response = self.client.post('/api/telemetry/', data=data)
|
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
|
|
|
def test_bad_post(self):
|
|
"""Test the SiDS posting capability with bad data"""
|
|
norad = self.satellite.satellite_entry.norad_cat_id
|
|
|
|
data = {
|
|
'frame': '',
|
|
'locator': 'longLat',
|
|
'latitude': '206.12S',
|
|
'longitude': '59.34WE',
|
|
'noradID': str(norad),
|
|
'source': '',
|
|
'timestamp': ''
|
|
}
|
|
response = self.client.post('/api/telemetry/', data=data)
|
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|