示例#1
0
    def test_sc_channel_delete(self):
        """JRPC test: configuration.sc.channel.delete
        """
        try:
            jrpc_sc_channels_if.sc_channel_delete('FAKE-SC', 'FAKE-SC-CHANNEL')
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        try:
            jrpc_sc_channels_if.sc_channel_delete(self.__sc_1_id,
                                                  'FAKE-SC-CHANNEL')
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        self.assertTrue(
            jrpc_sc_channels_if.sc_channel_create(
                spacecraft_id=self.__sc_1_id,
                channel_id=self.__sc_1_ch_2_id,
                configuration={
                    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'
                }), 'Channel should have been created!')
        self.assertTrue(
            jrpc_sc_channels_if.sc_channel_delete(self.__sc_1_id,
                                                  self.__sc_1_ch_2_id),
            'Channel should have been removed!')
        self.assertFalse(
            jrpc_sc_channels_if.sc_channel_is_unique(self.__sc_1_ch_2_id),
            'Channel should not exist yet!')
示例#2
0
    def test_sc_channel_delete(self):
        """JRPC test: configuration.sc.channel.delete
        """
        try:
            jrpc_sc_channels_if.sc_channel_delete(
                'FAKE-SC', 'FAKE-SC-CHANNEL'
            )
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        try:
            jrpc_sc_channels_if.sc_channel_delete(
                self.__sc_1_id, 'FAKE-SC-CHANNEL'
            )
            self.fail('An exception should have been thrown!')
        except Exception:
            pass

        self.assertTrue(
            jrpc_sc_channels_if.sc_channel_create(
                spacecraft_id=self.__sc_1_id,
                channel_id=self.__sc_1_ch_2_id,
                configuration={
                    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'
                }
            ),
            'Channel should have been created!'
        )
        self.assertTrue(
            jrpc_sc_channels_if.sc_channel_delete(
                self.__sc_1_id, self.__sc_1_ch_2_id
            ),
            'Channel should have been removed!'
        )
        self.assertFalse(
            jrpc_sc_channels_if.sc_channel_is_unique(self.__sc_1_ch_2_id),
            'Channel should not exist yet!'
        )
示例#3
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)
        )
示例#4
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'
        )
