示例#1
0
    def setUp(self):
        """
        This method populates the database with some information to be used
        only for this test.
        """
        self.__verbose_testing = False
        self.__test_slot_id = -1

        self.__sc_1_id = 'xatcobeo-sc'
        self.__sc_1_tle_id = 'HUMSAT-D'
        self.__sc_1_ch_1_id = 'gmsk-sc-1'
        self.__sc_1_ch_1_f = 437000000
        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.__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.__sc_1_ch_1 = db_tools.sc_add_channel(
            self.__sc_1,
            self.__sc_1_ch_1_f,
            self.__sc_1_ch_1_id,
        )
        self.__gs_1_ch_1 = db_tools.gs_add_channel(self.__gs_1, self.__band,
                                                   self.__gs_1_ch_1_id)

        self.__rule_1 = jrpc_rules.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=sn_misc.get_today_utc(),
                date_f=sn_misc.get_today_utc() + datetime.timedelta(days=50),
                starting_time=sn_misc.get_next_midnight() +
                datetime.timedelta(seconds=1),
                ending_time=sn_misc.get_next_midnight() +
                datetime.timedelta(hours=23, minutes=59, seconds=59)))
示例#2
0
    def test_add_daily_rule(self):
        """JRPC test: (D) cfg.gs.channel.addRule, cfg.gs.channel.removeRule
        Should correctly add a DAILY rule to the system.
        """
        if self.__verbose_testing:
            print('>>> TEST (test_gs_channel_add_rule)')

        now = misc.get_now_utc()
        r_1_s_time = now + datetime.timedelta(minutes=30)
        r_1_e_time = now + datetime.timedelta(minutes=45)

        # 1) A daily rule is inserted in the database:
        rule_cfg = db_tools.create_jrpc_daily_rule(
            starting_time=r_1_s_time,
            ending_time=r_1_e_time
        )
        rule_pk = jrpc_rules.add_rule(self.__gs_1_id, rule_cfg)

        # 2) get the rule back through the JRPC interface
        rules_g1c1 = jrpc_rules.list_channel_rules(self.__gs_1_id)
        expected_r = {
            jrpc_serial.RULE_PK_K: rule_pk,
            jrpc_serial.RULE_PERIODICITY: jrpc_serial.RULE_PERIODICITY_DAILY,
            jrpc_serial.RULE_OP: jrpc_serial.RULE_OP_ADD,
            jrpc_serial.RULE_DATES: {
                jrpc_serial.RULE_DAILY_I_DATE: common_serial
                .serialize_iso8601_date(
                    misc.get_today_utc() + datetime.timedelta(days=1)
                ),
                jrpc_serial.RULE_DAILY_F_DATE: common_serial
                .serialize_iso8601_date(
                    misc.get_today_utc() + datetime.timedelta(days=366)
                ),
                jrpc_serial.RULE_S_TIME: common_serial
                .serialize_iso8601_time(
                    r_1_s_time
                ),
                jrpc_serial.RULE_E_TIME: common_serial
                .serialize_iso8601_time(
                    r_1_e_time
                )
            }
        }

        if self.__verbose_testing:
            print('>>> rules from JRPC[' + str(len(rules_g1c1)) + ']:')
            for r in rules_g1c1:
                misc.print_dictionary(r)
            print('>>> expected_r:')
            misc.print_dictionary(expected_r)

        self.assertEqual(rules_g1c1[0], expected_r)
示例#3
0
    def test_add_daily_rule(self):
        """JRPC test: (D) cfg.gs.channel.addRule, cfg.gs.channel.removeRule
        Should correctly add a DAILY rule to the system.
        """
        if self.__verbose_testing:
            print('>>> TEST (test_gs_channel_add_rule)')

        now = misc.get_now_utc()
        r_1_s_time = now + datetime.timedelta(minutes=30)
        r_1_e_time = now + datetime.timedelta(minutes=45)

        # 1) A daily rule is inserted in the database:
        rule_cfg = db_tools.create_jrpc_daily_rule(starting_time=r_1_s_time,
                                                   ending_time=r_1_e_time)
        rule_pk = jrpc_rules.add_rule(self.__gs_1_id, rule_cfg)

        # 2) get the rule back through the JRPC interface
        rules_g1c1 = jrpc_rules.list_channel_rules(self.__gs_1_id)
        expected_r = {
            jrpc_serial.RULE_PK_K: rule_pk,
            jrpc_serial.RULE_PERIODICITY: jrpc_serial.RULE_PERIODICITY_DAILY,
            jrpc_serial.RULE_OP: jrpc_serial.RULE_OP_ADD,
            jrpc_serial.RULE_DATES: {
                jrpc_serial.RULE_DAILY_I_DATE:
                common_serial.serialize_iso8601_date(misc.get_today_utc() +
                                                     datetime.timedelta(
                                                         days=1)),
                jrpc_serial.RULE_DAILY_F_DATE:
                common_serial.serialize_iso8601_date(misc.get_today_utc() +
                                                     datetime.timedelta(
                                                         days=366)),
                jrpc_serial.RULE_S_TIME:
                common_serial.serialize_iso8601_time(r_1_s_time),
                jrpc_serial.RULE_E_TIME:
                common_serial.serialize_iso8601_time(r_1_e_time)
            }
        }

        if self.__verbose_testing:
            print('>>> rules from JRPC[' + str(len(rules_g1c1)) + ']:')
            for r in rules_g1c1:
                misc.print_dictionary(r)
            print('>>> expected_r:')
            misc.print_dictionary(expected_r)

        self.assertEqual(rules_g1c1[0], expected_r)
