Пример #1
0
    def test_gs_channel_create(self):
        """JRPC test: configuration.gs.channel.create
        """
        if self.__verbose_testing:
            print('>>> TEST (test_gs_channel_create)')

        try:
            jrpc_gs_channels_if.gs_channel_create(
                groundstation_id='FAKE-GS',
                channel_id=self.__gs_1_ch_2_id,
                configuration={
                    channel_serializers.BAND_K:
                        'UHF / U / 435000000.000000 / 438000000.000000',
                    channel_serializers.AUTOMATED_K: False,
                    channel_serializers.MODULATIONS_K: ['FM'],
                    channel_serializers.POLARIZATIONS_K: ['LHCP'],
                    channel_serializers.BITRATES_K: [300, 600, 900],
                    channel_serializers.BANDWIDTHS_K: [12.500000000]
                }
            )
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        self.assertTrue(
            jrpc_gs_channels_if.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_2_id,
                configuration={
                    channel_serializers.BAND_K:
                        'UHF / U / 435000000.000000 / 438000000.000000',
                    channel_serializers.AUTOMATED_K: False,
                    channel_serializers.MODULATIONS_K: ['FM'],
                    channel_serializers.POLARIZATIONS_K: ['LHCP'],
                    channel_serializers.BITRATES_K: [300, 600, 900],
                    channel_serializers.BANDWIDTHS_K: [12.500000000]
                }
            ),
            'Channel should have been created!'
        )
        db_tools.remove_gs_channel(self.__gs_1_id, self.__gs_1_ch_2_id)
Пример #2
0
    def test_gs_channel_create(self):
        """JRPC test: configuration.gs.channel.create
        """
        if self.__verbose_testing:
            print('>>> TEST (test_gs_channel_create)')

        try:
            jrpc_gs_channels_if.gs_channel_create(
                groundstation_id='FAKE-GS',
                channel_id=self.__gs_1_ch_2_id,
                configuration={
                    channel_serializers.BAND_K:
                    'UHF / U / 435000000.000000 / 438000000.000000',
                    channel_serializers.AUTOMATED_K: False,
                    channel_serializers.MODULATIONS_K: ['FM'],
                    channel_serializers.POLARIZATIONS_K: ['LHCP'],
                    channel_serializers.BITRATES_K: [300, 600, 900],
                    channel_serializers.BANDWIDTHS_K: [12.500000000]
                })
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        self.assertTrue(
            jrpc_gs_channels_if.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_2_id,
                configuration={
                    channel_serializers.BAND_K:
                    'UHF / U / 435000000.000000 / 438000000.000000',
                    channel_serializers.AUTOMATED_K: False,
                    channel_serializers.MODULATIONS_K: ['FM'],
                    channel_serializers.POLARIZATIONS_K: ['LHCP'],
                    channel_serializers.BITRATES_K: [300, 600, 900],
                    channel_serializers.BANDWIDTHS_K: [12.500000000]
                }), 'Channel should have been created!')
        db_tools.remove_gs_channel(self.__gs_1_id, self.__gs_1_ch_2_id)
Пример #3
0
    def test_gs_channel_get_configuration(self):
        """JRPC test: configuration.gs.channel.getConfiguration
        """
        try:
            jrpc_gs_channels_if.gs_channel_get_configuration(
                'FAKE-GS', 'FAKE-GS-CHANNEL'
            )
            self.fail('An exception should have been thrown!')
        except Exception:
            pass
        try:
            jrpc_gs_channels_if.gs_channel_get_configuration(
                self.__gs_1_id, 'FAKE-GS-CHANNEL'
            )
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        expected_c = {
            channel_serializers.CH_ID_K: self.__gs_1_ch_2_id,
            channel_serializers.BAND_K:
                'UHF / U / 435000000.000000 / 438000000.000000',
            channel_serializers.AUTOMATED_K: False,
            channel_serializers.MODULATIONS_K: ['FM'],
            channel_serializers.POLARIZATIONS_K: ['LHCP'],
            channel_serializers.BITRATES_K: [300, 600, 900],
            channel_serializers.BANDWIDTHS_K: [12.500000000]
        }
        self.assertTrue(
            jrpc_gs_channels_if.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_2_id,
                configuration=expected_c
            ),
            'Channel should have been created!'
        )

        actual_c = jrpc_gs_channels_if.gs_channel_get_configuration(
            self.__gs_1_id, self.__gs_1_ch_2_id
        )

        if self.__verbose_testing:
            misc.print_dictionary(actual_c)
            misc.print_dictionary(expected_c)

        self.assertEqual(actual_c, expected_c)
        db_tools.remove_gs_channel(self.__gs_1_id, self.__gs_1_ch_2_id)
