Exemple #1
0
    def test_delete_flightschedule(self):
        timestamp = datetime.datetime.fromtimestamp(1570749472)
        commands = {
            'ping': (0,False),
            'get-hk':(0,False),
        }
        for name, (num_args, is_danger) in commands.items():
            c = add_telecommand(command_name=name, num_arguments=num_args, is_dangerous=is_danger)

        command1 = Telecommands.query.filter_by(command_name='ping').first()
        flightschedule = add_flight_schedule(
            creation_date=timestamp,
            upload_date=timestamp,
            status=2,
            execution_time=timestamp)

        flightschedule_commands = add_command_to_flightschedule(
                                timestamp=timestamp,
                                flightschedule_id=flightschedule.id,
                                command_id=command1.id
                            )
        with self.client:
            response = self.client.delete(f'api/flightschedules/{flightschedule.id}')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(FlightSchedules.query.filter_by(id=flightschedule.id).first(), None)
            self.assertEqual(
                FlightScheduleCommands.query.filter_by(id=flightschedule_commands.id).first(),
                None
            )
Exemple #2
0
 def test_add_flight_schedule(self):
     timestamp = datetime.fromtimestamp(1570749472)
     flightschedule = add_flight_schedule(creation_date=timestamp,
                                          upload_date=timestamp,
                                          status=2,
                                          execution_time=timestamp)
     self.assertTrue(flightschedule.id)
     self.assertEqual(timestamp, flightschedule.creation_date)
     self.assertEqual(timestamp, flightschedule.upload_date)
Exemple #3
0
 def test_add_command_to_flight_schedule(self):
     timestamp = datetime.fromtimestamp(1570749472)
     command = add_telecommand(command_name='ping',
                               num_arguments=0,
                               is_dangerous=False)
     flightschedule = add_flight_schedule(creation_date=timestamp,
                                          upload_date=timestamp,
                                          status=2,
                                          execution_time=timestamp)
     flightschedule_commands = add_command_to_flightschedule(
         timestamp=timestamp,
         flightschedule_id=flightschedule.id,
         command_id=command.id)
     self.assertTrue(flightschedule_commands.id)
     self.assertEqual(flightschedule_commands.timestamp, timestamp)
     self.assertEqual(flightschedule_commands.command_id, command.id)
     self.assertEqual(flightschedule_commands.flightschedule_id,
                      flightschedule.id)
Exemple #4
0
    def test_patch_flight_schedule(self):
        timestamp = datetime.datetime.fromtimestamp(1570749472)
        commands = {
            'ping': (0,False),
            'get-hk':(0,False),
        }

        for name, (num_args, is_danger) in commands.items():
            c = add_telecommand(command_name=name, num_arguments=num_args, is_dangerous=is_danger)

        command1 = Telecommands.query.filter_by(command_name='ping').first()
        command2 = Telecommands.query.filter_by(command_name='get-hk').first()
        flightschedule = add_flight_schedule(
            creation_date=timestamp,
            upload_date=timestamp,
            status=2,
            execution_time=timestamp)
        flightschedule_commands1 = add_command_to_flightschedule(
                                timestamp=timestamp,
                                flightschedule_id=flightschedule.id,
                                command_id=command1.id
                            )
        flightschedule_commands2 = add_command_to_flightschedule(
                                timestamp=timestamp,
                                flightschedule_id=flightschedule.id,
                                command_id=command2.id
                            )
        post_data = json.dumps(fake_patch_update_as_dict(timestamp))
        with self.client:
            response = self.client.patch(
                f'api/flightschedules/{flightschedule.id}',
                data=post_data,
                content_type='application/json'
            )
            response_data = json.loads(response.data.decode())
            self.assertEqual(response.status_code, 200)
            self.assertEqual(len(response_data['data']['commands']), 3)
            self.assertEqual(response_data['data']['commands'][0]['command']['command_id'], 2)
            self.assertEqual(response_data['data']['commands'][2]['command']['command_id'], 1)