示例#4
0
    def _test_2_generate_slots_daily_rule(self):
        """INTR test: services.scheduling - add slots with a DAILY rule (2)
        Tests the generation of slots for a given daily rule.
        """
        if self.__verbose_testing:
            print('##### test_generate_slots_daily_rule')

        jrpc_rules_if.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=self.__utc_s_date,
                date_f=self.__utc_e_date,
                starting_time=self.__utc_s_time,
                ending_time=self.__utc_e_time
            )
        )

        a_slots = rule_models.AvailabilityRule.objects.get_availability_slots(
            self.__gs
        )

        self.assertEqual(len(a_slots), 3)
        db_a_slots = availability.AvailabilitySlot.objects.all()
        self.assertEqual(len(db_a_slots), 3)

        self.assertEquals(
            model_to_dict(
                db_a_slots[0], exclude=['id', 'groundstation', 'identifier']
            ), {
                'start': self.__rule_s_time,
                'end': self.__rule_e_time
            }
        )

        self.assertEquals(
            model_to_dict(
                db_a_slots[1], exclude=['id', 'groundstation', 'identifier']
            ), {
                'start': self.__rule_s_time + datetime.timedelta(days=1),
                'end': self.__rule_e_time + datetime.timedelta(days=1)
            }
        )
示例#5
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)
示例#6
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'
        )
示例#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 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
                )
            )
        )
示例#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 test_generate_slots_daily_rule(self):
        """UNIT test: services.configuration.models.rules - DAILY slots
        This test validates that a DAILY rule generates the right amount of
        slots depending on the interval relation with the start/end moments of
        the rule itself.
        """
        if self.__verbose_testing:
            print('>>> test_generate_slots_once_rule:')

        #######################################################################
        # ### XXXX SIGNAL DISCONNECTED
        django_signals.post_save.disconnect(
            availability_signals.daily_rule_saved,
            sender=rule_models.AvailabilityRuleDaily
        )

        #######################################################################
        # ### 1) rule starts ends interval, no slot the first day
        rule_id = rule_jrpc.add_rule(
            self.__gs_1_id,
            sn_helpers.create_jrpc_daily_rule(
                starting_time=sn_misc.get_next_midnight() + py_timedelta(
                    hours=2
                ),
                ending_time=sn_misc.get_next_midnight() + py_timedelta(
                    hours=3
                )
            )
        )

        rule_db_values = rule_models.AvailabilityRule.objects.filter(
            pk=rule_id
        ).values()

        interval = (
            sn_misc.get_next_midnight() + py_timedelta(days=300, hours=4),
            sn_misc.get_next_midnight() + py_timedelta(days=303)
        )

        slots = rule_models.AvailabilityRuleManager\
            .generate_available_slots_daily(
                rule_db_values[0], interval=interval
            )

        expected = [
            (
                sn_misc.get_next_midnight() + py_timedelta(days=301, hours=2),
                sn_misc.get_next_midnight() + py_timedelta(days=301, hours=3)
            ),
            (
                sn_misc.get_next_midnight() + py_timedelta(days=302, hours=2),
                sn_misc.get_next_midnight() + py_timedelta(days=302, hours=3)
            ),
        ]

        self.assertListEqual(slots, expected)

        #######################################################################
        # ### 2) rule starts before interval, ends within,
        #           first day slot truncated
        rule_id = rule_jrpc.add_rule(
            self.__gs_1_id,
            sn_helpers.create_jrpc_daily_rule(
                starting_time=sn_misc.get_next_midnight() + py_timedelta(
                    hours=2
                ),
                ending_time=sn_misc.get_next_midnight() + py_timedelta(
                    hours=6
                )
            )
        )

        rule_db_values = rule_models.AvailabilityRule.objects.filter(
            pk=rule_id
        ).values()

        interval = (
            sn_misc.get_next_midnight() + py_timedelta(days=300, hours=4),
            sn_misc.get_next_midnight() + py_timedelta(days=303)
        )

        slots = rule_models.AvailabilityRuleManager\
            .generate_available_slots_daily(
                rule_db_values[0], interval=interval
            )

        expected = [
            (
                sn_misc.get_next_midnight() + py_timedelta(days=300, hours=4),
                sn_misc.get_next_midnight() + py_timedelta(days=300, hours=6)
            ),
            (
                sn_misc.get_next_midnight() + py_timedelta(days=301, hours=2),
                sn_misc.get_next_midnight() + py_timedelta(days=301, hours=6)
            ),
            (
                sn_misc.get_next_midnight() + py_timedelta(days=302, hours=2),
                sn_misc.get_next_midnight() + py_timedelta(days=302, hours=6)
            ),
        ]

        self.assertListEqual(slots, expected)

        #######################################################################
        # ### XXXX SIGNAL RECONNECTED
        django_signals.post_save.connect(
            availability_signals.daily_rule_saved,
            sender=rule_models.AvailabilityRuleDaily
        )