Пример #4
0
    def test_gs_channel_delete(self):
        """JRPC test: configuration.gs.channel.delete
        """
        try:
            jrpc_gs_channels_if.gs_channel_delete(
                'FAKE-GS', 'FAKE-GS-CHANNEL'
            )
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        try:
            jrpc_gs_channels_if.gs_channel_delete(
                self.__gs_1_id, 'FAKE-GS-CHANNEL'
            )
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        self.assertTrue(
            jrpc_gs_channels_if.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_2_id,
                configuration={
                    channel_serializers.BAND_K:
                        'UHF / U / 435000000.000000 / 438000000.000000',
                    channel_serializers.AUTOMATED_K: False,
                    channel_serializers.MODULATIONS_K: ['FM'],
                    channel_serializers.POLARIZATIONS_K: ['LHCP'],
                    channel_serializers.BITRATES_K: [300, 600, 900],
                    channel_serializers.BANDWIDTHS_K: [12.500000000]
                }
            ),
            'Channel should have been created!'
        )
        self.assertTrue(
            jrpc_gs_channels_if.gs_channel_delete(
                self.__gs_1_id, self.__gs_1_ch_2_id
            ),
            'Channel should have been removed!'
        )
        self.assertFalse(
            jrpc_gs_channels_if.gs_channel_is_unique(self.__gs_1_ch_2_id),
            'Channel should not exist yet!'
        )
Пример #5
0
    def test_gs_channel_get_configuration(self):
        """JRPC test: configuration.gs.channel.getConfiguration
        """
        try:
            jrpc_gs_channels_if.gs_channel_get_configuration(
                'FAKE-GS', 'FAKE-GS-CHANNEL')
            self.fail('An exception should have been thrown!')
        except Exception:
            pass
        try:
            jrpc_gs_channels_if.gs_channel_get_configuration(
                self.__gs_1_id, 'FAKE-GS-CHANNEL')
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        expected_c = {
            channel_serializers.CH_ID_K: self.__gs_1_ch_2_id,
            channel_serializers.BAND_K:
            'UHF / U / 435000000.000000 / 438000000.000000',
            channel_serializers.AUTOMATED_K: False,
            channel_serializers.MODULATIONS_K: ['FM'],
            channel_serializers.POLARIZATIONS_K: ['LHCP'],
            channel_serializers.BITRATES_K: [300, 600, 900],
            channel_serializers.BANDWIDTHS_K: [12.500000000]
        }
        self.assertTrue(
            jrpc_gs_channels_if.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_2_id,
                configuration=expected_c), 'Channel should have been created!')

        actual_c = jrpc_gs_channels_if.gs_channel_get_configuration(
            self.__gs_1_id, self.__gs_1_ch_2_id)

        if self.__verbose_testing:
            misc.print_dictionary(actual_c)
            misc.print_dictionary(expected_c)

        self.assertEqual(actual_c, expected_c)
        db_tools.remove_gs_channel(self.__gs_1_id, self.__gs_1_ch_2_id)
Пример #6
0
    def test_gs_channel_delete(self):
        """JRPC test: configuration.gs.channel.delete
        """
        try:
            jrpc_gs_channels_if.gs_channel_delete('FAKE-GS', 'FAKE-GS-CHANNEL')
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        try:
            jrpc_gs_channels_if.gs_channel_delete(self.__gs_1_id,
                                                  'FAKE-GS-CHANNEL')
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        self.assertTrue(
            jrpc_gs_channels_if.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_2_id,
                configuration={
                    channel_serializers.BAND_K:
                    'UHF / U / 435000000.000000 / 438000000.000000',
                    channel_serializers.AUTOMATED_K: False,
                    channel_serializers.MODULATIONS_K: ['FM'],
                    channel_serializers.POLARIZATIONS_K: ['LHCP'],
                    channel_serializers.BITRATES_K: [300, 600, 900],
                    channel_serializers.BANDWIDTHS_K: [12.500000000]
                }), 'Channel should have been created!')
        self.assertTrue(
            jrpc_gs_channels_if.gs_channel_delete(self.__gs_1_id,
                                                  self.__gs_1_ch_2_id),
            'Channel should have been removed!')
        self.assertFalse(
            jrpc_gs_channels_if.gs_channel_is_unique(self.__gs_1_ch_2_id),
            'Channel should not exist yet!')