示例#5
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
            )
        )
    def test_sc_channel_update_compatibility(self):
        """INTR test: SC channel update provokes compatibility change
        Initially, the just created spacecraft channel should be compatible
        with the also created Ground Station channel. However, after the
        update they become incompatible and, therefore, this fact should be
        reflected in the compatibility table.
        """

        # 0) initially, the channels are compatible
        compatibility = jrpc_compat_if.sc_channel_get_compatible(
            self.__sc_1_id, self.__sc_1_ch_1_id
        )

        self.assertEqual(
            compatibility[0]['GroundStation']['identifier'],
            'uvigo',
            'Wrong compat!!!'
        )

        # 1) new configuration makes channels incompatible
        expected_c = {
            channel_serializers.CH_ID_K: self.__sc_1_ch_1_id,
            channel_serializers.FREQUENCY_K: 2000000000,
            channel_serializers.MODULATION_K: 'FM',
            channel_serializers.POLARIZATION_K: 'RHCP',
            channel_serializers.BITRATE_K: 600,
            channel_serializers.BANDWIDTH_K: 25
        }

        self.assertTrue(
            jrpc_sc_ch_if.sc_channel_set_configuration(
                self.__sc_1_id, self.__sc_1_ch_1_id, expected_c
            ),
            'Configuration should have been set correctly!'
        )

        actual_c = jrpc_sc_ch_if.sc_channel_get_configuration(
            self.__sc_1_id, self.__sc_1_ch_1_id
        )
        self.assertEqual(actual_c, expected_c)

        self.assertEquals(
            jrpc_compat_if.sc_channel_get_compatible(
                self.__sc_1_id, self.__sc_1_ch_1_id
            ),
            []
        )

        compatibility = jrpc_compat_if.sc_get_compatible(self.__sc_1_id)
        self.assertEquals(
            compatibility['spacecraft_id'], self.__sc_1_id,
            'Wrong compatiblity!'
        )
        self.assertEquals(
            compatibility['Compatibility'][0]['ScChannel']['identifier'],
            self.__sc_1_ch_1_id,
            'Wrong compatiblity!'
        )
        self.assertEquals(
            compatibility['Compatibility'][0]['Compatibility'],
            [],
            'Wrong compatiblity!'
        )

        # 2) this new configuration should make the channels compatible again
        expected_c = {
            channel_serializers.CH_ID_K: self.__sc_1_ch_1_id,
            channel_serializers.FREQUENCY_K: 436365000,
            channel_serializers.MODULATION_K: 'FM',
            channel_serializers.POLARIZATION_K: 'RHCP',
            channel_serializers.BITRATE_K: 600,
            channel_serializers.BANDWIDTH_K: 25
        }

        self.assertTrue(
            jrpc_sc_ch_if.sc_channel_set_configuration(
                self.__sc_1_id, self.__sc_1_ch_1_id, expected_c
            ),
            'Configuration should have been set correctly!'
        )

        actual_c = jrpc_sc_ch_if.sc_channel_get_configuration(
            self.__sc_1_id, self.__sc_1_ch_1_id
        )
        self.assertEqual(actual_c, expected_c)

        compatibility = jrpc_compat_if.sc_channel_get_compatible(
            self.__sc_1_id, self.__sc_1_ch_1_id
        )

        self.assertEqual(
            compatibility[0]['GroundStation']['identifier'],
            'uvigo',
            'Wrong compat!!!'
        )

        # 3) deleting the spacecraft channel should erase the compatibility
        self.assertTrue(
            jrpc_sc_ch_if.sc_channel_delete(
                self.__sc_1_id, self.__sc_1_ch_1_id
            ),
            'Could not properly remove spacecraft channel!'
        )

        try:
            channel_models.SpacecraftChannel.objects.get(
                identifier=self.__sc_1_ch_1_id
            )
            self.fail('SC channel should have not been found!')
        except Exception:
            pass

        try:
            jrpc_compat_if.sc_channel_get_compatible(
                self.__sc_1_id, self.__sc_1_ch_1_id
            )
            self.fail(
                'Spacecraft Channel DoesNotExist, an exception should have been'
                'thrown'
            )
        except Exception:
            pass

        try:
            jrpc_compat_if.sc_get_compatible(
                self.__sc_1_id, self.__sc_1_ch_1_id
            )
            self.fail(
                'Spacecraft Channel DoesNotExist, an exception should have been'
                'thrown'
            )
        except Exception:
            pass

        self.assertEquals(
            len(compatibility_models.ChannelCompatibility.objects.all()), 0,
            'No compatibility objects should have been found '
        )
