示例#1
0
 def test_records_wifi_read_file(self):
     self.assertEqual(2, len(self._kapture_data.records_wifi.keys()))
     self.assertEqual(2, len(self._kapture_data.records_wifi.key_pairs()))
     self.assertIn(1555398770307, self._kapture_data.records_wifi)
     self.assertIn('AC01324954_wifi',
                   self._kapture_data.records_wifi[1555398770307])
     record_wifi_expected = kapture.RecordWifi({
         '68:72:51:80:52:df':
         kapture.RecordWifiSignal(frequency=2417,
                                  rssi=-33.0,
                                  ssid='M1X_PicoM2'),
         '68:9c:e2:e1:b0:60':
         kapture.RecordWifiSignal(frequency=5765,
                                  rssi=-49,
                                  ssid='@HYUNDAI-WiFi')
     })
     # compare representation, to be robust to ?????
     self.assertEqual(
         str(record_wifi_expected),
         str(self._kapture_data.records_wifi[1555398770307,
                                             'AC01324954_wifi']))
     record_wifi_expected = kapture.RecordWifi({
         '68:72:51:80:52:df':
         kapture.RecordWifiSignal(frequency=2417,
                                  rssi=-35,
                                  ssid='M1X_PicoM2'),
         '68:9c:e2:e1:b0:60':
         kapture.RecordWifiSignal(frequency=5765,
                                  rssi=-47,
                                  ssid='@HYUNDAI-WiFi')
     })
     self.assertEqual(
         str(record_wifi_expected),
         str(self._kapture_data.records_wifi[1555398771307,
                                             'AC01324954_wifi']))
示例#2
0
    def test_init_wifi(self):
        records_wifi = kapture.RecordsWifi()
        timestamp0, timestamp1 = 0, 1
        device_id0, device_id1 = 'AC01324954_WIFI', 'AC01324955_WIFI'
        bssid, ssid = '68:72:51:80:52:df', 'M1X_PicoM2'
        rssi = -33
        freq = 2417
        scan_time_start, scan_time_end = 1555398770280, 1555398770290
        # assign

        wifi_data = kapture.RecordWifi({bssid: kapture.RecordWifiSignal(ssid=ssid, rssi=rssi, frequency=freq,
                                                                        scan_time_start=scan_time_start,
                                                                        scan_time_end=scan_time_end)})
        records_wifi[timestamp0, device_id0] = wifi_data
        kapture_data = kapture.Kapture(records_wifi=records_wifi)
        self.assertEqual(1, len(kapture_data.records_wifi.keys()))
        self.assertEqual(1, len(kapture_data.records_wifi.key_pairs()))
        self.assertIn(timestamp0, kapture_data.records_wifi)
        self.assertIn(device_id0, kapture_data.records_wifi[timestamp0])
        self.assertIn((timestamp0, device_id0), kapture_data.records_wifi)
        self.assertEqual(wifi_data, kapture_data.records_wifi[timestamp0, device_id0])
        kapture_data.records_wifi[timestamp1, device_id1] = wifi_data
        self.assertEqual(2, len(kapture_data.records_wifi.keys()))
        self.assertEqual(2, len(kapture_data.records_wifi.key_pairs()))
        kapture_data.records_wifi[timestamp0][device_id1] = wifi_data
        self.assertEqual(2, len(kapture_data.records_wifi.keys()))
        self.assertEqual(3, len(kapture_data.records_wifi.key_pairs()))
示例#3
0
    def test_non_dict(self):
        test_values = 5
        expected_list = [(test_values,)]
        actual_list = list(kapture.flatten(test_values, is_sorted=False))
        actual_list_sorted = list(kapture.flatten(test_values, is_sorted=True))
        self.assertEqual(actual_list, expected_list)
        self.assertEqual(actual_list_sorted, expected_list)

        test_values = [5.0, 7.3, 6.02]
        expected_list = [(5.0,), (7.3,), (6.02,)]
        expected_list_sorted = [(5.0,), (6.02,), (7.3,)]
        actual_list = list(kapture.flatten(test_values, is_sorted=False))
        actual_list_sorted = list(kapture.flatten(test_values, is_sorted=True))
        self.assertEqual(actual_list, expected_list)
        self.assertEqual(actual_list_sorted, expected_list_sorted)

        test_values = {5.0, 7.3, 6.02}
        expected_list_sorted = [(5.0,), (6.02,), (7.3,)]
        actual_list_sorted = list(kapture.flatten(test_values, is_sorted=True))
        self.assertEqual(actual_list_sorted, expected_list_sorted)

        test_values = kapture.RecordWifiSignal(frequency=2500, rssi=-1.0)
        expected_list = [(test_values,)]
        actual_list = list(kapture.flatten(test_values, is_sorted=False))
        actual_list_sorted = list(kapture.flatten(test_values, is_sorted=True))
        self.assertEqual(actual_list, expected_list)
        self.assertEqual(actual_list_sorted, expected_list)