Пример #7
0
    def _test_sc_select_slots(self):
        """
        Validates the method for the selection of the slots.
        """
        if self.__verbose_testing:
            print('##### test_sc_get_changes')
        operational_models.OperationalSlot.objects.reset_ids_counter()

        # ### channels required for the tests
        self.assertTrue(
            jrpc_sc_chs.sc_channel_create(
                spacecraft_id=self.__sc_1_id,
                channel_id=self.__sc_1_ch_1_id,
                configuration=self.__sc_1_ch_1_cfg
            ),
            'Channel should have been created!'
        )
        self.assertTrue(
            jrpc_gs_chs.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_1_id,
                configuration=self.__gs_1_ch_1_cfg
            ),
            'Channel should have been created!'
        )

        date_i = misc.get_today_utc() + datetime.timedelta(days=1)
        date_f = misc.get_today_utc() + datetime.timedelta(days=366)
        now = misc.get_now_utc()
        s_time = now + datetime.timedelta(minutes=30)
        e_time = now + datetime.timedelta(minutes=45)

        jrpc_rules.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=date_i,
                date_f=date_f,
                starting_time=s_time,
                ending_time=e_time
            )
        )

        # 1) select all the slots and retrieve the changes
        actual = operational_models.OperationalSlot.objects.all()
        id_list = db_tools.create_identifier_list(actual)
        actual = jrpc_sc_scheduling.select_slots(self.__sc_1_id, id_list)

        self.assertEqual(
            len(actual), 2, 'Wrong slots number!'
        )

        # ### clean up sc/gs
        self.assertTrue(
            jrpc_gs_chs.gs_channel_delete(
                groundstation_id=self.__gs_1_id, channel_id=self.__gs_1_ch_1_id
            ),
            'Could not delete GroundStationChannel = ' + str(
                self.__gs_1_ch_1_id
            )
        )
        self.assertTrue(
            jrpc_sc_chs.sc_channel_delete(
                spacecraft_id=self.__sc_1_id, channel_id=self.__sc_1_ch_1_id
            ),
            'Could not delete SpacecraftChannel = ' + str(self.__sc_1_ch_1_id)
        )
Пример #8
0
    def test_sc_get_changes(self):
        """JRPC test: services.scheduling.sc.getChanges
        Validates the JRPC method <sc_get_changes>.
        """
        if self.__verbose_testing:
            print('##### test_gs_get_operational_slots')
            self.maxDiff = None

        operational_models.OperationalSlot.objects.reset_ids_counter()

        # ### channels required for the tests
        self.assertTrue(
            jrpc_sc_chs.sc_channel_create(
                spacecraft_id=self.__sc_1_id,
                channel_id=self.__sc_1_ch_1_id,
                configuration=self.__sc_1_ch_1_cfg
            ),
            'Channel should have been created!'
        )
        self.assertTrue(
            jrpc_gs_chs.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_1_id,
                configuration=self.__gs_1_ch_1_cfg
            ),
            'Channel should have been created!'
        )

        # 3) we add some slots and they should be retrieved as 'changed' only
        #  once.
        date_i = misc.get_today_utc() + datetime.timedelta(days=1)
        date_f = misc.get_today_utc() + datetime.timedelta(days=366)

        s_time = misc.get_next_midnight() - datetime.timedelta(hours=23)
        e_time = s_time + datetime.timedelta(hours=20)

        jrpc_rules.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=date_i,
                date_f=date_f,
                starting_time=s_time,
                ending_time=e_time
            )
        )

        if self.__verbose_testing:
            misc.print_list(operational_models.OperationalSlot.objects.all())

        self.assertGreater(
            len(operational_models.OperationalSlot.objects.all()),
            0,
            'Wrong slots number!'
        )

        # 5) we add some slots and they should be retrieved as 'changed' only
        #  once.
        date_i = misc.get_today_utc() + datetime.timedelta(days=1)
        date_f = misc.get_today_utc() + datetime.timedelta(days=366)

        s_time = misc.get_next_midnight() - datetime.timedelta(hours=23)
        e_time = s_time + datetime.timedelta(hours=20)

        jrpc_rules.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=date_i,
                date_f=date_f,
                starting_time=s_time,
                ending_time=e_time
            )
        )

        self.assertGreater(
            len(operational_models.OperationalSlot.objects.all()),
            0,
            'Wrong slots number!'
        )

        # ### clean up sc/gs
        self.assertTrue(
            jrpc_gs_chs.gs_channel_delete(
                groundstation_id=self.__gs_1_id, channel_id=self.__gs_1_ch_1_id
            ),
            'Could not delete GroundStationChannel = ' + str(
                self.__gs_1_ch_1_id
            )
        )
        self.assertEquals(
            len(operational_models.OperationalSlot.objects.all()),
            0,
            'Expected operational slots to be available'
        )
        self.assertTrue(
            jrpc_sc_chs.sc_channel_delete(
                spacecraft_id=self.__sc_1_id, channel_id=self.__sc_1_ch_1_id
            ),
            'Could not delete SpacecraftChannel = ' + str(self.__sc_1_ch_1_id)
        )
        self.assertEquals(
            len(operational_models.OperationalSlot.objects.all()),
            0,
            'Expected operational slots to be available'
        )
