Improve logentry shredder function

This commit is contained in:
Raphael Michel
2023-12-21 22:46:19 +01:00
parent 12804ff1a0
commit 8c8650090d
2 changed files with 101 additions and 6 deletions

View File

@@ -39,6 +39,7 @@ from pretix.base.shredder import (
AttendeeInfoShredder, CachedTicketShredder, EmailAddressShredder,
InvoiceAddressShredder, InvoiceShredder, PaymentInfoShredder,
QuestionAnswerShredder, WaitingListShredder, shred_constraints,
shred_log_fields,
)
@@ -412,3 +413,83 @@ def test_shred_constraint_after_event_subevents(event):
date_to=now_dt + timedelta(hours=1)
)
assert shred_constraints(event)
@pytest.mark.django_db
def test_shred_log_fields_banlist(event):
le = event.log_action("foo.bar", data={
"dict": {
"subdict": {
"foo": "bar",
"empty": None,
}
},
"list": [
{
"foo": "bar",
},
"baz",
],
"string": "foo",
"bool": True,
"int": 0,
})
shred_log_fields(le, banlist=["dict", "list", "int", "bool"])
assert le.shredded
assert le.parsed_data == {
"dict": {
"subdict": {
"foo": "",
"empty": None,
}
},
"list": [
{
"foo": "",
},
"",
],
"string": "foo",
"bool": "",
"int": 0,
}
@pytest.mark.django_db
def test_shred_log_fields_whitelist(event):
le = event.log_action("foo.bar", data={
"dict": {
"subdict": {
"foo": "bar",
"empty": None,
}
},
"list": [
{
"foo": "bar",
},
"baz",
],
"string": "foo",
"bool": True,
"int": 0,
})
shred_log_fields(le, whitelist=["string"])
assert le.shredded
assert le.parsed_data == {
"dict": {
"subdict": {
"foo": "",
"empty": None,
}
},
"list": [
{
"foo": "",
},
"",
],
"string": "foo",
"bool": "",
"int": 0,
}