Opened 11 years ago
Last modified 11 years ago
#24759 new New feature
Add or document a way to test data migrations
| Reported by: | Tom Linford | Owned by: | nobody |
|---|---|---|---|
| Component: | Testing framework | Version: | 1.8 |
| Severity: | Normal | Keywords: | migrations |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
At Robinhood, we've been using a custom in-house MigrationTestCase that we'd like to contribute, but want to check the API of it before contributing it. Here's the definition of the class:
class MigrationTestCase(TransactionTestCase):
"""
app_label: name of app (ie. "users" or "polls")
(start|dest)_migration_name: name of migration in app
(e.g. "0001_initial")
additional_dependencies: list of tuples of `(app_label, migration_name)`.
Add any additional migrations here that need to be included in the
generation of the model states.
Usage:
class TestCase(MigrationTestCase):
app_label = ...
start_migration_name = ...
dest_migration_name = ...
additional_dependencies = ...
def setUp(self):
# Create models with regular orm
super(TestCase, self).setUp()
# Create models with start orm. Access model with:
# self.start_models["<app_label>"]["<model_name>"]
# Note that model_name must be all lower case, you can just do:
# <instance>._meta.model_name to get the model_name
def test(self):
# Still using start orm
self.migrate_to_dest()
# Now, you can access dest models with:
# self.dest_models["<app_label>"]["<model_name>"]
"""
app_label = None
start_migration_name = None
dest_migration_name = None
additional_dependencies = []
Let me know if this API is agreeable and I can make a PR for this feature.
Change History (2)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
| Summary: | MigrationTestCase → Add or document a way to test data migrations |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
Accepting on the basis of some way to test data migrations.
Note:
See TracTickets
for help on using tickets.
The DevelopersMailingList is a better place to propose and get feedback on features like this.