示例#4
0
    def test_equal_records_wifi(self):
        kapture_data_a = copy.deepcopy(self._kapture_data)
        kapture_data_b = copy.deepcopy(self._kapture_data)
        # check for deep copy
        self.assertTrue(
            equal_records_wifi(kapture_data_a.records_wifi,
                               kapture_data_b.records_wifi))

        record_wifi_1 = kapture.RecordWifi({
            '68:72:51:80:52:df':
            kapture.RecordWifiSignal(frequency=2417,
                                     rssi=-33.0,
                                     ssid='M1X_PicoM2'),
            '68:9c:e2:e1:b0:60':
            kapture.RecordWifiSignal(frequency=5765,
                                     rssi=-49.0,
                                     ssid='@HYUNDAI-WiFi'),
        })
        record_wifi_2 = kapture.RecordWifi({
            '68:72:51:80:52:df':
            kapture.RecordWifiSignal(frequency=2417,
                                     rssi=-35.0,
                                     ssid='M1X_PicoM2'),
            '68:9c:e2:e1:b0:60':
            kapture.RecordWifiSignal(frequency=5765,
                                     rssi=-47.0,
                                     ssid='@HYUNDAI-WiFi'),
        })
        record_wifi_2_str = kapture.RecordWifi({
            '68:72:51:80:52:df':
            kapture.RecordWifiSignal(frequency='2417',
                                     rssi='-35.0',
                                     ssid='M1X_PicoM2'),
            '68:9c:e2:e1:b0:60':
            kapture.RecordWifiSignal(frequency='5765',
                                     rssi='-47.0',
                                     ssid='@HYUNDAI-WiFi'),
        })
        # check deep copy just did nothing: recreate the B
        kapture_data_b.records_wifi = kapture.RecordsWifi()
        kapture_data_b.records_wifi[1555398770307,
                                    'AC01324954_wifi'] = record_wifi_1
        kapture_data_b.records_wifi[1555398771307,
                                    'AC01324954_wifi'] = record_wifi_2
        self.assertTrue(
            equal_records_wifi(kapture_data_a.records_wifi,
                               kapture_data_b.records_wifi))
        # check str arguments are casted to the proper types
        kapture_data_b.records_wifi[1555398771307,
                                    'AC01324954_wifi'] = record_wifi_2_str
        self.assertTrue(
            equal_records_wifi(kapture_data_a.records_wifi,
                               kapture_data_b.records_wifi))

        # check if some are missing, its not equal
        kapture_data_b.records_wifi = kapture.RecordsWifi()
        kapture_data_b.records_wifi[1555398770307,
                                    'AC01324954_wifi'] = record_wifi_1
        self.assertFalse(
            equal_records_wifi(kapture_data_a.records_wifi,
                               kapture_data_b.records_wifi))

        # just modify a single frequency
        kapture_data_b = copy.deepcopy(self._kapture_data)
        kapture_data_b.records_wifi[
            1555398770307,
            'AC01324954_wifi']['68:72:51:80:52:df'].frequency += 1
        self.assertFalse(
            equal_records_wifi(kapture_data_a.records_wifi,
                               kapture_data_b.records_wifi))

        # just modify a single rssi
        kapture_data_b = copy.deepcopy(self._kapture_data)
        kapture_data_b.records_wifi[
            1555398770307, 'AC01324954_wifi']['68:72:51:80:52:df'].rssi += 2.0
        self.assertFalse(
            equal_records_wifi(kapture_data_a.records_wifi,
                               kapture_data_b.records_wifi))

        # just modify a single bssid
        kapture_data_b = copy.deepcopy(self._kapture_data)
        dropped = kapture_data_b.records_wifi[
            1555398770307, 'AC01324954_wifi'].pop('68:72:51:80:52:df')
        self.assertFalse(
            equal_records_wifi(kapture_data_a.records_wifi,
                               kapture_data_b.records_wifi))
        kapture_data_b.records_wifi[
            1555398770307, 'AC01324954_wifi']['XX:XX:XX:XX:XX:XX'] = dropped
        self.assertFalse(
            equal_records_wifi(kapture_data_a.records_wifi,
                               kapture_data_b.records_wifi))