Пример #9
0
    def _sc_get_operational_slots(self):
        """
        Validates the JRPC method <sc_get_operational_slots>
        """
        if self.__verbose_testing:
            print('##### test_sc_get_operational_slots')
        operational_models.OperationalSlot.objects.reset_ids_counter()

        # 1) non-existant Spacecraft
        self.assertRaises(
            models.ObjectDoesNotExist,
            jrpc_sc_scheduling.get_operational_slots,
            0
        )

        # 2) basic test, should not generate slots until the GS is added,
        # raising an exception to confirm it
        self.assertEqual(
            jrpc_sc_chs.sc_channel_create(
                spacecraft_id=self.__sc_1_id,
                channel_id=self.__sc_1_ch_1_id,
                configuration=self.__sc_1_ch_1_cfg
            ), True, 'Channel should have been created!'
        )
        self.assertRaises(
            Exception,
            jrpc_sc_scheduling.get_operational_slots,
            self.__sc_1_ch_1_id
        )

        # 3) basic test, should generate 2 FREE slots
        self.assertEqual(
            jrpc_gs_chs.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_1_id,
                configuration=self.__gs_1_ch_1_cfg
            ), True, 'Channel should have been created!'
        )

        date_i = misc.get_today_utc() + datetime.timedelta(days=1)
        date_f = misc.get_today_utc() + datetime.timedelta(days=366)

        now = misc.get_now_utc()
        s_time = now + datetime.timedelta(minutes=30)
        e_time = now + datetime.timedelta(minutes=45)

        jrpc_rules.add_rule(
            self.__gs_1_id, self.__gs_1_ch_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=date_i,
                date_f=date_f,
                starting_time=s_time,
                ending_time=e_time
            )
        )

        actual = jrpc_sc_scheduling.get_operational_slots(self.__sc_1_id)
        expected = {
            self.__sc_1_ch_1_id: {
                self.__gs_1_ch_1_id: {
                    segment_serializers.GS_ID_K: self.__sc_1_id,
                    jrpc_sch_serial.SLOTS_K: [{
                        jrpc_sch_serial.SLOT_IDENTIFIER_K: '1',
                        jrpc_sch_serial.STATE_K: operational_models.STATE_FREE,
                        jrpc_sch_serial.DATE_START_K: (
                            s_time + datetime.timedelta(days=1)
                        ).isoformat(),
                        jrpc_sch_serial.DATE_END_K: (
                            e_time + datetime.timedelta(days=1)
                        ).isoformat()
                    }, {
                        jrpc_sch_serial.SLOT_IDENTIFIER_K: '2',
                        jrpc_sch_serial.STATE_K: operational_models.STATE_FREE,
                        jrpc_sch_serial.DATE_START_K: (
                            s_time + datetime.timedelta(days=2)
                        ).isoformat(),
                        jrpc_sch_serial.DATE_END_K: (
                            e_time + datetime.timedelta(days=2)
                        ).isoformat()
                    }]
                }
            }
        }
        self.assertEqual(actual, expected, 'Expected different slots!')

        # ### clean up
        self.assertTrue(
            jrpc_gs_chs.gs_channel_delete(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_1_id
            ),
            'Could not delete GroundStationChannel = ' + str(
                self.__gs_1_ch_1_id
            )
        )
        self.assertTrue(
            jrpc_sc_chs.sc_channel_delete(
                spacecraft_id=self.__sc_1_id,
                channel_id=self.__sc_1_ch_1_id
            ),
            'Could not delete SpacecraftChannel = ' + str(
                self.__sc_1_ch_1_id
            )
        )