示例#11
0
    def test_bug_1(self):
        """INTR test: services.scheduling - operational slot generation
        """

        self.__gs_1_id = 'gs-vigo'
        self.__gs_1_ch_1_id = 'chan-cas-1'
        self.__sc_1_id = 'sc-serpens'
        self.__sc_1_ch_1_id = 'xatco-fm-1'
        self.__sc_1_ch_1_f = 437500000

        self.__band = db_tools.create_band()
        self.__user_profile = db_tools.create_user_profile()

        # 1) create vigo gs
        self.__gs = db_tools.create_gs(user_profile=self.__user_profile,
                                       identifier=self.__gs_1_id)

        # CHECK A: NO ADDITIONAL pass slots, no operational slots
        # ### There are pass slots for the already-propagated spacecraft
        p_slots_0 = pass_models.PassSlots.objects.filter(
            groundstation__identifier=self.__gs_1_id,
            spacecraft__identifier=self.__sc_1_id)

        self.assertEqual(len(p_slots_0), 0)
        o_slots_0 = operational_models.OperationalSlot.objects.filter(
            pass_slot__in=p_slots_0)
        self.assertEqual(len(o_slots_0), 0)

        # 2) serpens spacecraft
        self.__sc = db_tools.create_sc(user_profile=self.__user_profile,
                                       identifier=self.__sc_1_id)

        # CHECK B: MORE pass slots, no operational slots
        # ### There are pass slots for the already-propagated spacecraft
        p_slots_1 = pass_models.PassSlots.objects.filter(
            groundstation__identifier=self.__gs_1_id,
            spacecraft__identifier=self.__sc_1_id)
        self.assertGreater(len(p_slots_1), len(p_slots_0))
        o_slots_0 = operational_models.OperationalSlot.objects.filter(
            pass_slot__in=p_slots_0)
        self.assertEqual(len(o_slots_0), 0)

        # 3) we add channels and, therefore, compatibility matches
        #       without availability rules, no operational slots
        self.__sc_1_ch_1 = db_tools.sc_add_channel(self.__sc,
                                                   self.__sc_1_ch_1_f,
                                                   self.__sc_1_ch_1_id)
        self.__gs_1_ch_1 = db_tools.gs_add_channel(self.__gs, self.__band,
                                                   self.__gs_1_ch_1_id)

        # CHECK C: SAME pass slots, no operational slots
        # ### There are pass slots for the already-propagated spacecraft
        p_slots_2 = pass_models.PassSlots.objects.filter(
            groundstation__identifier=self.__gs_1_id,
            spacecraft__identifier=self.__sc_1_id)
        self.assertEqual(len(p_slots_2), len(p_slots_1))
        o_slots_0 = operational_models.OperationalSlot.objects.filter(
            pass_slot__in=p_slots_0)
        self.assertEqual(len(o_slots_0), 0)

        # 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 = rules_jrpc.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=sn_misc.get_today_utc(),
                date_f=sn_misc.get_today_utc() + datetime.timedelta(days=50),
                starting_time=sn_misc.get_next_midnight() +
                datetime.timedelta(seconds=1),
                ending_time=sn_misc.get_next_midnight() +
                datetime.timedelta(hours=23, minutes=59, seconds=59)))

        # CHECK D: 3 availability slots (1 per day, almost 24 hours)
        #           should transform all pass slots into operational slots
        a_slots = availability_models.AvailabilitySlot.objects.values_list(
            'start', 'end')
        x_slots = [
            (sn_misc.get_today_utc() + datetime.timedelta(seconds=1),
             sn_misc.get_today_utc() +
             datetime.timedelta(hours=23, minutes=59, seconds=59)),
            (sn_misc.get_today_utc() + datetime.timedelta(days=1, seconds=1),
             sn_misc.get_today_utc() +
             datetime.timedelta(days=1, hours=23, minutes=59, seconds=59)),
            (sn_misc.get_today_utc() + datetime.timedelta(days=2, seconds=1),
             sn_misc.get_today_utc() +
             datetime.timedelta(days=2, hours=23, minutes=59, seconds=59))
        ]

        self.assertCountEqual(a_slots, x_slots)

        p_slots_applicable_objs = pass_models.PassSlots.objects.filter(
            groundstation__identifier=self.__gs_1_id,
            spacecraft__identifier=self.__sc_1_id,
            start__gte=sn_misc.get_now_utc())
        p_slots_applicable = p_slots_applicable_objs.values_list(
            'start', 'end')

        self.assertGreaterEqual(len(p_slots_2), len(p_slots_applicable))

        o_slots_1 = operational_models.OperationalSlot.objects.filter(
            pass_slot__in=p_slots_applicable_objs,
            state=operational_models.STATE_FREE).values_list('start', 'end')
        self.assertCountEqual(p_slots_applicable, o_slots_1)

        # CHECK E: RPC interface should return an equivalent set of slots:
        o_slots_gs = gs_ops_rpc.get_operational_slots(self.__gs_1_id)
        self.assertEqual(len(o_slots_gs[self.__sc_1_id]), len(o_slots_1))

        if self.__verbose_testing:
            sn_misc.print_list(o_slots_1, name='o_slots_1')
            sn_misc.print_list(o_slots_gs[self.__sc_1_id],
                               name='o_slots-' + self.__gs_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
        )
示例#13
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)))
示例#14
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('configuration').setLevel(level=logging.CRITICAL)
            logging.getLogger('scheduling').setLevel(level=logging.CRITICAL)

        self.__rule_1_cfg = db_tools.create_jrpc_daily_rule(
            starting_time=misc.localize_time_utc(
                datetime.time(hour=8, minute=0, second=0)),
            ending_time=misc.localize_time_utc(
                datetime.time(hour=23, minute=55, second=0)))

        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]
        }

        # noinspection PyUnresolvedReferences
        from services.scheduling.signals import availability
        # noinspection PyUnresolvedReferences
        from services.scheduling.signals import compatibility
        # noinspection PyUnresolvedReferences
        from services.scheduling.signals import operational

        self.__band = db_tools.create_band()
        self.__user_profile = db_tools.create_user_profile()
        self.__gs_1 = db_tools.create_gs(
            user_profile=self.__user_profile,
            identifier=self.__gs_1_id,
        )
