Ejemplo n.º 1
0
def list_spacecraft(launch_id, **kwargs):
    """JRPC method
    Returns the list of spacecraft registered for this launch.
    system.
    :param launch_id: Identifier of the LEOP cluster.
    :param kwargs: Dictionary with additional variables like the HTTP request
                    itself (defined by RPC4Django).
    :return: List of the identifiers of the spacecraft associated with the
    launch
    """
    # user must be obtained from the request, since this has already been
    # validated by the authentication backend
    if satnet_settings.JRPC_PERMISSIONS:
        http_request = kwargs.get('request', None)
        if not http_request or not http_request.user.is_staff:
            raise django_ex.PermissionDenied()

    launch = launch_models.Launch.objects.get(identifier=launch_id)

    # The spacecraft associated with this launch include the spacecraft for
    # the cluster and the spacecraft of the identified objects.
    scs = [launch.cluster_spacecraft_id]

    for identified_o in launch.identified_objects.all():

        scs += [
            launch_utils.generate_object_sc_identifier(
                launch_id, identified_o.identifier
            )
        ]

    # Since 'scs' is simply an array of strings (identifiers), no further
    # serialization should be required
    return scs
Ejemplo n.º 2
0
    def setUp(self):
        """Database setup for the tests.
        """

        self.__verbose_testing = False
        satnet_settings.JRPC_PERMISSIONS = True

        self.__user = db_tools.create_user_profile()
        self.__request_1 = db_tools.create_request(user_profile=self.__user)

        self.__gs_1_id = 'gs-uvigo'
        self.__gs_1 = db_tools.create_gs(
            user_profile=self.__user,
            identifier=self.__gs_1_id
        )
        self.__gs_2_id = 'gs-calpoly'
        self.__gs_2 = db_tools.create_gs(
            user_profile=self.__user,
            identifier=self.__gs_2_id
        )

        self.__admin = db_tools.create_user_profile(
            username='******',
            email='*****@*****.**',
            is_staff=True
        )
        self.__request_2 = db_tools.create_request(user_profile=self.__admin)

        self.__leop_tle_l1 = db_tools.ISS_TLE[0]
        self.__leop_tle_l2 = db_tools.ISS_TLE[1]
        self.__leop_id = 'leop_cluster_4testing'
        self.__leop_date = pytz.utc.localize(datetime.datetime.today())
        self.__leop = db_tools.create_launch(
            admin=self.__admin, identifier=self.__leop_id,
            date=self.__leop_date,
            tle_l1=self.__leop_tle_l1, tle_l2=self.__leop_tle_l2
        )
        self.__leop_serial_date = str(self.__leop.date.isoformat())
        self.__leop_cs = launch_utils.generate_cluster_callsign(self.__leop_id)
        self.__leop_sc_id = launch_utils.generate_cluster_sc_identifier(
            self.__leop_id, self.__leop_cs
        )

        self.__ufo_id = 1
        self.__ufo_sc_id = launch_utils.generate_object_sc_identifier(
            self.__leop_id, self.__ufo_id
        )
        self.__ufo_callsign = 'SCLLY'
        self.__ufo_tle_l1 = self.__leop_tle_l1
        self.__ufo_tle_l2 = self.__leop_tle_l2

        self.__leop_2_tle_l1 = db_tools.TIANGONG_TLE[0]
        self.__leop_2_tle_l2 = db_tools.TIANGONG_TLE[1]

        if not self.__verbose_testing:
            logging.getLogger('leop').setLevel(level=logging.CRITICAL)
            logging.getLogger('simulation').setLevel(level=logging.CRITICAL)