Пример #10
0
    def setUp(self):
        """Database setup
        """
        self.__verbose_testing = False

        self.__sc_1_id = 'xatcobeo-sc'
        self.__sc_1_tle_id = 'HUMSAT-D'
        self.__sc_1_ch_1_id = 'xatcobeo-fm'
        self.__sc_1_ch_1_cfg = {
            channel_serializers.FREQUENCY_K: '437000000',
            channel_serializers.MODULATION_K: 'FM',
            channel_serializers.POLARIZATION_K: 'LHCP',
            channel_serializers.BITRATE_K: '300',
            channel_serializers.BANDWIDTH_K: '12.500000000'
        }
        self.__gs_1_id = 'gs-la'
        self.__gs_1_ch_1_id = 'gs-la-fm'
        self.__gs_1_ch_1_cfg = {
            channel_serializers.BAND_K:
            'UHF / U / 435000000.000000 / 438000000.000000',
            channel_serializers.AUTOMATED_K: False,
            channel_serializers.MODULATIONS_K: ['FM'],
            channel_serializers.POLARIZATIONS_K: ['LHCP'],
            channel_serializers.BITRATES_K: [300, 600, 900],
            channel_serializers.BANDWIDTHS_K: [12.500000000, 25.000000000]
        }
        self.__gs_1_ch_2_id = 'gs-la-fm-2'
        self.__gs_1_ch_2_cfg = {
            channel_serializers.BAND_K:
            'UHF / U / 435000000.000000 / 438000000.000000',
            channel_serializers.AUTOMATED_K: False,
            channel_serializers.MODULATIONS_K: ['FM'],
            channel_serializers.POLARIZATIONS_K: ['LHCP'],
            channel_serializers.BITRATES_K: [300, 600, 900],
            channel_serializers.BANDWIDTHS_K: [12.500000000, 25.000000000]
        }

        self.__band = db_tools.create_band()
        self.__user_profile = db_tools.create_user_profile()
        self.__sc_1 = db_tools.create_sc(
            user_profile=self.__user_profile,
            identifier=self.__sc_1_id,
            tle_id=self.__sc_1_tle_id,
        )
        self.__gs_1 = db_tools.create_gs(
            user_profile=self.__user_profile, identifier=self.__gs_1_id,
        )

        self.assertEqual(
            jrpc_gs_chs.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_1_id,
                configuration=self.__gs_1_ch_1_cfg
            ), True, 'Channel should have been created!'
        )
        self.assertRaises(
            Exception,
            jrpc_gs_scheduling.get_operational_slots,
            self.__gs_1_ch_1_id
        )

        # 3) basic test, should generate 2 FREE slots
        self.assertEqual(
            jrpc_sc_chs.sc_channel_create(
                spacecraft_id=self.__sc_1_id,
                channel_id=self.__sc_1_ch_1_id,
                configuration=self.__sc_1_ch_1_cfg
            ), True, 'Channel should have been created!'
        )

        # 4) we add a daily rule 12 hours, 00:00:01am to 11:59:59pm UTC
        #       all pass slots should became operational slots.
        self.__rule_1 = jrpc_rules.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=misc.get_today_utc(),
                date_f=misc.get_today_utc() + datetime.timedelta(days=50),
                starting_time=misc.get_next_midnight() + datetime.timedelta(
                    seconds=1
                ),
                ending_time=misc.get_next_midnight() + datetime.timedelta(
                    hours=23, minutes=59, seconds=59
                )
            )
        )
Пример #11
0
    def setUp(self):
        """
        This method populates the database with some information to be used
        only for this test.
        """
        self.__verbose_testing = False

        if not self.__verbose_testing:
            logging.getLogger('common').setLevel(level=logging.CRITICAL)
            logging.getLogger('configuration').setLevel(level=logging.CRITICAL)
            logging.getLogger('scheduling').setLevel(level=logging.CRITICAL)

        operational.OperationalSlot.objects.set_debug()

        self.__sc_1_id = 'xatcobeo-sc'
        self.__sc_1_tle_id = 'HUMSAT-D'
        self.__sc_1_ch_1_id = 'xatcobeo-fm'
        self.__sc_1_ch_1_cfg = {
            channel_serializers.FREQUENCY_K: '437000000',
            channel_serializers.MODULATION_K: 'FM',
            channel_serializers.POLARIZATION_K: 'LHCP',
            channel_serializers.BITRATE_K: '300',
            channel_serializers.BANDWIDTH_K: '12.500000000'
        }
        self.__gs_1_id = 'gs-la'
        self.__gs_1_ch_1_id = 'gs-la-fm'
        self.__gs_1_ch_1_cfg = {
            channel_serializers.BAND_K:
            'UHF / U / 435000000.000000 / 438000000.000000',
            channel_serializers.AUTOMATED_K: False,
            channel_serializers.MODULATIONS_K: ['FM'],
            channel_serializers.POLARIZATIONS_K: ['LHCP'],
            channel_serializers.BITRATES_K: [300, 600, 900],
            channel_serializers.BANDWIDTHS_K: [12.500000000, 25.000000000]
        }
        self.__gs_1_ch_2_id = 'gs-la-fm-2'
        self.__gs_1_ch_2_cfg = {
            channel_serializers.BAND_K:
            'UHF / U / 435000000.000000 / 438000000.000000',
            channel_serializers.AUTOMATED_K: False,
            channel_serializers.MODULATIONS_K: ['FM'],
            channel_serializers.POLARIZATIONS_K: ['LHCP'],
            channel_serializers.BITRATES_K: [300, 600, 900],
            channel_serializers.BANDWIDTHS_K: [12.500000000, 25.000000000]
        }

        self.__band = db_tools.create_band()
        self.__user_profile = db_tools.create_user_profile()
        self.__sc_1 = db_tools.create_sc(
            user_profile=self.__user_profile,
            identifier=self.__sc_1_id,
            tle_id=self.__sc_1_tle_id,
        )
        self.__gs_1 = db_tools.create_gs(
            user_profile=self.__user_profile,
            identifier=self.__gs_1_id,
        )

        self.assertEqual(
            jrpc_gs_chs.gs_channel_create(groundstation_id=self.__gs_1_id,
                                          channel_id=self.__gs_1_ch_1_id,
                                          configuration=self.__gs_1_ch_1_cfg),
            True, 'Channel should have been created!')
        self.assertRaises(Exception, jrpc_gs_scheduling.get_operational_slots,
                          self.__gs_1_ch_1_id)

        # 3) basic test, should generate 2 FREE slots
        self.assertEqual(
            jrpc_sc_chs.sc_channel_create(spacecraft_id=self.__sc_1_id,
                                          channel_id=self.__sc_1_ch_1_id,
                                          configuration=self.__sc_1_ch_1_cfg),
            True, 'Channel should have been created!')

        # 4) we add a daily rule 12 hours, 00:00:01am to 11:59:59pm UTC
        #       all pass slots should became operational slots.
        self.__rule_1 = jrpc_rules.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=misc.get_today_utc(),
                date_f=misc.get_today_utc() + datetime.timedelta(days=50),
                starting_time=misc.get_next_midnight() +
                datetime.timedelta(seconds=1),
                ending_time=misc.get_next_midnight() +
                datetime.timedelta(hours=23, minutes=59, seconds=59)))
