-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed conflict of model parameter and hints in DefaultRouter.allow_mi…
…grate (#46) Fixed conflict of model parameter and hints in DefaultRouter.allow_migrate
- Loading branch information
Showing
7 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from django.test import SimpleTestCase | ||
|
||
from django_clickhouse.migrations import RunSQL, CreateTable | ||
from django_clickhouse.routers import DefaultRouter | ||
from tests.clickhouse_models import ClickHouseTestModel | ||
|
||
|
||
class DefaultRouterAllowMigrateTest(SimpleTestCase): | ||
def setUp(self): | ||
self.router = DefaultRouter() | ||
self.operation = RunSQL('SELECT 1') | ||
|
||
def test_hints_model_class(self): | ||
hints = {'model': ClickHouseTestModel} | ||
|
||
with self.subTest('Allow migrate'): | ||
res = self.router.allow_migrate('default', 'tests', self.operation, **hints) | ||
self.assertTrue(res) | ||
|
||
with self.subTest('Reject migrate'): | ||
res = self.router.allow_migrate('other', 'tests', self.operation, **hints) | ||
self.assertFalse(res) | ||
|
||
def test_hints_model_name(self): | ||
hints = {'model': 'ClickHouseTestModel'} | ||
|
||
with self.subTest('Allow migrate'): | ||
res = self.router.allow_migrate('default', 'tests', self.operation, **hints) | ||
self.assertTrue(res) | ||
|
||
with self.subTest('Reject migrate'): | ||
res = self.router.allow_migrate('other', 'tests', self.operation, **hints) | ||
self.assertFalse(res) | ||
|
||
def test_hints_force_migrate_on_databases(self): | ||
hints = {'force_migrate_on_databases': ['secondary']} | ||
|
||
with self.subTest('Allow migrate'): | ||
res = self.router.allow_migrate('secondary', 'apps', self.operation, **hints) | ||
self.assertTrue(res) | ||
|
||
with self.subTest('Reject migrate'): | ||
res = self.router.allow_migrate('default', 'apps', self.operation, **hints) | ||
self.assertFalse(res) | ||
|
||
def test_model_operation(self): | ||
with self.subTest('Allow migrate'): | ||
operation = CreateTable(ClickHouseTestModel) | ||
res = self.router.allow_migrate('default', 'apps', operation) | ||
self.assertTrue(res) | ||
|
||
with self.subTest('Reject migrate'): | ||
operation = CreateTable(ClickHouseTestModel) | ||
res = self.router.allow_migrate('other', 'apps', operation) | ||
self.assertFalse(res) | ||
|
||
def test_no_model(self): | ||
with self.assertRaises(ValueError): | ||
self.router.allow_migrate('default', 'apps', self.operation) |