示例#15
0
    def test_propagate_simple(self):
        """INTR test: services.scheduling - slot propagation
        This test validates the propagation of the slots with a simple set of
        rules.
        """
        if self.__verbose_testing:
            print('>>> test_propagate_simple:')

        r_1_s_time = misc.get_next_midnight() - datetime.timedelta(hours=12)
        r_1_e_time = r_1_s_time + datetime.timedelta(hours=10)

        r_cfg = db_tools.create_jrpc_daily_rule(
            starting_time=r_1_s_time,
            ending_time=r_1_e_time
        )

        self.assertEquals(list(availability.AvailabilitySlot.objects.all()), [])

        r_1_id = jrpc_rules_if.add_rule(self.__gs_1_id, r_cfg)

        x_pre = [
            (
                r_1_s_time,
                r_1_e_time,
            ),
            (
                r_1_s_time + datetime.timedelta(days=1),
                r_1_e_time + datetime.timedelta(days=1),
            ),
            (
                r_1_s_time + datetime.timedelta(days=2),
                r_1_e_time + datetime.timedelta(days=2),
            )
        ]
        a_pre = list(
            availability.AvailabilitySlot.objects.values_list('start', 'end')
        )
        self.assertEqual(a_pre, x_pre)

        scheduling_tasks.populate_slots()

        expected_post = [
            (
                r_1_s_time,
                r_1_e_time,
            ),
            (
                r_1_s_time + datetime.timedelta(days=1),
                r_1_e_time + datetime.timedelta(days=1),
            ),
            (
                r_1_s_time + datetime.timedelta(days=2),
                r_1_e_time + datetime.timedelta(days=2),
            ),
            (
                r_1_s_time + datetime.timedelta(days=3),
                r_1_e_time + datetime.timedelta(days=3),
            )
        ]
        actual_post = list(
            availability.AvailabilitySlot.objects.values_list('start', 'end')
        )

        self.assertEqual(actual_post, expected_post)
        self.assertTrue(jrpc_rules_if.remove_rule(self.__gs_1_id, r_1_id))

        self.assertListEqual(
            list(availability.AvailabilitySlot.objects.all()), []
        )
        self.assertListEqual(
            list(operational.OperationalSlot.objects.all()), []
        )
示例#16
0
    def setUp(self):
        """
        This method populates the database with some information to be used
        only for this test.
        """
        self.__verbose_testing = False
        self.__test_slot_id = -1

        self.__sc_1_id = 'xatcobeo-sc'
        self.__sc_1_tle_id = 'HUMSAT-D'
        self.__sc_1_ch_1_id = 'gmsk-sc-1'
        self.__sc_1_ch_1_f = 437000000
        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.__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.__sc_1_ch_1 = db_tools.sc_add_channel(
            self.__sc_1, self.__sc_1_ch_1_f, self.__sc_1_ch_1_id,
        )
        self.__gs_1_ch_1 = db_tools.gs_add_channel(
            self.__gs_1, self.__band, self.__gs_1_ch_1_id
        )

        self.__rule_1 = jrpc_rules.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=sn_misc.get_today_utc(),
                date_f=sn_misc.get_today_utc() + datetime.timedelta(days=50),
                starting_time=sn_misc.get_next_midnight() + datetime.timedelta(
                    seconds=1
                ),
                ending_time=sn_misc.get_next_midnight() + datetime.timedelta(
                    hours=23, minutes=59, seconds=59
                )
            )
        )