Пример #12
0
    def test_gs_get_operational_slots(self):
        """JRPC test: services.scheduling.gs.getOperationalSlots
        Validates the JRPC method <gs_get_operational_slots>
        """
        if self.__verbose_testing:
            print('##### test_gs_get_operational_slots')
            self.maxDiff = None

        operational_models.OperationalSlot.objects.reset_ids_counter()

        if self.__verbose_testing:
            print('######### CHECK #1')
            misc.print_list(
                availability_models.AvailabilitySlot.objects.all(),
                name='availability'
            )
            misc.print_list(
                compatibility_models.ChannelCompatibility.objects.all(),
                name='compatibility'
            )
            misc.print_list(
                pass_models.PassSlots.objects.all(),
                name='passes'
            )
            misc.print_list(
                operational_models.OperationalSlot.objects.all(),
                name='operational'
            )

        # 1) non-existant GroundStation
        self.assertRaises(
            models.ObjectDoesNotExist,
            jrpc_gs_scheduling.get_operational_slots,
            0
        )

        # 2) basic test, should not generate slots until the GS is added,
        # raising an exception to confirm it
        self.assertTrue(
            jrpc_gs_ch_if.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_1_id,
                configuration=self.__gs_1_ch_1_cfg
            ),
            'Channel should have been created!'
        )
        self.assertRaises(
            Exception,
            jrpc_gs_scheduling.get_operational_slots,
            self.__gs_1_ch_1_id
        )

        # 3) basic test, should generate 2 FREE slots
        self.assertTrue(
            jrpc_sc_ch_if.sc_channel_create(
                spacecraft_id=self.__sc_1_id,
                channel_id=self.__sc_1_ch_1_id,
                configuration=self.__sc_1_ch_1_cfg
            ),
            'Channel should have been created!'
        )

        date_i = misc.get_today_utc() + datetime.timedelta(days=1)
        date_f = misc.get_today_utc() + datetime.timedelta(days=366)

        s_time = misc.get_next_midnight() - datetime.timedelta(hours=20)
        e_time = s_time + datetime.timedelta(hours=12)

        jrpc_rules.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=date_i,
                date_f=date_f,
                starting_time=s_time,
                ending_time=e_time
            )
        )

        if self.__verbose_testing:
            print('######### CHECK #2')
            misc.print_list(
                availability_models.AvailabilitySlot.objects.all(),
                name='availability'
            )
            misc.print_list(
                compatibility_models.ChannelCompatibility.objects.all(),
                name='compatibility'
            )
            misc.print_list(
                pass_models.PassSlots.objects.all(),
                name='passes'
            )
            misc.print_list(
                operational_models.OperationalSlot.objects.all(),
                name='operational'
            )

        self.assertGreater(
            len(jrpc_gs_scheduling.get_operational_slots(self.__gs_1_id)), 0
        )

        # ### clean up sc/gs
        self.assertTrue(
            jrpc_gs_ch_if.gs_channel_delete(
                groundstation_id=self.__gs_1_id, channel_id=self.__gs_1_ch_1_id
            ),
            'Could not delete GroundStationChannel = ' + str(
                self.__gs_1_ch_1_id
            )
        )

        self.assertEquals(
            len(jrpc_gs_scheduling.get_operational_slots(self.__gs_1_id)), 0
        )

        self.assertTrue(
            jrpc_sc_ch_if.sc_channel_delete(
                spacecraft_id=self.__sc_1_id, channel_id=self.__sc_1_ch_1_id
            )
        )

        self.assertEquals(
            len(jrpc_gs_scheduling.get_operational_slots(self.__gs_1_id)), 0
        )
