2017-01-03 02:25:00 -07:00
|
|
|
import json
|
|
|
|
|
|
|
|
from django.test import TestCase
|
2018-04-01 05:52:20 -06:00
|
|
|
from rest_framework.utils.encoders import JSONEncoder
|
|
|
|
|
2019-09-23 05:08:11 -06:00
|
|
|
import pytest
|
|
|
|
from network.base.tests import AntennaFactory, ObservationFactory, \
|
|
|
|
SatelliteFactory, StationFactory
|
2017-01-03 02:25:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.django_db(transaction=True)
|
|
|
|
class JobViewApiTest(TestCase):
|
|
|
|
"""
|
|
|
|
Tests the Job View API
|
|
|
|
"""
|
2017-09-11 04:33:49 -06:00
|
|
|
observation = None
|
2017-01-03 02:25:00 -07:00
|
|
|
satellites = []
|
|
|
|
stations = []
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
for x in xrange(1, 10):
|
|
|
|
self.satellites.append(SatelliteFactory())
|
|
|
|
for x in xrange(1, 10):
|
|
|
|
self.stations.append(StationFactory())
|
2017-09-11 04:33:49 -06:00
|
|
|
self.observation = ObservationFactory()
|
2017-01-03 02:25:00 -07:00
|
|
|
|
|
|
|
def test_job_view_api(self):
|
|
|
|
response = self.client.get('/api/jobs/')
|
|
|
|
response_json = json.loads(response.content)
|
2017-01-08 07:25:47 -07:00
|
|
|
self.assertEqual(response_json, [])
|
2017-01-03 02:25:00 -07:00
|
|
|
|
|
|
|
|
2018-04-01 05:52:20 -06:00
|
|
|
@pytest.mark.django_db(transaction=True)
|
|
|
|
class StationViewApiTest(TestCase):
|
|
|
|
"""
|
|
|
|
Tests the Station View API
|
|
|
|
"""
|
|
|
|
station = None
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.antenna = AntennaFactory()
|
|
|
|
self.encoder = JSONEncoder()
|
|
|
|
self.station = StationFactory.create(antennas=[self.antenna])
|
|
|
|
|
|
|
|
def test_station_view_api(self):
|
|
|
|
|
|
|
|
ants = self.station.antenna.all()
|
2018-08-24 08:14:24 -06:00
|
|
|
ser_ants = [{u'band': ant.band,
|
|
|
|
u'frequency': ant.frequency,
|
|
|
|
u'frequency_max': ant.frequency_max,
|
|
|
|
u'antenna_type': ant.antenna_type} for ant in ants]
|
2018-04-01 05:52:20 -06:00
|
|
|
|
|
|
|
station_serialized = {
|
|
|
|
u'altitude': self.station.alt,
|
|
|
|
u'antenna': ser_ants,
|
2018-10-01 06:24:48 -06:00
|
|
|
u'client_version': self.station.client_version,
|
2018-04-01 05:52:20 -06:00
|
|
|
u'created': self.encoder.default(self.station.created),
|
|
|
|
u'description': self.station.description,
|
|
|
|
u'id': self.station.id,
|
|
|
|
u'last_seen': self.encoder.default(self.station.last_seen),
|
|
|
|
u'lat': self.station.lat,
|
|
|
|
u'lng': self.station.lng,
|
|
|
|
u'location': self.station.location,
|
|
|
|
u'min_horizon': self.station.horizon,
|
|
|
|
u'name': self.station.name,
|
|
|
|
u'observations': 0,
|
|
|
|
u'qthlocator': self.station.qthlocator,
|
2019-02-07 11:06:39 -07:00
|
|
|
u'target_utilization': self.station.target_utilization,
|
2018-04-01 05:52:20 -06:00
|
|
|
u'status': self.station.get_status_display()}
|
|
|
|
|
|
|
|
response = self.client.get('/api/stations/')
|
|
|
|
response_json = json.loads(response.content)
|
|
|
|
self.assertEqual(response_json, [station_serialized])
|