def test_get_housekeeping_with_dynamic_filters_4(self): for i in range(15): timestamp = datetime.datetime.fromtimestamp(1570749472 + i) housekeepingData = fakeHousekeepingAsDict(timestamp) housekeepingData['battery_voltage'] = 16 + i 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() with self.client: response = self.client.get('/api/housekeepinglog?battery_voltage=gt-20&battery_voltage=lt-24') data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 200) self.assertEqual(len(data['data']['logs']), 3) response = self.client.get('/api/housekeepinglog?battery_voltage=gt-20&battery_voltage=lt-24&battery_voltage=eq-17') data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 200) self.assertEqual(len(data['data']['logs']), 0) response = self.client.get('/api/housekeepinglog?battery_voltage=gt-20&limit=1&battery_voltage=lt-24') data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 200) self.assertEqual(len(data['data']['logs']), 1)
def test_get_housekeeping_with_dynamic_filters_2(self): timestamp = datetime.datetime.fromtimestamp(1570749472) housekeepingData = fakeHousekeepingAsDict(timestamp) housekeepingData['temp_1'] = 11 housekeepingData['temp_2'] = 12 housekeepingData['temp_3'] = 13 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() with self.client: response = self.client.get('/api/housekeepinglog?temp_1=gt-10&temp_2=gt-11&temp_3=gt-12') data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 200) self.assertEqual(len(data['data']['logs']), 1) response = self.client.get('/api/housekeepinglog?temp_1=gt-10&temp_2=gt-11&temp_3=gt-14') data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 200) self.assertEqual(len(data['data']['logs']), 0)
def test_get_housekeeping_with_dynamic_filters_3(self): timestamp = datetime.datetime.fromtimestamp(1570749472) housekeepingData = fakeHousekeepingAsDict(timestamp) housekeepingData['battery_voltage'] = 16 housekeepingData['watchdog_1'] = 140 housekeepingData['panel_5_current'] = 0.5 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() with self.client: response = self.client.get('/api/housekeepinglog?battery_voltage=eq-16&watchdog_1=lt-150&panel_5_current=gt-0.2') data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 200) self.assertEqual(len(data['data']['logs']), 1) response = self.client.get('/api/housekeepinglog?battery_voltage=eq-15&watchdog_1=lt-150&panel_5_current=gt-0.2') data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 200) self.assertEqual(len(data['data']['logs']), 0)
def test_get_housekeeping_with_dynamic_filters_5_invalid_attribute(self): timestamp = datetime.datetime.fromtimestamp(1570749472) housekeepingData = fakeHousekeepingAsDict(timestamp) housekeepingData['temp_1'] = 11 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() with self.client: response = self.client.get('/api/housekeepinglog?tempp_1=gt-12') data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 400)
def test_get_housekeeping(self): """Test getting a housekeeping log""" timestamp = datetime.datetime.fromtimestamp(1570749472) housekeepingData = fakeHousekeepingAsDict(timestamp) 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() with self.client: response = self.client.get(f'/api/housekeepinglog/{housekeeping.id}') data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 200) self.assertIn('Passive', data['data']['satellite_mode']) self.assertEqual(1.7, data['data']['battery_voltage']) self.assertEqual(14, data['data']['no_MCU_resets']) self.assertIn(str(timestamp), data['data']['last_beacon_time']) self.assertEqual(6000, data['data']['watchdog_1']) self.assertEqual(11, data['data']['watchdog_2']) self.assertEqual(0, data['data']['watchdog_3']) self.assertEqual(1.1, data['data']['panel_1_current']) self.assertEqual(1.0, data['data']['panel_2_current']) self.assertEqual(1.2, data['data']['panel_3_current']) self.assertEqual(1.0, data['data']['panel_4_current']) self.assertEqual(1.0, data['data']['panel_5_current']) self.assertEqual(1.0, data['data']['panel_6_current']) self.assertEqual(11.0, data['data']['temp_1']) self.assertEqual(11.0, data['data']['temp_2']) self.assertEqual(14.0, data['data']['temp_3']) self.assertEqual(12.0, data['data']['temp_4']) self.assertEqual(11.0, data['data']['temp_5']) self.assertEqual(10.0, data['data']['temp_6']) for i in range(1, 25): self.assertEqual(data['data']['channels'][i-1]['id'], i) # \/ Should probably be housekeeping.id or smth instead of just 1 self.assertEqual(data['data']['channels'][i-1]['hk_id'], 1) self.assertEqual(data['data']['channels'][i-1]['channel_no'], i) self.assertEqual(data['data']['channels'][i-1]['enabled'], True) self.assertEqual(data['data']['channels'][i-1]['current'], 0.0) self.assertIn('success', data['status'])
def test_post_housekeeping_with_channels(self): timestamp = str(datetime.datetime.fromtimestamp(1570749472)) housekeepingData = fakeHousekeepingAsDict(timestamp) for i in range(1, 25): channel = fake_power_channel_as_dict(i) housekeepingData['channels'].append(channel) with self.client: response = self.client.post( '/api/housekeepinglog', data=json.dumps(housekeepingData), content_type='application/json' ) data = json.loads(response.data.decode()) self.assertEqual(response.status_code, 201) self.assertEqual( f'Housekeeping Log with timestamp {timestamp} was added!', data['message'] ) self.assertIn('success', data['status'])
def testAddHousekeepingEntry(self): timestamp = datetime.fromtimestamp(1570749472) housekeepingData = fakeHousekeepingAsDict(timestamp) 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() self.assertTrue(housekeeping.id) self.assertEqual(housekeeping.satellite_mode, 'Passive') self.assertEqual(housekeeping.battery_voltage, 1.7) self.assertEqual(housekeeping.current_in, 1.2) self.assertEqual(housekeeping.no_MCU_resets, 14) self.assertEqual(housekeeping.last_beacon_time, timestamp) self.assertEqual(housekeeping.watchdog_1, 6000) self.assertEqual(housekeeping.watchdog_2, 11) self.assertEqual(housekeeping.watchdog_3, 0) self.assertEqual(housekeeping.panel_1_current, 1.1) self.assertEqual(housekeeping.panel_2_current, 1.0) self.assertEqual(housekeeping.panel_3_current, 1.2) self.assertEqual(housekeeping.panel_4_current, 1.0) self.assertEqual(housekeeping.panel_5_current, 1.0) self.assertEqual(housekeeping.panel_6_current, 1.0) self.assertEqual(housekeeping.temp_1, 11.0) self.assertEqual(housekeeping.temp_2, 11.0) self.assertEqual(housekeeping.temp_3, 14.0) self.assertEqual(housekeeping.temp_4, 12.0) self.assertEqual(housekeeping.temp_5, 11.0) self.assertEqual(housekeeping.temp_6, 10.0) for i in range(1, 25): self.assertEqual(housekeeping.channels[i - 1].id, i) self.assertEqual(housekeeping.channels[i - 1].hk_id, 1) self.assertEqual(housekeeping.channels[i - 1].channel_no, i) self.assertEqual(housekeeping.channels[i - 1].enabled, True) self.assertEqual(housekeeping.channels[i - 1].current, 0.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()
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))