Пример #13
0
    def test_1_compatibility_sc_channel_added_deleted(self):
        """INTR test: compatibility changed generates operational slots

        1) +GS_CH
        2) +RULE
        3) +SC_CH
        4) -SC_CH
        5) -RULE
        6) -GS_CH

        OperationalSlots should be available only in bewteen steps 3 and 4.
        """
        if self.__verbose_testing:
            print('##### test_add_slots: no rules')

        self.__sc_1 = db_tools.create_sc(
            user_profile=self.__user_profile,
            identifier=self.__sc_1_id,
            tle_id=self.__sc_1_tle_id,
        )

        self.assertTrue(
            jrpc_gs_ch_if.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_1_id,
                configuration=self.__gs_1_ch_1_cfg),
            'Channel should have been created!')

        r_1_id = jrpc_rules_if.add_rule(self.__gs_1_id, self.__rule_1_cfg)
        self.assertIsNot(r_1_id, 0, 'Rule should have been added!')

        self.assertTrue(
            jrpc_sc_ch_if.sc_channel_create(
                spacecraft_id=self.__sc_1_id,
                channel_id=self.__sc_1_ch_1_id,
                configuration=self.__sc_1_ch_1_cfg),
            'Channel should have been created!')

        a_slots = availability_models.AvailabilitySlot.objects.get_applicable(
            groundstation=self.__gs_1)

        if self.__verbose_testing:
            misc.print_list(a_slots, 'AvailabilitySlots')
            misc.print_list(operational_models.OperationalSlot.objects.all(),
                            'OperationalSlots')

        self.assertGreaterEqual(
            len(operational_models.OperationalSlot.objects.all()), 2)

        self.assertTrue(
            jrpc_sc_ch_if.sc_channel_delete(spacecraft_id=self.__sc_1_id,
                                            channel_id=self.__sc_1_ch_1_id))

        expected = []
        actual = list(
            operational_models.OperationalSlot.objects.filter(
                state=operational_models.STATE_FREE).values_list('state'))

        if self.__verbose_testing:
            print('>>> window = ' +
                  str(simulation.OrbitalSimulator.get_simulation_window()))
            misc.print_list(rule_models.AvailabilityRule.objects.all())
            misc.print_list(availability_models.AvailabilitySlot.objects.all())
            misc.print_list(operational_models.OperationalSlot.objects.all())
            misc.print_list(actual)
            misc.print_list(expected)

        self.assertEqual(actual, expected)

        self.assertTrue(jrpc_rules_if.remove_rule(self.__gs_1_id, r_1_id),
                        'Rule should have been removed!')
        expected = []
        actual = list(
            operational_models.OperationalSlot.objects.filter(
                state=operational_models.STATE_FREE).values_list('state'))
        self.assertEqual(actual, expected)

        self.assertTrue(
            jrpc_gs_ch_if.gs_channel_delete(groundstation_id=self.__gs_1_id,
                                            channel_id=self.__gs_1_ch_1_id),
            'Could not delete GroundStationChannel = ' +
            str(self.__gs_1_ch_1_id))
        expected = []
        actual = list(
            operational_models.OperationalSlot.objects.filter(
                state=operational_models.STATE_FREE).values_list('state'))
        self.assertEqual(actual, expected)
Пример #14
0
    def test_gs_get_operational_slots(self):
        """JRPC test: services.scheduling.gs.getOperationalSlots
        Validates the JRPC method <gs_get_operational_slots>
        """
        if self.__verbose_testing:
            print('##### test_gs_get_operational_slots')
            self.maxDiff = None

        operational_models.OperationalSlot.objects.reset_ids_counter()

        if self.__verbose_testing:
            print('######### CHECK #1')
            misc.print_list(availability_models.AvailabilitySlot.objects.all(),
                            name='availability')
            misc.print_list(
                compatibility_models.ChannelCompatibility.objects.all(),
                name='compatibility')
            misc.print_list(pass_models.PassSlots.objects.all(), name='passes')
            misc.print_list(operational_models.OperationalSlot.objects.all(),
                            name='operational')

        # 1) non-existant GroundStation
        self.assertRaises(models.ObjectDoesNotExist,
                          jrpc_gs_scheduling.get_operational_slots, 0)

        # 2) basic test, should not generate slots until the GS is added,
        # raising an exception to confirm it
        self.assertTrue(
            jrpc_gs_ch_if.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_1_id,
                configuration=self.__gs_1_ch_1_cfg),
            'Channel should have been created!')
        self.assertRaises(Exception, jrpc_gs_scheduling.get_operational_slots,
                          self.__gs_1_ch_1_id)

        # 3) basic test, should generate 2 FREE slots
        self.assertTrue(
            jrpc_sc_ch_if.sc_channel_create(
                spacecraft_id=self.__sc_1_id,
                channel_id=self.__sc_1_ch_1_id,
                configuration=self.__sc_1_ch_1_cfg),
            'Channel should have been created!')

        date_i = misc.get_today_utc() + datetime.timedelta(days=1)
        date_f = misc.get_today_utc() + datetime.timedelta(days=366)

        s_time = misc.get_next_midnight() - datetime.timedelta(hours=20)
        e_time = s_time + datetime.timedelta(hours=12)

        jrpc_rules.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(date_i=date_i,
                                            date_f=date_f,
                                            starting_time=s_time,
                                            ending_time=e_time))

        if self.__verbose_testing:
            print('######### CHECK #2')
            misc.print_list(availability_models.AvailabilitySlot.objects.all(),
                            name='availability')
            misc.print_list(
                compatibility_models.ChannelCompatibility.objects.all(),
                name='compatibility')
            misc.print_list(pass_models.PassSlots.objects.all(), name='passes')
            misc.print_list(operational_models.OperationalSlot.objects.all(),
                            name='operational')

        self.assertGreater(
            len(jrpc_gs_scheduling.get_operational_slots(self.__gs_1_id)), 0)

        # ### clean up sc/gs
        self.assertTrue(
            jrpc_gs_ch_if.gs_channel_delete(groundstation_id=self.__gs_1_id,
                                            channel_id=self.__gs_1_ch_1_id),
            'Could not delete GroundStationChannel = ' +
            str(self.__gs_1_ch_1_id))

        self.assertEquals(
            len(jrpc_gs_scheduling.get_operational_slots(self.__gs_1_id)), 0)

        self.assertTrue(
            jrpc_sc_ch_if.sc_channel_delete(spacecraft_id=self.__sc_1_id,
                                            channel_id=self.__sc_1_ch_1_id))

        self.assertEquals(
            len(jrpc_gs_scheduling.get_operational_slots(self.__gs_1_id)), 0)