Ejemplo n.º 3
0
    def test_forget(self):
        """UNIT test: services.leop.launch.forget
        Validates the under-promotion of an identified object back to its
        unknown state.
        """
        launch_models.Launch.objects.add_unknown(self.__launch_id,
                                                 self.__ufo_1_id)
        self.assertEqual(len(simulation_models.GroundTrack.objects.all()), 2,
                         'One single track at the beginning')

        launch_models.Launch.objects.identify(self.__launch_id,
                                              self.__ufo_1_id, self.__ufo_1_cs,
                                              self.__tle_l1, self.__tle_l2)

        self.assertFalse(
            self.__launch.unknown_objects.filter(
                identifier=self.__ufo_1_id).exists(),
            'Object should not exist')

        # 0) Object should have been forgotten...
        self.assertTrue(
            launch_models.Launch.objects.forget(self.__launch_id,
                                                self.__ufo_1_id),
            'Object should have been forgotten')
        # 1) ... although it should exist now as an "unknown" object:
        self.assertTrue(
            self.__launch.unknown_objects.filter(
                identifier=self.__ufo_1_id).exists(),
            'Object should not exist')

        # 2) Associated spacecraft should have been deleted...
        sc_id = leop_utils.generate_object_sc_identifier(
            self.__launch_id, self.__ufo_1_id)
        self.assertFalse(
            self.__launch.identified_objects.filter(
                identifier=self.__ufo_1_id).exists(),
            'Spacecraft object should have been deleted')

        # 3) ...,, the associated TLE object should have been deleted...
        tle_id = leop_utils.generate_object_tle_id(self.__ufo_1_id,
                                                   self.__ufo_1_cs)
        self.assertFalse(
            tle_models.TwoLineElement.objects.filter(
                identifier=tle_id).exists(),
            'Cluster TLE object should have been deleted')

        # 4) ... and the groundtrack as well.
        self.assertEqual(len(simulation_models.GroundTrack.objects.all()), 2,
                         'Groundtrack should have been deleted')

        if self.__verbose_testing:

            print(' >>> sc_id (object) = ' + str(sc_id))
            print(' >>> tle_id (object) = ' + str(tle_id))
Ejemplo n.º 4
0
    def setUp(self):
        """Database setup for the tests.
        """

        self.__verbose_testing = False
        satnet_settings.JRPC_PERMISSIONS = True

        self.__user = db_tools.create_user_profile()
        self.__request_1 = db_tools.create_request(user_profile=self.__user)

        self.__gs_1_id = 'gs-uvigo'
        self.__gs_1 = db_tools.create_gs(user_profile=self.__user,
                                         identifier=self.__gs_1_id)
        self.__gs_2_id = 'gs-calpoly'
        self.__gs_2 = db_tools.create_gs(user_profile=self.__user,
                                         identifier=self.__gs_2_id)

        self.__admin = db_tools.create_user_profile(username='******',
                                                    email='*****@*****.**',
                                                    is_staff=True)
        self.__request_2 = db_tools.create_request(user_profile=self.__admin)

        self.__leop_tle_l1 = db_tools.ISS_TLE[0]
        self.__leop_tle_l2 = db_tools.ISS_TLE[1]
        self.__leop_id = 'leop_cluster_4testing'
        self.__leop_date = pytz.utc.localize(datetime.datetime.today())
        self.__leop = db_tools.create_launch(admin=self.__admin,
                                             identifier=self.__leop_id,
                                             date=self.__leop_date,
                                             tle_l1=self.__leop_tle_l1,
                                             tle_l2=self.__leop_tle_l2)
        self.__leop_serial_date = str(self.__leop.date.isoformat())
        self.__leop_cs = launch_utils.generate_cluster_callsign(self.__leop_id)
        self.__leop_sc_id = launch_utils.generate_cluster_sc_identifier(
            self.__leop_id, self.__leop_cs)

        self.__ufo_id = 1
        self.__ufo_sc_id = launch_utils.generate_object_sc_identifier(
            self.__leop_id, self.__ufo_id)
        self.__ufo_callsign = 'SCLLY'
        self.__ufo_tle_l1 = self.__leop_tle_l1
        self.__ufo_tle_l2 = self.__leop_tle_l2

        self.__leop_2_tle_l1 = db_tools.TIANGONG_TLE[0]
        self.__leop_2_tle_l2 = db_tools.TIANGONG_TLE[1]

        if not self.__verbose_testing:
            logging.getLogger('leop').setLevel(level=logging.CRITICAL)
            logging.getLogger('simulation').setLevel(level=logging.CRITICAL)