Exemple #5
0
 def test_add_arg_to_flightschedule_command(self):
     timestamp = datetime.fromtimestamp(1570749472)
     command = add_telecommand(command_name='turn-on',
                               num_arguments=1,
                               is_dangerous=False)
     flightschedule = add_flight_schedule(creation_date=timestamp,
                                          upload_date=timestamp,
                                          status=2,
                                          execution_time=timestamp)
     flightschedule_commands = add_command_to_flightschedule(
         timestamp=timestamp,
         flightschedule_id=flightschedule.id,
         command_id=command.id)
     command_arg = add_arg_to_flightschedulecommand(
         index=0,
         argument='5',
         flightschedule_command_id=flightschedule_commands.id)
     self.assertTrue(command_arg.id)
     self.assertEqual(command_arg.index, 0)
     self.assertEqual(command_arg.argument, '5')
     self.assertEqual(command_arg.flightschedulecommand_id,
                      flightschedule_commands.id)
Exemple #6
0
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.get(self.get_server_url())

        db.drop_all()
        db.create_all()
        db.session.commit()

        # seed the database for testing
        timestamp = datetime.fromtimestamp(1570749472)
        for i in range(20):
            housekeepingData = fakeHousekeepingAsDict(timestamp + timedelta(
                minutes=i * 15))
            housekeeping = Housekeeping(**housekeepingData)

            for i in range(1, 25):
                channel = fake_power_channel_as_dict(i)
                p = PowerChannels(**channel)
                housekeeping.channels.append(p)

            db.session.add(housekeeping)
        db.session.commit()

        commands = {
            'ping': (0, False),
            'get-hk': (0, False),
            'turn-on': (1, True),
            'turn-off': (1, True),
            'set-fs': (1, True),
            'upload-fs': (0, False)
        }

        for name, (num_args, is_danger) in commands.items():
            c = add_telecommand(command_name=name,
                                num_arguments=num_args,
                                is_dangerous=is_danger)

        command = Telecommands.query.filter_by(command_name='ping').first()
        flightschedule = add_flight_schedule(creation_date=timestamp,
                                             upload_date=timestamp,
                                             status=2,
                                             execution_time=timestamp)
        flightschedule_commands = add_command_to_flightschedule(
            timestamp=timestamp,
            flightschedule_id=flightschedule.id,
            command_id=command.id)

        add_user(username='******', password='******', is_admin=True)
        add_user(username='******', password='******', is_admin=False)
        add_user(username='******', password='******', is_admin=False)
        command = Telecommands.query.filter_by(command_name='turn-on').first()
        flightschedule_commands = add_command_to_flightschedule(
            timestamp=timestamp,
            flightschedule_id=flightschedule.id,
            command_id=command.id)

        flightschedulecommand_arg = add_arg_to_flightschedulecommand(
            index=0,
            argument='5',
            flightschedule_command_id=flightschedule_commands.id)

        message = add_message_to_communications(timestamp=timestamp,
                                                message='ping',
                                                sender='user',
                                                receiver='comm')

        now = datetime.utcnow()
        add_passover(timestamp=now - timedelta(seconds=10))
        for i in range(1, 20):
            p = add_passover(timestamp=now + timedelta(minutes=i * 5))

        db.session.commit()
Exemple #7
0
def seed_db():
    """Seed the database with a set of users and flight schedules
    """
    timestamp = datetime.fromtimestamp(1570749472)
    for x in range(20):
        # 20 days
        for y in range(3):
            # 3 entries per day
            housekeepingData = fakeHousekeepingAsDict(
                timestamp + timedelta(days=x, minutes=y * 15))
            if (x + y) % 10 == 0:
                housekeepingData['satellite_mode'] = 'Danger'

            housekeeping = Housekeeping(**housekeepingData)

            for i in range(1, 25):
                channel = fake_power_channel_as_dict(i)
                p = PowerChannels(**channel)
                housekeeping.channels.append(p)

            db.session.add(housekeeping)
    db.session.commit()

    commands = {
        'ping': (0, False),
        'get-hk': (0, False),
        'turn-on': (1, True),
        'turn-off': (1, True),
        'upload-fs': (0, False),
        'adjust-attitude': (1, True),
        'magnetometer': (0, False),
        'imaging': (0, False)
    }

    for name, (num_args, is_danger) in commands.items():
        c = add_telecommand(command_name=name,
                            num_arguments=num_args,
                            is_dangerous=is_danger)

    command = Telecommands.query.filter_by(command_name='ping').first()
    flightschedule = add_flight_schedule(creation_date=timestamp,
                                         upload_date=timestamp,
                                         status=2,
                                         execution_time=timestamp)
    flightschedule_commands = add_command_to_flightschedule(
        timestamp=timestamp,
        flightschedule_id=flightschedule.id,
        command_id=command.id)

    add_user(username='******', password='******', is_admin=True)
    add_user(username='******', password='******', is_admin=False)
    add_user(username='******', password='******', is_admin=False)
    add_user(username='******', password='******', is_admin=False)
    add_user(username='******', password='******', is_admin=True)

    command = Telecommands.query.filter_by(command_name='turn-on').first()
    flightschedule_commands = add_command_to_flightschedule(
        timestamp=timestamp,
        flightschedule_id=flightschedule.id,
        command_id=command.id)

    flightschedulecommand_arg = add_arg_to_flightschedulecommand(
        index=0,
        argument='5',
        flightschedule_command_id=flightschedule_commands.id)

    message = add_message_to_communications(timestamp=timestamp,
                                            message='ping',
                                            sender='user',
                                            receiver='comm')

    now = datetime.utcnow()
    add_passover(timestamp=now - timedelta(seconds=10))
    for i in range(1, 20):
        p = add_passover(timestamp=now + timedelta(minutes=i * 5))
