anthony sottile 28f5037299 ref: enable pyupgrade --py311-plus (#64363) | 1 year ago | |
---|---|---|
.. | ||
snapshots | 969ba26c4e feat(metrics-extraction): Add spec version column for on-demand (#64208) | 1 year ago |
README.md | ffce497273 feat(backup): Add correctness snapshot test (#51925) | 1 year ago |
__init__.py | 28f5037299 ref: enable pyupgrade --py311-plus (#64363) | 1 year ago |
test_comparators.py | 57bbfd4459 feat(backup): Add EqualOrRemovedComparator (#62699) | 1 year ago |
test_coverage.py | cfa79ebcf3 ref(backup): Split backup `helpers` module (#63075) | 1 year ago |
test_dependencies.py | f6263b286f chore: run prettier on our yaml, json, markdown (#59871) | 1 year ago |
test_exhaustive.py | c8a00d1cf6 ref: pep 585 pyupgrade --py311-plus changes (#64275) | 1 year ago |
test_exports.py | c8a00d1cf6 ref: pep 585 pyupgrade --py311-plus changes (#64275) | 1 year ago |
test_findings.py | c8a00d1cf6 ref: pep 585 pyupgrade --py311-plus changes (#64275) | 1 year ago |
test_imports.py | c8a00d1cf6 ref: pep 585 pyupgrade --py311-plus changes (#64275) | 1 year ago |
test_invariants.py | cfa79ebcf3 ref(backup): Split backup `helpers` module (#63075) | 1 year ago |
test_models.py | c8a00d1cf6 ref: pep 585 pyupgrade --py311-plus changes (#64275) | 1 year ago |
test_releases.py | c8a00d1cf6 ref: pep 585 pyupgrade --py311-plus changes (#64275) | 1 year ago |
test_rpc.py | 7a00c55924 ref: pep 604 pyupgrade --py311-plus changes (#64349) | 1 year ago |
test_snapshots.py | 5fc3754445 ref: remove deprecated return-from-test-function (#60130) | 1 year ago |
test_validate.py | c7d1cc6928 feat(backup): Allow custom ordinals during validation (#60156) | 1 year ago |
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.
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.
A number of default starter snapshots are provided to bootstrap this test flow.
This represents the state of the database immediately after running ./install.sh
to create a new
instance of self-hosted
.