Skip to content

South - FKs between apps #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion tests/test_second_app/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ def test_both_migrated(self):
self.assertEqual(mymodel.number, 10)


# TODO: conclude if this is permanent, or if there is a workaround.
@unittest.skipIf(django.VERSION < (1, 7), 'Not supported by South')
class SecondAppFKToTestAppMigrationTest(MigrationTest):
"""We don't actually migrate anything here, before and after are the
same. We just check that the model we load can be linked and
saved, even if they come from different apps.

See SecondAppFKToTestAppUsingPksMigrationTest for a
south-supported approach.

"""

app_name = 'test_second_app'
Expand All @@ -98,6 +100,28 @@ def test_save_and_reload_model(self):
mymodelsecond.save()


class SecondAppFKToTestAppUsingPksMigrationTest(MigrationTest):
"""Copy of SecondAppFKToTestAppMigrationTest but uses pks instead of
django's orm magic. Also have to declare in before and after the
migrations for all the models that are used.

"""

before = [('test_app', '0005'), ('test_second_app', '0003')]
after = [('test_app', '0005'), ('test_second_app', '0003')]

def test_save_and_reload_model(self):
MyModelSecond = self.get_model_before('test_second_app.MyModel')
MyModelFirst = self.get_model_before('test_app.MyModel')

mymodelfirst = MyModelFirst()
mymodelfirst.save()

mymodelsecond = MyModelSecond()
mymodelsecond.my_model_id = mymodelfirst.pk
mymodelsecond.save()


class MigrateFromZero(MigrationTest):
before = [('test_app', '0002'), ('test_second_app', 'zero')]
after = [('test_app', '0002'), ('test_second_app', '0001')]
Expand Down