def test_serialize(self, time, uuid): time.return_value = 333 uuid.return_value = "1-2-3-4" event = Event("topic", "type") event.set_field("normal", "value1") event.set_field("obfuscated", "value2", kind=FieldKind.OBFUSCATED) event.set_field("high_cardinality", "value3", kind=FieldKind.HIGH_CARDINALITY) event.set_field("empty", "") event.set_field("null", None) serialized = event.serialize() deserialized = json.loads(serialized) self.assertEqual( deserialized, { "event_topic": "topic", "event_type": "type", "event_ts": 333000, "uuid": "1-2-3-4", "payload": { "normal": "value1", "obfuscated_data": { "obfuscated": "value2", }, "interana_excluded": { "high_cardinality": "value3", }, }, })
def test_serialize(self, time, uuid): time.return_value = 333 uuid.return_value = "1-2-3-4" event = Event("topic", "type") event.set_field("normal", "value1") event.set_field("obfuscated", "value2", kind=FieldKind.OBFUSCATED) event.set_field("high_cardinality", "value3", kind=FieldKind.HIGH_CARDINALITY) event.set_field("empty", "") event.set_field("null", None) serialized = event.serialize() deserialized = json.loads(serialized) self.assertEqual(deserialized, { "event_topic": "topic", "event_type": "type", "event_ts": 333000, "uuid": "1-2-3-4", "payload": { "normal": "value1", "obfuscated_data": { "obfuscated": "value2", }, "interana_excluded": { "high_cardinality": "value3", }, }, })
def test_serialize(self, time, uuid): time.return_value = 333 uuid.return_value = "1-2-3-4" event = Event("topic", "type") event.set_field("normal", "value1") event.set_field("obfuscated", "value2", obfuscate=True) event.set_field("empty", "") event.set_field("null", None) serialized = event.serialize() deserialized = json.loads(serialized) self.assertEqual(deserialized, { "event_topic": "topic", "event_type": "type", "event_ts": 333000, "uuid": "1-2-3-4", "payload": { "normal": "value1", "obfuscated_data": { "obfuscated": "value2", }, }, })
def test_set_field(self, time, uuid): time.return_value = 333 uuid.return_value = "1-2-3-4" event = Event("topic", "type") with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") event.set_field("deprecated", "value", obfuscate=True) self.assertEqual(len(w), 1) self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) self.assertIn("deprecated", str(w[-1].message)) self._assert_payload(event, {"obfuscated_data": { "deprecated": "value" }})
def test_set_field(self, time, uuid): time.return_value = 333 uuid.return_value = "1-2-3-4" event = Event("topic", "type") with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") event.set_field("deprecated", "value", obfuscate=True) self.assertEqual(len(w), 1) self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) self.assertIn("deprecated", str(w[-1].message)) self._assert_payload(event, { "obfuscated_data": { "deprecated": "value", }, })
def test_get_field(self, time, uuid): time.return_value = 333 uuid.return_value = "1-2-3-4" event = Event("topic", "type") event.set_field("normal", "value1") event.set_field("obfuscated", "value2", kind=FieldKind.OBFUSCATED) event.set_field("high_cardinality", "value3", kind=FieldKind.HIGH_CARDINALITY) self.assertEqual(event.get_field("normal"), "value1") self.assertEqual(event.get_field("obfuscated"), "value2") self.assertEqual(event.get_field("high_cardinality"), "value3")
def test_set_field_same_key_different_sections(self, time, uuid): time.return_value = 333 uuid.return_value = "1-2-3-4" event = Event("topic", "type") event.set_field("foo", "bar") self._assert_payload(event, { "foo": "bar", }) event.set_field("foo", "bar", kind=FieldKind.OBFUSCATED) self._assert_payload(event, { "obfuscated_data": { "foo": "bar", }, }) event.set_field("foo", "bar") self._assert_payload(event, { "foo": "bar", }) event.set_field("foo", "bar", kind=FieldKind.HIGH_CARDINALITY) self._assert_payload(event, { "interana_excluded": { "foo": "bar", }, }) event.set_field("foo", "bar") self._assert_payload(event, { "foo": "bar", }) event.set_field("foo", "bar", kind=FieldKind.HIGH_CARDINALITY) self._assert_payload(event, { "interana_excluded": { "foo": "bar", }, }) event.set_field("foo", "bar", kind=FieldKind.OBFUSCATED) self._assert_payload(event, { "obfuscated_data": { "foo": "bar", }, }) event.set_field("foo", "bar", kind=FieldKind.HIGH_CARDINALITY) self._assert_payload(event, { "interana_excluded": { "foo": "bar", }, })