示例#17
0
    def _test_3_generate_slots_several_rules_1(self):
        """INTR test: services.scheduling - add slots with several rules (3)
        This method tests the addition of new availability slots when there
        are several availability rules in the database.
        """
        if self.__verbose_testing:
            print('##### test_add_slots: several rules (1)')

        # R1) ADD+ONCE (+1 slot)
        rule_1_id = jrpc_rules_if.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_once_rule(
                starting_time=self.__rule_s_time, ending_time=self.__rule_e_time
            )
        )
        a_slots = rule_models.AvailabilityRule.objects.get_availability_slots(
            self.__gs
        )
        self.assertEqual(
            len(a_slots), 1, 'Only 1 slot expected, got = ' + str(len(a_slots))
        )
        av_slots = availability.AvailabilitySlot.objects.all()
        self.assertEqual(
            len(av_slots), 1, '1 slot expected, got = ' + str(len(av_slots))
        )

        if self.__verbose_testing:
            misc.print_list(
                rule_models.AvailabilityRule.objects.all(), name='RULES@1'
            )
            misc.print_list(av_slots, name='AVAILABLE@1')

        # R2) ADD+DAILY (+2 slots)
        rule_2_id = jrpc_rules_if.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=self.__utc_s_date,
                date_f=self.__utc_e_date,
                starting_time=self.__utc_s_time,
                ending_time=self.__utc_e_time
            )
        )

        a_slots = rule_models.AvailabilityRule.objects.get_availability_slots(
            self.__gs
        )
        av_slots = availability.AvailabilitySlot.objects.all()

        if self.__verbose_testing:
            print('>>> today_utc = ' + str(misc.get_today_utc()))
            print('>>> window = ' + str(
                simulation.OrbitalSimulator.get_simulation_window()
            ))
            misc.print_list(
                rule_models.AvailabilityRule.objects.all(), name='RULES@2'
            )
            misc.print_list(av_slots, name='AVAILABLE@2')

        expected_slots = 3
        self.assertEqual(len(a_slots), expected_slots)
        self.assertEqual(len(av_slots), expected_slots)

        # R3) ADD-ONCE (-1 slot)
        rule_3_id = jrpc_rules_if.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_once_rule(
                operation=jrpc_serial.RULE_OP_REMOVE,
                starting_time=self.__rule_s_time, ending_time=self.__rule_e_time
            )
        )

        a_slots = rule_models.AvailabilityRule.objects.get_availability_slots(
            self.__gs
        )
        av_slots = availability.AvailabilitySlot.objects.all()

        if self.__verbose_testing:
            print('>>> today_utc = ' + str(misc.get_today_utc()))
            print('>>> window = ' + str(
                simulation.OrbitalSimulator.get_simulation_window()
            ))
            misc.print_list(
                rule_models.AvailabilityRule.objects.all(), name='RULES@3'
            )
            misc.print_list(av_slots, name='AVAILABLE@3')

        expected_slots = 2
        self.assertEqual(len(a_slots), expected_slots)
        self.assertEqual(len(av_slots), expected_slots)

        # R4) ADD-DAILY (-7 slots)
        rule_4_id = jrpc_rules_if.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                operation=jrpc_serial.RULE_OP_REMOVE,
                date_i=self.__utc_s_date,
                date_f=self.__utc_e_date,
                starting_time=self.__utc_s_time,
                ending_time=self.__utc_e_time
            )
        )

        a_slots = rule_models.AvailabilityRule.objects.get_availability_slots(
            self.__gs
        )
        av_slots = availability.AvailabilitySlot.objects.all()

        if self.__verbose_testing:
            print('>>> today_utc = ' + str(misc.get_today_utc()))
            print('>>> window = ' + str(
                simulation.OrbitalSimulator.get_simulation_window()
            ))
            misc.print_list(
                rule_models.AvailabilityRule.objects.all(), name='RULES@4'
            )
            misc.print_list(av_slots, name='AVAILABLE@4')

        expected = 0
        self.assertEqual(len(a_slots), expected)
        self.assertEqual(len(av_slots), expected)

        # REMOVE R#4 (+6 slots)
        jrpc_rules_if.remove_rule(
            groundstation_id=self.__gs_1_id,
            rule_id=rule_4_id
        )

        a_slots = rule_models.AvailabilityRule.objects.get_availability_slots(
            self.__gs
        )
        av_slots = availability.AvailabilitySlot.objects.all()

        if self.__verbose_testing:
            print('>>> today_utc = ' + str(misc.get_today_utc()))
            print('>>> window = ' + str(
                simulation.OrbitalSimulator.get_simulation_window()
            ))
            misc.print_list(
                rule_models.AvailabilityRule.objects.all(), name='RULES@5'
            )
            misc.print_list(av_slots, name='AVAILABLE@5')

        expected = 2
        self.assertEqual(len(a_slots), expected)
        self.assertEqual(len(av_slots), expected)

        # REMOVE R#3 (+1 slot)
        jrpc_rules_if.remove_rule(
            groundstation_id=self.__gs_1_id,
            rule_id=rule_3_id
        )

        a_slots = rule_models.AvailabilityRule.objects.get_availability_slots(
            self.__gs
        )
        av_slots = availability.AvailabilitySlot.objects.all()

        if self.__verbose_testing:
            print('>>> today_utc = ' + str(misc.get_today_utc()))
            print('>>> window = ' + str(
                simulation.OrbitalSimulator.get_simulation_window()
            ))
            misc.print_list(
                rule_models.AvailabilityRule.objects.all(), name='RULES@6'
            )
            misc.print_list(av_slots, name='AVAILABLE@6')

        expected = 3
        self.assertEqual(len(a_slots), expected)
        self.assertEqual(len(av_slots), expected)

        # REMOVE R#2 (-7 slots)
        jrpc_rules_if.remove_rule(
            groundstation_id=self.__gs_1_id,
            rule_id=rule_2_id
        )
        a_slots = rule_models.AvailabilityRule.objects.get_availability_slots(
            self.__gs
        )
        self.assertEqual(len(a_slots), 1)
        av_slots = availability.AvailabilitySlot.objects.all()
        self.assertEqual(len(av_slots), 1)

        if self.__verbose_testing:
            misc.print_list(
                rule_models.AvailabilityRule.objects.all(), name='RULES@7'
            )
            misc.print_list(av_slots, name='AVAILABLE@7')

        # REMOVE R#1 (-1 slot)
        jrpc_rules_if.remove_rule(
            groundstation_id=self.__gs_1_id,
            rule_id=rule_1_id
        )
        a_slots = rule_models.AvailabilityRule.objects.get_availability_slots(
            self.__gs
        )
        self.assertEqual(len(a_slots), 0)
        av_slots = availability.AvailabilitySlot.objects.all()
        self.assertEqual(len(av_slots), 0)

        if self.__verbose_testing:
            misc.print_list(
                rule_models.AvailabilityRule.objects.all(), name='RULES@8'
            )
            misc.print_list(av_slots, name='AVAILABLE@8')

        self.__verbose_testing = False
示例#18
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('configuration').setLevel(level=logging.CRITICAL)
            logging.getLogger('scheduling').setLevel(level=logging.CRITICAL)

        self.__rule_1_cfg = db_tools.create_jrpc_daily_rule(
            starting_time=misc.localize_time_utc(datetime.time(
                hour=8, minute=0, second=0
            )),
            ending_time=misc.localize_time_utc(datetime.time(
                hour=23, minute=55, second=0
            ))
        )

        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]
        }

        # noinspection PyUnresolvedReferences
        from services.scheduling.signals import availability
        # noinspection PyUnresolvedReferences
        from services.scheduling.signals import compatibility
        # noinspection PyUnresolvedReferences
        from services.scheduling.signals import operational

        self.__band = db_tools.create_band()
        self.__user_profile = db_tools.create_user_profile()
        self.__gs_1 = db_tools.create_gs(
            user_profile=self.__user_profile, identifier=self.__gs_1_id,
        )
