Josh Callender 37350314a8 Update the Action Model (#79923) 4 months ago
..
snapshots 37350314a8 Update the Action Model (#79923) 4 months ago
README.md ffce497273 feat(backup): Add correctness snapshot test (#51925) 1 year ago
__init__.py ff1b84a557 perf: remove jsondata usages (#70608) 10 months ago
test_comparators.py ff1b84a557 perf: remove jsondata usages (#70608) 10 months ago
test_coverage.py e892643a80 chore(control_silo): Move User model to new home in users package (#75597) 7 months ago
test_dependencies.py 32ea9d7146 perf: move sentry/backup to orjson (#71652) 9 months ago
test_exhaustive.py 01d69f1dcb feat(admin): Impove user account merging (#72692) 9 months ago
test_exports.py 0bac3a42de Add comment to export test to help understand the test failure (#78182) 5 months ago
test_findings.py e701623b19 ref(control_silo): Move Email model to Users module (#75915) 7 months ago
test_imports.py d8ecb26edf ref(control_silo): Move UserOption model to users module (#76231) 7 months ago
test_invariants.py cfa79ebcf3 ref(backup): Split backup `helpers` module (#63075) 1 year ago
test_models.py ff1b84a557 perf: remove jsondata usages (#70608) 10 months ago
test_releases.py 3279650619 feat(relocation): 24.9.0 release tests (#77676) 6 months ago
test_rpc.py e892643a80 chore(control_silo): Move User model to new home in users package (#75597) 7 months ago
test_sanitize.py 4261c76c4f chore(models): Prevent use of `DefaultFieldsModelExisting` (#80032) 4 months ago
test_snapshots.py 01d69f1dcb feat(admin): Impove user account merging (#72692) 9 months ago
test_validate.py 32ea9d7146 perf: move sentry/backup to orjson (#71652) 9 months ago

README.md

Backup tests

This directory tests a number of scenarios where we take an empty database, import a given backup .json file, optionally perform some transform, re-export it and validate the diff. The expected result is that only the changes we have made are reflected in the final diff between the original input .json that we imported, and the final output .json that we exported.

Comparators

A number of fields in the export JSON format are not so easily compared before and after running through an import/export cycle. We introduce "comparators" to account for such cases. Comparators are custom, model-specific ways of comparing portions of two json files that take into account more nuanced validations beyond the simple character-for-character matching that the default diffing algorithm provides for us.

For example, date_updated fields that change due to the very act of importing the JSON, or hashes that may change between import and export. In these cases, we may choose to simply validate that the exported date_updated is greater than the imported value for the same model instance, or that hashes match some general regex rule around size and valid characters without being identical.

Comparator functions should implement the JSONMutatingComparator callback protocol, and be included in the COMPARATORS dictionary, matching them to the models they are applicable to. Note that the comparator is explicitly described as "mutating" - this is important, as part of its functionality is to modify the compared fields in both the expected and actual output, so that text-based JSON diffing does not fail on them. In the example above, the date_updated field in both the expected and actual JSON should be replaced with some obvious sentinel value indicating that a comparator-initiated mutation took place, like __COMPARATOR_DATE_UPDATED__.

While it may be tempting to remove the offending field, or to make the actual match the expected after the comparison is completed, this is discouraged, as it will result in the subsequent JSON diff looking identical, potentially confusing future readers. Better to just throw up a very obvious signal that "a framework-generated replacement occurred here" to make future debugging less stressful.

Snapshots

A number of default starter snapshots are provided to bootstrap this test flow.

fresh_install.json

This represents the state of the database immediately after running ./install.sh to create a new instance of self-hosted.