示例#7
0
    def test_1_booking(self):
        """Basic booking test.

        This test should validate the basic booking process of remote
        operations, which involve:

        * Spacecraft operators SELECT slots (remote operation request).
        * GroundStation operatotrs CONFIRM the selection of the slots (remote
        operation is RESERVED).
        * Spacecraft operators and GroundStation operators can retrieve this
        final status of the slots through the 'getChanges' method.

        """
        if self.__verbose_testing:
            print('##### test_1_booking')

        selection_1 = [
            int(x.identifier) for x in
            operational.OperationalSlot.objects.filter(
                state=operational.STATE_FREE
            ).order_by('id')[:3]
        ]

        # 0) Spacecraft operators selected a set of slots...
        sc_s_slots = jrpc_sc_scheduling.select_slots(
            self.__sc_1_id, selection_1
        )
        self.assertEqual(
            [int(x['identifier']) for x in sc_s_slots], selection_1
        )

        # 1) GroundStation operators confirm the selected slots...
        gs_c_slots = jrpc_gs_scheduling.confirm_selections(
            self.__gs_1_id, selection_1
        )
        self.assertEqual(
            [int(x['identifier']) for x in gs_c_slots], selection_1
        )

        # 5) GroundStation operators cancel the selected slots...
        jrpc_gs_scheduling.cancel_reservations(self.__gs_1_id, selection_1)
        # 5.a) No canceled Operational Slots
        self.assertEqual(
            [
                x.identifier
                for x in operational.OperationalSlot.objects.filter(
                    state=operational.STATE_CANCELED
                )
            ],
            []
        )
        # 5.b) No selected Operational Slots
        self.assertEqual(
            [
                x.identifier
                for x in operational.OperationalSlot.objects.filter(
                    state=operational.STATE_SELECTED
                )
            ],
            []
        )

        # 7) SpacecraftOperator retries the selection...
        sc_s_slots = jrpc_sc_scheduling.select_slots(
            self.__sc_1_id, selection_1
        )
        self.assertEqual(
            [int(x['identifier']) for x in sc_s_slots], selection_1
        )

        # 8) GroundStation operator denies the selection...
        gs_d_slots = jrpc_gs_scheduling.deny_selections(
            self.__gs_1_id, selection_1
        )
        self.assertEqual(
            [int(x['identifier']) for x in gs_d_slots], selection_1
        )

        # 5.a) No canceled Operational Slots
        self.assertEqual(
            [
                x.identifier
                for x in operational.OperationalSlot.objects.filter(
                    state=operational.STATE_CANCELED
                )
            ],
            []
        )
        # 5.b) No selected Operational Slots
        self.assertEqual(
            [
                x.identifier
                for x in operational.OperationalSlot.objects.filter(
                    state=operational.STATE_SELECTED
                )
            ],
            []
        )

        # ### 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_1_booking(self):
        """Basic booking test.

        This test should validate the basic booking process of remote
        operations, which involve:

        * Spacecraft operators SELECT slots (remote operation request).
        * GroundStation operatotrs CONFIRM the selection of the slots (remote
        operation is RESERVED).
        * Spacecraft operators and GroundStation operators can retrieve this
        final status of the slots through the 'getChanges' method.

        """
        if self.__verbose_testing:
            print('##### test_1_booking')

        selection_1 = [
            int(x.identifier)
            for x in operational.OperationalSlot.objects.filter(
                state=operational.STATE_FREE).order_by('id')[:3]
        ]

        # 0) Spacecraft operators selected a set of slots...
        sc_s_slots = jrpc_sc_scheduling.select_slots(self.__sc_1_id,
                                                     selection_1)
        self.assertEqual([int(x['identifier']) for x in sc_s_slots],
                         selection_1)

        # 1) GroundStation operators confirm the selected slots...
        gs_c_slots = jrpc_gs_scheduling.confirm_selections(
            self.__gs_1_id, selection_1)
        self.assertEqual([int(x['identifier']) for x in gs_c_slots],
                         selection_1)

        # 5) GroundStation operators cancel the selected slots...
        jrpc_gs_scheduling.cancel_reservations(self.__gs_1_id, selection_1)
        # 5.a) No canceled Operational Slots
        self.assertEqual([
            x.identifier for x in operational.OperationalSlot.objects.filter(
                state=operational.STATE_CANCELED)
        ], [])
        # 5.b) No selected Operational Slots
        self.assertEqual([
            x.identifier for x in operational.OperationalSlot.objects.filter(
                state=operational.STATE_SELECTED)
        ], [])

        # 7) SpacecraftOperator retries the selection...
        sc_s_slots = jrpc_sc_scheduling.select_slots(self.__sc_1_id,
                                                     selection_1)
        self.assertEqual([int(x['identifier']) for x in sc_s_slots],
                         selection_1)

        # 8) GroundStation operator denies the selection...
        gs_d_slots = jrpc_gs_scheduling.deny_selections(
            self.__gs_1_id, selection_1)
        self.assertEqual([int(x['identifier']) for x in gs_d_slots],
                         selection_1)

        # 5.a) No canceled Operational Slots
        self.assertEqual([
            x.identifier for x in operational.OperationalSlot.objects.filter(
                state=operational.STATE_CANCELED)
        ], [])
        # 5.b) No selected Operational Slots
        self.assertEqual([
            x.identifier for x in operational.OperationalSlot.objects.filter(
                state=operational.STATE_SELECTED)
        ], [])

        # ### 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))
    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
        )
示例#10
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)
示例#11
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)
示例#12
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)