示例#19
0
    def _test_4_get_availability_slots(self):
        """INTR test: services.scheduling - availability slot generation (4)
        Validates the method that gathers the AvailabilitySlots that are
        applicable within a defined interval.
        """
        if self.__verbose_testing:
            print('##### test_get_availability_slots:')

        # 0) Stability with None...
        self.assertEqual(
            availability.AvailabilitySlot.objects.get_applicable(None), [],
            '[] should be the result!'
        )
        # 1) Stability with []...
        self.assertEqual(
            availability.AvailabilitySlot.objects.get_applicable(
                groundstation=self.__gs,
            ), [],
            '[] should be the result!'
        )

        # 2) Single daily rule, adds availability slots...
        jrpc_rules_if.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=self.__utc_s_date,
                date_f=self.__utc_e_date,
                starting_time=self.__utc_s_time,
                ending_time=self.__utc_e_time
            )
        )

        a_slots = list(
            availability.AvailabilitySlot.objects.values_list(
                'start', 'end'
            )
        )
        # ### the identifier is included as it is obtained from the actual
        # ### execution of the method
        x_slots = [
            (
                self.__rule_s_time,
                self.__rule_e_time
            ),
            (
                self.__rule_s_time + datetime.timedelta(days=1),
                self.__rule_e_time + datetime.timedelta(days=1)
            ),
            (
                self.__rule_s_time + datetime.timedelta(days=2),
                self.__rule_e_time + datetime.timedelta(days=2)
            )
        ]

        if self.__verbose_testing:
            print('>>> window = ' + str(
                simulation.OrbitalSimulator.get_simulation_window()
            ))
            misc.print_list(
                rule_models.AvailabilityRule.objects.all(), name='RULES@1'
            )
            misc.print_list(a_slots, name='AVAILABLE@1')

        self.assertEqual(a_slots, x_slots)

        # 3) Period ending in the middle of an AvailabilitySlot, should
        # return the applicable half of that slot...
        a_slots = availability.AvailabilitySlot.objects.get_applicable(
            groundstation=self.__gs,
            start=self.__rule_s_time,
            end=self.__rule_s_time + datetime.timedelta(hours=3)
        )
        x_slots = [
            (
                self.__rule_s_time,
                self.__rule_s_time + datetime.timedelta(hours=3),
                a_slots[0][2]
            )
        ]

        if self.__verbose_testing:
            print('>>> window = ' + str(
                simulation.OrbitalSimulator.get_simulation_window()
            ))
            misc.print_list(x_slots, name='XSLOTS@2')
            misc.print_list(a_slots, name='AVAILABLE@2')

        self.assertEqual(a_slots, x_slots)

        # 4) Period starting in the middle of an AvailabilitySlot, should
        # return the applicable half of that slot...
        a_slots = availability.AvailabilitySlot.objects.get_applicable(
            groundstation=self.__gs,
            start=self.__rule_s_time + datetime.timedelta(hours=2),
            end=self.__rule_s_time + datetime.timedelta(hours=8)
        )
        x_slots = [(
            (
                self.__rule_s_time + datetime.timedelta(hours=2),
                self.__rule_s_time + datetime.timedelta(hours=5),
                a_slots[0][2]
            )
        )]
        self.assertEqual(a_slots, x_slots)

        # 5) Period starting after an AvailabilitySlot, should not return any
        #  slot at all...
        a_slots = availability.AvailabilitySlot.objects.get_applicable(
            groundstation=self.__gs,
            start=self.__rule_s_time + datetime.timedelta(hours=8),
            end=self.__rule_s_time + datetime.timedelta(hours=10)
        )
        self.assertEqual(a_slots, [])

        # 6) Period starting JUST after an AvailabilitySlot, should not return
        #  any slot at all...
        a_slots = availability.AvailabilitySlot.objects.get_applicable(
            groundstation=self.__gs,
            start=self.__rule_s_time + datetime.timedelta(hours=5),
            end=self.__rule_s_time + datetime.timedelta(hours=8)
        )
        self.assertEqual(a_slots, [])

        # 7) Period starting after an AvailabilitySlot, should not return any
        #  slot at all...
        a_slots = availability.AvailabilitySlot.objects.get_applicable(
            groundstation=self.__gs,
            start=self.__rule_s_time + datetime.timedelta(hours=7),
            end=self.__rule_s_time + datetime.timedelta(hours=8)
        )
        self.assertEqual(a_slots, [])

        # 8) Period starting JUST before an AvailabilitySlot, should not return
        #  any slot at all...
        a_slots = availability.AvailabilitySlot.objects.get_applicable(
            groundstation=self.__gs,
            start=self.__rule_s_time - datetime.timedelta(hours=2),
            end=self.__rule_s_time - datetime.timedelta(hours=1)
        )
        self.assertEqual(a_slots, [])
    def test_bug_1(self):
        """INTR test: services.scheduling - operational slot generation
        """

        self.__gs_1_id = 'gs-vigo'
        self.__gs_1_ch_1_id = 'chan-cas-1'
        self.__sc_1_id = 'sc-serpens'
        self.__sc_1_ch_1_id = 'xatco-fm-1'
        self.__sc_1_ch_1_f = 437500000

        self.__band = db_tools.create_band()
        self.__user_profile = db_tools.create_user_profile()

        # 1) create vigo gs
        self.__gs = db_tools.create_gs(
            user_profile=self.__user_profile, identifier=self.__gs_1_id
        )

        # CHECK A: NO ADDITIONAL pass slots, no operational slots
        # ### There are pass slots for the already-propagated spacecraft
        p_slots_0 = pass_models.PassSlots.objects.filter(
            groundstation__identifier=self.__gs_1_id,
            spacecraft__identifier=self.__sc_1_id
        )

        self.assertEqual(len(p_slots_0), 0)
        o_slots_0 = operational_models.OperationalSlot.objects.filter(
            pass_slot__in=p_slots_0
        )
        self.assertEqual(len(o_slots_0), 0)

        # 2) serpens spacecraft
        self.__sc = db_tools.create_sc(
            user_profile=self.__user_profile, identifier=self.__sc_1_id
        )

        # CHECK B: MORE pass slots, no operational slots
        # ### There are pass slots for the already-propagated spacecraft
        p_slots_1 = pass_models.PassSlots.objects.filter(
            groundstation__identifier=self.__gs_1_id,
            spacecraft__identifier=self.__sc_1_id
        )
        self.assertGreater(len(p_slots_1), len(p_slots_0))
        o_slots_0 = operational_models.OperationalSlot.objects.filter(
            pass_slot__in=p_slots_0
        )
        self.assertEqual(len(o_slots_0), 0)

        # 3) we add channels and, therefore, compatibility matches
        #       without availability rules, no operational slots
        self.__sc_1_ch_1 = db_tools.sc_add_channel(
            self.__sc, self.__sc_1_ch_1_f, self.__sc_1_ch_1_id
        )
        self.__gs_1_ch_1 = db_tools.gs_add_channel(
            self.__gs, self.__band, self.__gs_1_ch_1_id
        )

        # CHECK C: SAME pass slots, no operational slots
        # ### There are pass slots for the already-propagated spacecraft
        p_slots_2 = pass_models.PassSlots.objects.filter(
            groundstation__identifier=self.__gs_1_id,
            spacecraft__identifier=self.__sc_1_id
        )
        self.assertEqual(len(p_slots_2), len(p_slots_1))
        o_slots_0 = operational_models.OperationalSlot.objects.filter(
            pass_slot__in=p_slots_0
        )
        self.assertEqual(len(o_slots_0), 0)

        # 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 = rules_jrpc.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(
                date_i=sn_misc.get_today_utc(),
                date_f=sn_misc.get_today_utc() + datetime.timedelta(days=50),
                starting_time=sn_misc.get_next_midnight() + datetime.timedelta(
                    seconds=1
                ),
                ending_time=sn_misc.get_next_midnight() + datetime.timedelta(
                    hours=23, minutes=59, seconds=59
                )
            )
        )

        # CHECK D: 3 availability slots (1 per day, almost 24 hours)
        #           should transform all pass slots into operational slots
        a_slots = availability_models.AvailabilitySlot.objects.values_list(
            'start', 'end'
        )
        x_slots = [
            (
                sn_misc.get_today_utc() + datetime.timedelta(
                    seconds=1
                ),
                sn_misc.get_today_utc() + datetime.timedelta(
                    hours=23, minutes=59, seconds=59
                )
            ),
            (
                sn_misc.get_today_utc() + datetime.timedelta(
                    days=1, seconds=1
                ),
                sn_misc.get_today_utc() + datetime.timedelta(
                    days=1, hours=23, minutes=59, seconds=59
                )
            ),
            (
                sn_misc.get_today_utc() + datetime.timedelta(
                    days=2, seconds=1
                ),
                sn_misc.get_today_utc() + datetime.timedelta(
                    days=2, hours=23, minutes=59, seconds=59
                )
            )
        ]

        self.assertCountEqual(a_slots, x_slots)

        p_slots_applicable_objs = pass_models.PassSlots.objects.filter(
            groundstation__identifier=self.__gs_1_id,
            spacecraft__identifier=self.__sc_1_id,
            start__gte=sn_misc.get_now_utc()
        )
        p_slots_applicable = p_slots_applicable_objs.values_list(
            'start', 'end'
        )

        self.assertGreaterEqual(len(p_slots_2), len(p_slots_applicable))

        o_slots_1 = operational_models.OperationalSlot.objects.filter(
            pass_slot__in=p_slots_applicable_objs,
            state=operational_models.STATE_FREE
        ).values_list('start', 'end')
        self.assertCountEqual(p_slots_applicable, o_slots_1)

        # CHECK E: RPC interface should return an equivalent set of slots:
        o_slots_gs = gs_ops_rpc.get_operational_slots(self.__gs_1_id)
        self.assertEqual(len(o_slots_gs[self.__sc_1_id]), len(o_slots_1))

        if self.__verbose_testing:
            sn_misc.print_list(o_slots_1, name='o_slots_1')
            sn_misc.print_list(
                o_slots_gs[self.__sc_1_id], name='o_slots-' + self.__gs_1_id
            )