Exemple #8
0
def demo_db():
    timestamp = datetime.fromtimestamp(1570749472)
    time2 = datetime.fromisoformat('2019-11-04 00:05:23.283+00:00')
    #time3 = datetime.fromisoformat('2019-11-05 00:08:43.203+00:00')
    #time4 = datetime.fromisoformat('2019-11-05 00:15:20.118+00:00')

    housekeepingData = fakeHousekeepingAsDict(timestamp)
    hkd2 = fakeHousekeepingAsDict(time2)
    #hkd3 = fakeHousekeepingAsDict(time3)
    #hkd4 = fakeHousekeepingAsDict(time4)

    housekeeping = Housekeeping(**housekeepingData)
    hk2 = Housekeeping(**hkd2)
    #hk3 = Housekeeping(**hkd3)
    #hk4 = Housekeeping(**hkd4)

    db.session.add(housekeeping)
    db.session.add(hk2)
    #db.session.add(hk3)
    #db.session.add(hk4)

    db.session.commit()

    add_user(username='******', password='******', is_admin=True)
    add_user(username='******', password='******', is_admin=True)
    add_user(username='******', password='******', is_admin=False)
    add_user(username='******', password='******', is_admin=False)
    add_user(username='******', password='******', is_admin=False)
    add_user(username='******', password='******', is_admin=False)
    add_user(username='******', password='******', is_admin=False)

    commands = {
        'ping': (0, False),
        'get-hk': (0, False),
        'turn-on': (1, True),
        'turn-off': (1, True),
        'set-fs': (1, True),
        'upload-fs': (0, False)
    }

    for name, (num_args, is_danger) in commands.items():
        c = add_telecommand(command_name=name,
                            num_arguments=num_args,
                            is_dangerous=is_danger)

    command = Telecommands.query.filter_by(command_name='ping').first()
    flightschedule = add_flight_schedule(creation_date=timestamp,
                                         upload_date=timestamp,
                                         status=2)
    flightschedule_commands = add_command_to_flightschedule(
        timestamp=timestamp,
        flightschedule_id=flightschedule.id,
        command_id=command.id)

    command = Telecommands.query.filter_by(command_name='turn-on').first()
    flightschedule_commands = add_command_to_flightschedule(
        timestamp=timestamp,
        flightschedule_id=flightschedule.id,
        command_id=command.id)

    flightschedulecommand_arg = add_arg_to_flightschedulecommand(
        index=0,
        argument='5',
        flightschedule_command_id=flightschedule_commands.id)

    message = add_message_to_communications(timestamp=timestamp,
                                            message='ping',
                                            sender='user',
                                            receiver='comm')

    command = Telecommands.query.filter_by(command_name='ping').first()
    flightschedule = add_flight_schedule(creation_date=time2,
                                         upload_date=time2,
                                         status=2)
    flightschedule_commands = add_command_to_flightschedule(
        timestamp=time2,
        flightschedule_id=flightschedule.id,
        command_id=command.id)

    flightschedulecommand_arg = add_arg_to_flightschedulecommand(
        index=1,
        argument='5',
        flightschedule_command_id=flightschedule_commands.id)

    message = add_message_to_communications(timestamp=time2,
                                            message='ping',
                                            sender='user',
                                            receiver='comm')

    now = datetime.utcnow()
    add_passover(timestamp=now - timedelta(seconds=10))
    for i in range(5):
        add_passover(timestamp=now + timedelta(minutes=i * 10))