Exemplo n.º 1
0
    def test_computeViewReturnsCorrectDataAccordingToTheDate(self):
        """
            Check if the view returns the correct data according to the date
        """
        tle = TLE.objects.findByCatalogEntryAndTime(
            CatalogEntry.objects.first(), format_inline_time('20170825200000'))
        sc = SatelliteComputation(tle=tle)

        sc.observer.date = '2017/8/25 20:00:00'
        expected_data_1 = sc.compute()

        sc.observer.date = '2017/8/25 20:00:01'
        expected_data_2 = sc.compute()

        response = self.client.get(
            '/api/v1/compute/25544/?time=20170825200000')
        content = response.content.decode('utf8')
        json_data_1 = json.loads(content)
        del json_data_1['tle']

        response = self.client.get(
            '/api/v1/compute/25544/?time=20170825200001')
        content = response.content.decode('utf8')
        json_data_2 = json.loads(content)
        del json_data_2['tle']

        self.assertEquals(json_data_1, expected_data_1)
        self.assertEquals(json_data_2, expected_data_2)
Exemplo n.º 2
0
    def test_calcOrbitalProducesCorrectOutput(self):
        expected_velocities = {
            100: 7849.1108,
            200: 7789.2220,
            300: 7730.6834,
            400: 7673.4451,
            1000: 7354.8236,
            2000: 6901.9526,
        }

        results = {
            100: 0,
            200: 0,
            300: 0,
            400: 0,
            1000: 0,
            2000: 0,
        }

        sc = SatelliteComputation(tle=TLE.objects.first())

        for km in expected_velocities:
            results[km] = round(sc._calc_orbital_velocity(km * 1000), 4)

        self.assertEquals(expected_velocities, results)
Exemplo n.º 3
0
    def test_calcOrbitalVelocityTakesAParameter(self):
        sc = SatelliteComputation(tle=TLE.objects.first())

        try:
            sc._calc_orbital_velocity(0)
        except TypeError:
            self.fail("method _calc_orbital_velocity must take a parameter")
Exemplo n.º 4
0
    def get(self, request, satellite_number, format=None):
        entry = get_object_or_404(CatalogEntry,
                                  norad_catalog_number=satellite_number)

        try:
            time = format_inline_time(request.GET.get('time', None))
        except ValueError:
            return Response({'detail': 'The given time is not correct'},
                            status=status.HTTP_400_BAD_REQUEST)

        try:
            tle = TLE.objects.findByCatalogEntryAndTime(entry, time)
        except:
            return Response(
                {'detail': 'No TLE corresponding to the given date.'},
                status=status.HTTP_400_BAD_REQUEST)

        sc = SatelliteComputation(tle=tle)
        sc.observer.date = time

        try:
            data = sc.compute()
        except ValueError as e:
            return Response({'detail': '{0}'.format(e)},
                            status=status.HTTP_400_BAD_REQUEST)

        return Response({
            'longitude': data['longitude'],
            'latitude': data['latitude'],
            'elevation': data['elevation'],
            'velocity': data['velocity'],
            'tle': tle.id,
        })
Exemplo n.º 5
0
    def test_calcOrbitalVelocityExists(self):
        sc = SatelliteComputation(tle=TLE.objects.first())

        try:
            sc._calc_orbital_velocity()
        except AttributeError:
            self.fail("method _calc_orbital_velocity does not exist")
        except TypeError:
            pass
Exemplo n.º 6
0
    def test_methodComputeOutputsDataAsDict(self):
        sc = SatelliteComputation(tle=TLE.objects.first())

        # Put the observer on a fixed date to avoid the test to fail while
        # running tests after the TLE expires
        sc.observer.date = '2017/8/25 20:00:00'

        data = sc.compute()

        self.assertTrue(isinstance(data, dict), "output is not a dict")
Exemplo n.º 7
0
    def test_calcOrbitalVelocityRaisesACorrectExceptionIfAltitudeIsNotANumber(
            self):
        sc = SatelliteComputation(tle=TLE.objects.first())

        try:
            sc._calc_orbital_velocity(None)
            self.fail(
                "method _calc_orbital_velocity can't accept a non number")
        except TypeError as e:
            self.assertEquals("altitude must be a number", str(e))