示例#21
0
    def test_utc_database(self):
        """UNIT test: UTC database datetimes
        This test validates whether the date/time information saved in the
        database is converted to UTC or not.
        """
        if self.__verbose_testing:
            print('>>> test_utc_database:')

        local_dt = datetime.datetime.now(pytz.timezone('US/Pacific')).replace(
            hour=0, minute=0, second=0, microsecond=0)
        utc_dt = datetime.datetime.now(pytz.timezone('UTC')).replace(
            hour=0, minute=0, second=0, microsecond=0)

        if self.__verbose_testing:
            print('>> local_dt = ' + str(local_dt))
            print('>> local_dt.iso() = ' + str(local_dt.isoformat()))
            print('>> local_dt.date() = ' + str(local_dt.date()))
            print('>> local_dt.time() = ' + str(local_dt.time()))
            print('>> local_dt.time().iso() = ' +
                  str(local_dt.time().isoformat()))
            print('>> local_dt.timetz() = ' + str(local_dt.timetz()))
            print('>> local_dt.tzname() = ' + str(local_dt.tzname()))
            print('>> local_dt.utcoffset() = ' + str(local_dt.utcoffset()))
            print('>> utc_dt = ' + str(utc_dt))
            print('>> utc_dt.iso() = ' + str(utc_dt.isoformat()))
            print('>> utc_dt.date() = ' + str(utc_dt.date()))
            print('>> utc_dt.time() = ' + str(utc_dt.time()))
            print('>> utc_dt.timetz() = ' + str(utc_dt.timetz()))
            print('>> utc_dt.tzname() = ' + str(utc_dt.tzname()))

        # 1) adds a single UTC rule to the database
        utc_i_date = utc_dt + datetime.timedelta(days=1)
        utc_e_date = utc_dt + datetime.timedelta(days=366)
        utc_s_time = utc_dt - datetime.timedelta(minutes=15)
        utc_e_time = utc_dt + datetime.timedelta(minutes=15)

        jrpc_rules_if.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(date_i=utc_i_date,
                                            date_f=utc_e_date,
                                            starting_time=utc_s_time,
                                            ending_time=utc_e_time))

        actual = [str(r) for r in rules.AvailabilityRule.objects.all()]
        expected = [
            '+(D):' + utc_i_date.isoformat().split('T')[0] + '>>' +
            utc_e_date.isoformat().split('T')[0] + '_T_' +
            utc_s_time.isoformat() + '>>' + utc_e_time.isoformat()
        ]

        self.assertEqual(actual, expected)

        # 2) adds a single PacificTime rule to the database (should be
        # converted into a UTC one).
        local_i_date = local_dt
        local_e_date = local_dt + datetime.timedelta(days=365)
        local_s_time = local_dt.replace(
            hour=0, minute=0, second=0,
            microsecond=0) + datetime.timedelta(hours=12)
        local_e_time = local_s_time + datetime.timedelta(minutes=30)

        jrpc_rules_if.add_rule(
            self.__gs_1_id,
            db_tools.create_jrpc_daily_rule(date_i=local_i_date,
                                            date_f=local_e_date,
                                            starting_time=local_s_time,
                                            ending_time=local_e_time))

        if self.__verbose_testing:
            print('>>> window = ' +
                  str(simulation.OrbitalSimulator.get_simulation_window()))
            misc.print_list(rules.AvailabilityRule.objects.all(), name='RULES')

        actual = [str(r) for r in rules.AvailabilityRule.objects.all()]
        expected.append('+(D):' + local_i_date.isoformat().split('T')[0] +
                        '>>' + local_e_date.isoformat().split('T')[0] + '_T_' +
                        local_s_time.astimezone(pytz.utc).isoformat() + '>>' +
                        local_e_time.astimezone(pytz.utc).isoformat())

        self.assertEqual(actual, expected)

        if self.__verbose_testing:
            misc.print_list(availability.AvailabilitySlot.objects.all(),
                            name='Availability Slots')
