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_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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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)