Exemplo n.º 8
0
    def test_checkMethodComputeExists(self):
        sc = SatelliteComputation(tle=TLE.objects.first())

        # Put the observer on a fixed date to avoid the test to fail while
        # running tests after the TLE expires
        sc.observer.date = '2017/8/25 20:00:00'

        try:
            sc.compute()
        except AttributeError:
            self.fail("compute() method does not exist")
Exemplo n.º 9
0
    def test_calcOrbitalVelocityRaisesACorrectExceptionIfAltitudeIsNegative(
            self):
        sc = SatelliteComputation(tle=TLE.objects.first())

        try:
            sc._calc_orbital_velocity(-1)
            self.fail(
                "method _calc_orbital_velocity can't accept a negaitive number"
            )
        except ValueError as e:
            self.assertEquals("altitude must be positive", str(e))
Exemplo n.º 10
0
    def test_methodComputeOutputsWellFormedDict(self):
        sc = SatelliteComputation(tle=TLE.objects.first())

        # Put the observer on a fixed date to avoid the test to fail while
        # running tests after the TLE expires
        sc.observer.date = '2017/8/25 20:00:00'

        data = sc.compute()

        expected_keys = ['longitude', 'latitude', 'elevation', 'velocity']

        for key in expected_keys:
            self.assertIn(key, data)
Exemplo n.º 11
0
    def test_observerPropertyExists(self):
        sc = SatelliteComputation(tle=TLE.objects.first())

        try:
            sc.observer
        except AttributeError:
            self.fail("observer attribute does not exist")
Exemplo n.º 12
0
    def test_methodComputOutputsPyEphemDataAndCorrectVelocity(self):
        expected_data = {
            'elevation': 406818.65625,
            'latitude': 49.48508595186298,
            'longitude': -156.969959505129,
            'velocity': 7669.588322702025,
        }

        sc = SatelliteComputation(tle=TLE.objects.first())

        # Put the observer on a fixed date to avoid the test to fail while
        # running tests after the TLE expires
        sc.observer.date = '2017/8/25 20:00:00'

        data = sc.compute()

        self.assertEquals(expected_data, data)
Exemplo n.º 13
0
    def test_computeViewReturnsSameDataAsSatelliteComputation(self):
        """
            Check if the view returns the same data as SatelliteComputation tool
        """
        tle = TLE.objects.findByCatalogEntryAndTime(
            CatalogEntry.objects.first(), format_inline_time('20170825200000'))
        sc = SatelliteComputation(tle=tle)

        # Put the observer on a fixed date to avoid the test to fail while
        # running after the TLE expires
        sc.observer.date = '2017/8/25 20:00:00'
        response = self.client.get(
            '/api/v1/compute/25544/?time=20170825200000')

        content = response.content.decode('utf8')
        json_data = json.loads(content)
        del json_data['tle']

        expected_data = sc.compute()

        self.assertEquals(json_data, expected_data)
Exemplo n.º 14
0
 def test_emptyConstructorRaisesCorrectException(self):
     try:
         SatelliteComputation()
         self.fail("SatelliteComputation() can take no parameter")
     except TypeError as e:
         self.assertEquals("tle parameter is missing", str(e))
Exemplo n.º 15
0
 def test_constructorCanTakeAWellFormedTleParameter(self):
     try:
         SatelliteComputation(tle=TLE.objects.first())
     except TypeError:
         self.fail("SatelliteComputation() can't take a 'tle' parameter")
Exemplo n.º 16
0
    def test_observerPropertyIsAPyEphemObserver(self):
        sc = SatelliteComputation(tle=TLE.objects.first())

        self.assertTrue(isinstance(sc.observer, ephem.Observer),
                        "observer is not of type ephem.Observer")
Exemplo n.º 17
0
 def test_constructorThrowsCorrectExceptionIfTheParamIsNotATle(self):
     try:
         SatelliteComputation(tle=None)
         self.fail("SatelliteComputation() can take a non TLE parameter")
     except TypeError as e:
         self.assertEquals("tle must be of type TLE", str(e))
Exemplo n.º 18
0
 def test_constructorThrowsCorrectExceptionIfTheTleIsInvalid(self):
     try:
         SatelliteComputation(tle=TLE())
         self.fail("SatelliteComputation() can take an empty TLE")
     except ValueError as e:
         self.assertEquals("invalid TLE", str(e))