示例#22
0
    def test_generate_slots_daily_rule(self):
        """UNIT test: services.configuration.models.rules - DAILY slots
        This test validates that a DAILY rule generates the right amount of
        slots depending on the interval relation with the start/end moments of
        the rule itself.
        """
        if self.__verbose_testing:
            print('>>> test_generate_slots_once_rule:')

        #######################################################################
        # ### XXXX SIGNAL DISCONNECTED
        django_signals.post_save.disconnect(
            availability_signals.daily_rule_saved,
            sender=rule_models.AvailabilityRuleDaily)

        #######################################################################
        # ### 1) rule starts ends interval, no slot the first day
        rule_id = rule_jrpc.add_rule(
            self.__gs_1_id,
            sn_helpers.create_jrpc_daily_rule(
                starting_time=sn_misc.get_next_midnight() +
                py_timedelta(hours=2),
                ending_time=sn_misc.get_next_midnight() +
                py_timedelta(hours=3)))

        rule_db_values = rule_models.AvailabilityRule.objects.filter(
            pk=rule_id).values()

        interval = (sn_misc.get_next_midnight() +
                    py_timedelta(days=300, hours=4),
                    sn_misc.get_next_midnight() + py_timedelta(days=303))

        slots = rule_models.AvailabilityRuleManager\
            .generate_available_slots_daily(
                rule_db_values[0], interval=interval
            )

        expected = [
            (sn_misc.get_next_midnight() + py_timedelta(days=301, hours=2),
             sn_misc.get_next_midnight() + py_timedelta(days=301, hours=3)),
            (sn_misc.get_next_midnight() + py_timedelta(days=302, hours=2),
             sn_misc.get_next_midnight() + py_timedelta(days=302, hours=3)),
        ]

        self.assertListEqual(slots, expected)

        #######################################################################
        # ### 2) rule starts before interval, ends within,
        #           first day slot truncated
        rule_id = rule_jrpc.add_rule(
            self.__gs_1_id,
            sn_helpers.create_jrpc_daily_rule(
                starting_time=sn_misc.get_next_midnight() +
                py_timedelta(hours=2),
                ending_time=sn_misc.get_next_midnight() +
                py_timedelta(hours=6)))

        rule_db_values = rule_models.AvailabilityRule.objects.filter(
            pk=rule_id).values()

        interval = (sn_misc.get_next_midnight() +
                    py_timedelta(days=300, hours=4),
                    sn_misc.get_next_midnight() + py_timedelta(days=303))

        slots = rule_models.AvailabilityRuleManager\
            .generate_available_slots_daily(
                rule_db_values[0], interval=interval
            )

        expected = [
            (sn_misc.get_next_midnight() + py_timedelta(days=300, hours=4),
             sn_misc.get_next_midnight() + py_timedelta(days=300, hours=6)),
            (sn_misc.get_next_midnight() + py_timedelta(days=301, hours=2),
             sn_misc.get_next_midnight() + py_timedelta(days=301, hours=6)),
            (sn_misc.get_next_midnight() + py_timedelta(days=302, hours=2),
             sn_misc.get_next_midnight() + py_timedelta(days=302, hours=6)),
        ]

        self.assertListEqual(slots, expected)

        #######################################################################
        # ### XXXX SIGNAL RECONNECTED
        django_signals.post_save.connect(
            availability_signals.daily_rule_saved,
            sender=rule_models.AvailabilityRuleDaily)