|
| 1 | +from datetime import datetime |
| 2 | + |
1 | 3 | from django.core.management import call_command
|
2 | 4 | from django.db import connection
|
3 | 5 | from django.db.migrations.executor import MigrationExecutor
|
@@ -50,6 +52,66 @@ def tearDownClass(cls) -> None:
|
50 | 52 | call_command("migrate", verbosity=0, database=connection._alias)
|
51 | 53 |
|
52 | 54 |
|
| 55 | +class SwitchToNewTokenAuthModelTestCase(BaseMigrationTest): |
| 56 | + app = "token" |
| 57 | + migrate_from = "0005_tokenauth" |
| 58 | + migrate_to = "0006_copy_token_auth" |
| 59 | + |
| 60 | + def test_migrate_to_new_model(self): |
| 61 | + OldTokenAuth = self.old_app_state.get_model("token", "OldTokenAuth") |
| 62 | + |
| 63 | + token = OldTokenAuth.objects.create( |
| 64 | + token="foo", |
| 65 | + contact_person="john doe", |
| 66 | + email="john@example.com", |
| 67 | + organization="ACME", |
| 68 | + last_modified=datetime(2024, 1, 1), |
| 69 | + created=datetime(2024, 1, 1), |
| 70 | + application="Foo", |
| 71 | + administration="Bar", |
| 72 | + ) |
| 73 | + |
| 74 | + self.assertEqual(token.pk, "foo") |
| 75 | + |
| 76 | + self._perform_migration() |
| 77 | + |
| 78 | + TokenAuth = self.apps.get_model("token", "TokenAuth") |
| 79 | + token = TokenAuth.objects.get() |
| 80 | + |
| 81 | + self.assertTrue(isinstance(token.pk, int)) |
| 82 | + self.assertEqual(token.token, "foo") |
| 83 | + |
| 84 | + |
| 85 | +class SwitchToOldTokenAuthModelTestCase(BaseMigrationTest): |
| 86 | + app = "token" |
| 87 | + migrate_from = "0006_copy_token_auth" |
| 88 | + migrate_to = "0005_tokenauth" |
| 89 | + |
| 90 | + def test_migrate_to_old_model(self): |
| 91 | + TokenAuth = self.old_app_state.get_model("token", "TokenAuth") |
| 92 | + |
| 93 | + token = TokenAuth.objects.create( |
| 94 | + token="foo", |
| 95 | + contact_person="john doe", |
| 96 | + email="john@example.com", |
| 97 | + organization="ACME", |
| 98 | + last_modified=datetime(2024, 1, 1), |
| 99 | + created=datetime(2024, 1, 1), |
| 100 | + application="Foo", |
| 101 | + administration="Bar", |
| 102 | + ) |
| 103 | + |
| 104 | + self.assertTrue(isinstance(token.pk, int)) |
| 105 | + |
| 106 | + self._perform_migration() |
| 107 | + |
| 108 | + OldTokenAuth = self.apps.get_model("token", "OldTokenAuth") |
| 109 | + token = OldTokenAuth.objects.get() |
| 110 | + |
| 111 | + self.assertEqual(token.pk, "foo") |
| 112 | + self.assertEqual(token.token, "foo") |
| 113 | + |
| 114 | + |
53 | 115 | class TestTokenAuthUniqueness(BaseMigrationTest):
|
54 | 116 | app = "token"
|
55 | 117 | migrate_from = "0008_alter_tokenauth_token"
|
|
0 commit comments