-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backup): Support comparators (#52597)
This change introduces the idea of comparators, or special handlers for comparing JSON fields on exported models that cannot be tested for simple stringh equivalency. The first of these comparators, the `DateUpdatedComparator`, is added to ensure that comparisons on models that have an audit timetamp incremented every time they are mutated are still able to succeed.
- Loading branch information
1 parent
46c8af5
commit d1563a1
Showing
3 changed files
with
196 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from sentry.runner.commands.backup import DateUpdatedComparator, InstanceID | ||
|
||
|
||
def test_good_date_updated_comparator(): | ||
cmp = DateUpdatedComparator("my_date_field") | ||
id = InstanceID("test", 1) | ||
left = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"my_date_field": "2023-06-22T23:00:00.123Z", | ||
}, | ||
} | ||
right = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"my_date_field": "2023-06-22T23:00:00.123Z", | ||
}, | ||
} | ||
assert cmp.compare(id, left, right) is None | ||
|
||
|
||
def test_bad_date_updated_comparator(): | ||
cmp = DateUpdatedComparator("my_date_field") | ||
id = InstanceID("test", 1) | ||
left = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"my_date_field": "2023-06-22T23:12:34.567Z", | ||
}, | ||
} | ||
right = { | ||
"model": "test", | ||
"pk": 1, | ||
"fields": { | ||
"my_date_field": "2023-06-22T23:00:00.001Z", | ||
}, | ||
} | ||
res = cmp.compare(id, left, right) | ||
assert res is not None | ||
assert res.on == id | ||
assert res.kind == "DateUpdatedComparator" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters