def test_samples_to_entity_set__invalid_location(self,
                                                     mock_convert_geometries):

        fake_sample_list = [GOOD_POINT_SAMPLE]
        with self.assertRaisesRegex(
                ValueError,
                r"Error processing sample at index 0. Samples must define a location \(point, path, or polygon\)."
        ):
            util.samples_to_entity_set(fake_sample_list)
    def test_samples_to_entity_set__invalid_id(self):
        NO_ID_SAMPLE = {
            'id': '',
            'kind': 'fake kind',
            'time': datetime.datetime.today(),
            'point': 'fake point'
        }

        fake_sample_list = [NO_ID_SAMPLE]
        with self.assertRaisesRegex(
                ValueError, 'Error processing sample at index 0. Invalid ID.'):
            util.samples_to_entity_set(fake_sample_list)
    def test_samples_to_entity_set__invalid_time(self):
        NO_ID_SAMPLE = {
            'id': 'fake ID',
            'kind': 'fake kind',
            'point': 'fake point',
            'time': None
        }

        fake_sample_list = [NO_ID_SAMPLE]
        with self.assertRaisesRegex(
                ValueError,
                'Error processing sample at index 0. Invalid time.'):
            util.samples_to_entity_set(fake_sample_list)
    def test_samples_to_entity_set__no_time(self):
        NO_ID_SAMPLE = {
            'id': 'fake ID',
            'kind': 'fake kind',
            'point': 'fake point'
        }

        fake_sample_list = [NO_ID_SAMPLE]
        with self.assertRaisesRegex(
                ValueError,
                'Error processing sample at index 0. Samples must include a time field.'
        ):
            util.samples_to_entity_set(fake_sample_list)
    def test_samples_to_entity_set__time_not_datetime(self):
        NO_ID_SAMPLE = {
            'id': 'fake ID',
            'kind': 'fake kind',
            'point': 'fake point',
            'time': 'invalid time',
        }

        fake_sample_list = [NO_ID_SAMPLE]
        with self.assertRaisesRegex(
                TypeError,
                'Error processing sample at index 0. Time must be a datetime object.'
        ):
            util.samples_to_entity_set(fake_sample_list)
    def test_samples_to_entity_set(self, mock_convert_geometries,
                                   mock_get_attributes,
                                   mock_datetime_to_timestamp):

        fake_sample_list = [GOOD_POINT_SAMPLE]
        expected_entity_set = {
            'entities': [{
                'identity': GOOD_POINT_SAMPLE['id'],
                'kind': GOOD_POINT_SAMPLE['kind'],
                'timestamp_ms': 'fake sample time',
                'endtime_ms': 'fake sample time',
                'path': 'fake converted geometries',
                'attrs': 'fake attributes',
            }]
        }
        self.assertEqual(util.samples_to_entity_set(fake_sample_list),
                         expected_entity_set)
        mock_convert_geometries.assert_called_once_with(GOOD_POINT_SAMPLE)
        mock_get_attributes.assert_called_once_with(['_kind'],
                                                    GOOD_POINT_SAMPLE)
        mock_datetime_to_timestamp.assert_called_with(
            GOOD_POINT_SAMPLE['time'])
        self.assertEqual(len(mock_datetime_to_timestamp.call_args_list), 2)