diff options
| author | Claude Paroz <claude@2xlibre.net> | 2015-10-23 21:02:34 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2015-10-29 20:12:38 +0100 |
| commit | 7d81ee6efc385f7d4c1218639e4102c64495ba0f (patch) | |
| tree | 1ad9200f0775f223cff67b770dbda1f929e516d3 /tests | |
| parent | 9dcfecb7c6c8285630ad271888a9ec4ba9140e3a (diff) | |
Fixed #16734 -- Set script prefix even outside of requests
Thanks Tim Graham for the review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/user_commands/management/commands/reverse_url.py | 10 | ||||
| -rw-r--r-- | tests/user_commands/tests.py | 19 | ||||
| -rw-r--r-- | tests/user_commands/urls.py | 5 |
3 files changed, 34 insertions, 0 deletions
diff --git a/tests/user_commands/management/commands/reverse_url.py b/tests/user_commands/management/commands/reverse_url.py new file mode 100644 index 0000000000..f2064bf05d --- /dev/null +++ b/tests/user_commands/management/commands/reverse_url.py @@ -0,0 +1,10 @@ +from django.core.management.base import BaseCommand +from django.core.urlresolvers import reverse + + +class Command(BaseCommand): + """ + This command returns a URL from a reverse() call. + """ + def handle(self, *args, **options): + return reverse('some_url') diff --git a/tests/user_commands/tests.py b/tests/user_commands/tests.py index 772da22bed..048ac4d963 100644 --- a/tests/user_commands/tests.py +++ b/tests/user_commands/tests.py @@ -1,5 +1,7 @@ import os +from admin_scripts.tests import AdminScriptTestCase + from django.apps import apps from django.core import management from django.core.management import BaseCommand, CommandError, find_commands @@ -159,6 +161,23 @@ class CommandTests(SimpleTestCase): BaseCommand.check = saved_check +class CommandRunTests(AdminScriptTestCase): + """ + Tests that need to run by simulating the command line, not by call_command. + """ + def tearDown(self): + self.remove_settings('settings.py') + + def test_script_prefix_set_in_commands(self): + self.write_settings('settings.py', apps=['user_commands'], sdict={ + 'ROOT_URLCONF': '"user_commands.urls"', + 'FORCE_SCRIPT_NAME': '"/PREFIX/"', + }) + out, err = self.run_manage(['reverse_url']) + self.assertNoOutput(err) + self.assertEqual(out.strip(), '/PREFIX/some/url/') + + class UtilsTests(SimpleTestCase): def test_no_existent_external_program(self): diff --git a/tests/user_commands/urls.py b/tests/user_commands/urls.py new file mode 100644 index 0000000000..fe20693dce --- /dev/null +++ b/tests/user_commands/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls import url + +urlpatterns = [ + url(r'^some/url/$', lambda req:req, name='some_url'), +] |