Ejemplo n.º 5
0
    def delete(self, launch_id, object_id):
        """
        Deletes an identified object from the database together with its
        associated resources (TLE and Spacecraft objects).
        :param launch_id: Identifier of the launch
        :param object_id: Identifier for the identified object
        :return: True if the operation was succesfull
        """
        sc_id = leop_utils.generate_object_sc_identifier(launch_id, object_id)
        sc = segment_models.Spacecraft.objects.get(identifier=sc_id)

        self.get(identifier=object_id).delete()
        sc.tle.delete()
        sc.delete()

        return True
Ejemplo n.º 6
0
    def delete(self, launch_id, object_id):
        """
        Deletes an identified object from the database together with its
        associated resources (TLE and Spacecraft objects).
        :param launch_id: Identifier of the launch
        :param object_id: Identifier for the identified object
        :return: True if the operation was succesfull
        """
        sc_id = leop_utils.generate_object_sc_identifier(launch_id, object_id)
        sc = segment_models.Spacecraft.objects.get(identifier=sc_id)

        self.get(identifier=object_id).delete()
        sc.tle.delete()
        sc.delete()

        return True
Ejemplo n.º 7
0
    def test_identifiy(self):
        """UNIT test: services.leop.launch.identify
        Validates the promotion of an unknown object into an identified one
        and the allocation of the resources necessary (spacecraft, tle and
        associated groundtrack).
        """
        launch_models.Launch.objects.add_unknown(self.__launch_id,
                                                 self.__ufo_1_id)
        actual_id = launch_models.Launch.objects.identify(
            self.__launch_id, self.__ufo_1_id, self.__ufo_1_cs, self.__tle_l1,
            self.__tle_l2)
        self.assertEqual(actual_id[0], self.__ufo_1_id,
                         'Identifiers should be the same')

        # 1) unknown object should have been deleted from the database.
        self.assertFalse(
            self.__launch.unknown_objects.filter(
                identifier=self.__ufo_1_id).exists(),
            'Object should not exist')
        # 2) Objects should exist as an spacecraft object now
        sc_id = leop_utils.generate_object_sc_identifier(
            self.__launch_id, self.__ufo_1_id)

        self.assertTrue(
            self.__launch.identified_objects.filter(
                identifier=self.__ufo_1_id).exists(), 'Object should exist')

        # 3) The associated TLE object should have been created as well
        tle_id = leop_utils.generate_object_tle_id(self.__ufo_1_id,
                                                   self.__ufo_1_cs)
        self.assertTrue(
            tle_models.TwoLineElement.objects.filter(
                identifier=tle_id).exists(),
            'Cluster TLE object should have been created')

        # 4) and the groundtrack generated
        self.assertTrue(
            simulation_models.GroundTrack.objects.filter(
                spacecraft=segment_models.Spacecraft.objects.get(
                    identifier=sc_id)).exists(),
            'Groundtrack should have been created')

        if self.__verbose_testing:

            print(' >>> sc_id (object) = ' + str(sc_id))
            print(' >>> tle_id (object) = ' + str(tle_id))