Пример #15
0
    def test_1_compatibility_sc_channel_added_deleted(self):
        """INTR test: compatibility changed generates operational slots

        1) +GS_CH
        2) +RULE
        3) +SC_CH
        4) -SC_CH
        5) -RULE
        6) -GS_CH

        OperationalSlots should be available only in bewteen steps 3 and 4.
        """
        if self.__verbose_testing:
            print('##### test_add_slots: no rules')

        self.__sc_1 = db_tools.create_sc(
            user_profile=self.__user_profile,
            identifier=self.__sc_1_id,
            tle_id=self.__sc_1_tle_id,
        )

        self.assertTrue(
            jrpc_gs_ch_if.gs_channel_create(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_1_id,
                configuration=self.__gs_1_ch_1_cfg
            ),
            'Channel should have been created!'
        )

        r_1_id = jrpc_rules_if.add_rule(self.__gs_1_id, self.__rule_1_cfg)
        self.assertIsNot(r_1_id, 0, 'Rule should have been added!')

        self.assertTrue(
            jrpc_sc_ch_if.sc_channel_create(
                spacecraft_id=self.__sc_1_id,
                channel_id=self.__sc_1_ch_1_id,
                configuration=self.__sc_1_ch_1_cfg
            ), 'Channel should have been created!'
        )

        a_slots = availability_models.AvailabilitySlot.objects.get_applicable(
            groundstation=self.__gs_1
        )

        if self.__verbose_testing:
            misc.print_list(a_slots, 'AvailabilitySlots')
            misc.print_list(
                operational_models.OperationalSlot.objects.all(),
                'OperationalSlots'
            )

        self.assertGreaterEqual(
            len(operational_models.OperationalSlot.objects.all()), 2
        )

        self.assertTrue(
            jrpc_sc_ch_if.sc_channel_delete(
                spacecraft_id=self.__sc_1_id, channel_id=self.__sc_1_ch_1_id
            )
        )

        expected = []
        actual = list(
            operational_models.OperationalSlot.objects.filter(
                state=operational_models.STATE_FREE
            ).values_list('state')
        )

        if self.__verbose_testing:
            print('>>> window = ' + str(
                simulation.OrbitalSimulator.get_simulation_window()
            ))
            misc.print_list(rule_models.AvailabilityRule.objects.all())
            misc.print_list(availability_models.AvailabilitySlot.objects.all())
            misc.print_list(operational_models.OperationalSlot.objects.all())
            misc.print_list(actual)
            misc.print_list(expected)

        self.assertEqual(actual, expected)

        self.assertTrue(
            jrpc_rules_if.remove_rule(self.__gs_1_id, r_1_id),
            'Rule should have been removed!'
        )
        expected = []
        actual = list(
            operational_models.OperationalSlot.objects.filter(
                state=operational_models.STATE_FREE
            ).values_list('state')
        )
        self.assertEqual(actual, expected)

        self.assertTrue(
            jrpc_gs_ch_if.gs_channel_delete(
                groundstation_id=self.__gs_1_id,
                channel_id=self.__gs_1_ch_1_id
            ),
            'Could not delete GroundStationChannel = ' + str(
                self.__gs_1_ch_1_id
            )
        )
        expected = []
        actual = list(
            operational_models.OperationalSlot.objects.filter(
                state=operational_models.STATE_FREE
            ).values_list('state')
        )
        self.assertEqual(actual, expected)