diff options
| author | Claude Paroz <claude@2xlibre.net> | 2015-05-09 17:01:40 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2015-05-13 18:30:36 +0200 |
| commit | f61c4f490dc4c8ec6ba94ad4f40247db2425fc3e (patch) | |
| tree | 8ce61422333b0b4fb850a13b1f776f0024bd0d1d /tests/admin_scripts | |
| parent | 3c8fe5dddf34533a419d2deed5208a28de32cb4a (diff) | |
Fixed #24742 -- Made runserver.check_migrations ignore read-only databases
Thanks Luis Del Giudice for the report, and Aymeric Augustin and Markus
Holtermann for the reviews.
Diffstat (limited to 'tests/admin_scripts')
| -rw-r--r-- | tests/admin_scripts/tests.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index fbf28ad4f2..6343d89c3e 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -22,6 +22,9 @@ from django.conf import settings from django.core.management import ( BaseCommand, CommandError, call_command, color, ) +from django.db import ConnectionHandler +from django.db.migrations.exceptions import MigrationSchemaMissing +from django.db.migrations.recorder import MigrationRecorder from django.test import LiveServerTestCase, TestCase, mock, override_settings from django.test.runner import DiscoverRunner from django.utils._os import npath, upath @@ -1247,7 +1250,8 @@ class ManageRunserver(AdminScriptTestCase): def monkey_run(*args, **options): return - self.cmd = Command() + self.output = StringIO() + self.cmd = Command(stdout=self.output) self.cmd.run = monkey_run def assertServerSettings(self, addr, port, ipv6=None, raw_ipv6=False): @@ -1298,6 +1302,26 @@ class ManageRunserver(AdminScriptTestCase): self.cmd.handle(addrport="deadbeef:7654") self.assertServerSettings('deadbeef', '7654') + def test_no_database(self): + """ + Ensure runserver.check_migrations doesn't choke on empty DATABASES. + """ + tested_connections = ConnectionHandler({}) + with mock.patch('django.core.management.commands.runserver.connections', new=tested_connections): + self.cmd.check_migrations() + + def test_readonly_database(self): + """ + Ensure runserver.check_migrations doesn't choke when a database is read-only + (with possibly no django_migrations table). + """ + with mock.patch.object( + MigrationRecorder, 'ensure_schema', + side_effect=MigrationSchemaMissing()): + self.cmd.check_migrations() + # Check a warning is emitted + self.assertIn("Not checking migrations", self.output.getvalue()) + class ManageRunserverEmptyAllowedHosts(AdminScriptTestCase): def setUp(self): |