Ejemplo n.º 8
0
    def test_forget(self):
        """UNIT test: services.leop.launch.forget
        Validates the under-promotion of an identified object back to its
        unknown state.
        """
        launch_models.Launch.objects.add_unknown(
            self.__launch_id, self.__ufo_1_id
        )
        self.assertEqual(
            len(simulation_models.GroundTrack.objects.all()), 2,
            'One single track at the beginning'
        )

        launch_models.Launch.objects.identify(
            self.__launch_id, self.__ufo_1_id, self.__ufo_1_cs,
            self.__tle_l1, self.__tle_l2
        )

        self.assertFalse(
            self.__launch.unknown_objects.filter(
                identifier=self.__ufo_1_id
            ).exists(),
            'Object should not exist'
        )

        # 0) Object should have been forgotten...
        self.assertTrue(
            launch_models.Launch.objects.forget(
                self.__launch_id, self.__ufo_1_id
            ),
            'Object should have been forgotten'
        )
        # 1) ... although it should exist now as an "unknown" object:
        self.assertTrue(
            self.__launch.unknown_objects.filter(
                identifier=self.__ufo_1_id
            ).exists(),
            'Object should not exist'
        )

        # 2) Associated spacecraft should have been deleted...
        sc_id = leop_utils.generate_object_sc_identifier(
            self.__launch_id, self.__ufo_1_id
        )
        self.assertFalse(
            self.__launch.identified_objects.filter(
                identifier=self.__ufo_1_id
            ).exists(),
            'Spacecraft object should have been deleted'
        )

        # 3) ...,, the associated TLE object should have been deleted...
        tle_id = leop_utils.generate_object_tle_id(
            self.__ufo_1_id, self.__ufo_1_cs
        )
        self.assertFalse(
            tle_models.TwoLineElement.objects.filter(
                identifier=tle_id
            ).exists(),
            'Cluster TLE object should have been deleted'
        )

        # 4) ... and the groundtrack as well.
        self.assertEqual(
            len(simulation_models.GroundTrack.objects.all()), 2,
            'Groundtrack should have been deleted'
        )

        if self.__verbose_testing:

            print(' >>> sc_id (object) = ' + str(sc_id))
            print(' >>> tle_id (object) = ' + str(tle_id))
Ejemplo n.º 9
0
    def test_identifiy(self):
        """UNIT test: services.leop.launch.identify
        Validates the promotion of an unknown object into an identified one
        and the allocation of the resources necessary (spacecraft, tle and
        associated groundtrack).
        """
        launch_models.Launch.objects.add_unknown(
            self.__launch_id, self.__ufo_1_id
        )
        actual_id = launch_models.Launch.objects.identify(
            self.__launch_id, self.__ufo_1_id, self.__ufo_1_cs,
            self.__tle_l1, self.__tle_l2
        )
        self.assertEqual(
            actual_id[0], self.__ufo_1_id, 'Identifiers should be the same'
        )

        # 1) unknown object should have been deleted from the database.
        self.assertFalse(
            self.__launch.unknown_objects.filter(
                identifier=self.__ufo_1_id
            ).exists(),
            'Object should not exist'
        )
        # 2) Objects should exist as an spacecraft object now
        sc_id = leop_utils.generate_object_sc_identifier(
            self.__launch_id, self.__ufo_1_id
        )

        self.assertTrue(
            self.__launch.identified_objects.filter(
                identifier=self.__ufo_1_id
            ).exists(),
            'Object should exist'
        )

        # 3) The associated TLE object should have been created as well
        tle_id = leop_utils.generate_object_tle_id(
            self.__ufo_1_id, self.__ufo_1_cs
        )
        self.assertTrue(
            tle_models.TwoLineElement.objects.filter(
                identifier=tle_id
            ).exists(),
            'Cluster TLE object should have been created'
        )

        # 4) and the groundtrack generated
        self.assertTrue(
            simulation_models.GroundTrack.objects.filter(
                spacecraft=segment_models.Spacecraft.objects.get(
                    identifier=sc_id
                )
            ).exists(),
            'Groundtrack should have been created'
        )

        if self.__verbose_testing:

            print(' >>> sc_id (object) = ' + str(sc_id))
            print(' >>> tle_id (object) = ' + str(tle_id))