Skip to content

Commit

Permalink
Routes command should import settings
Browse files Browse the repository at this point in the history
It loads modules, which might need setup code, e.g. `django.setup()`

Fixes #128
  • Loading branch information
moggers87 committed Dec 13, 2019
1 parent d061cbc commit 68dd4ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions salmon/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ def routes(modules, test, path):
sys.path += path.split(':')
test_case_matches = []

utils.import_settings(False)

for module in modules:
try:
import_module(module)
Expand Down
6 changes: 5 additions & 1 deletion tests/command_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from click import testing
from mock import Mock, patch

from salmon import queue, commands, encoding, mail, routing
from salmon import queue, commands, encoding, mail, routing, utils

from .setup_env import SalmonTestCase

Expand Down Expand Up @@ -296,6 +296,7 @@ def setUp(self):
routing.Router.clear_routes()
routing.Router.clear_states()
routing.Router.HANDLERS.clear()
utils.settings = None

def test_no_args(self):
runner = CliRunner()
Expand All @@ -306,6 +307,7 @@ def test_not_importable(self):
runner = CliRunner()
result = runner.invoke(commands.main, ("routes", "not_a_module", "--test", "user@example.com"))
self.assertEqual(result.exit_code, 1)
self.assertIsNotNone(utils.settings)
self.assertEqual(result.output,
("Error: Module 'not_a_module' could not be imported. "
"Did you forget to use the --path option?\n"))
Expand All @@ -314,6 +316,7 @@ def test_match(self):
runner = CliRunner()
result = runner.invoke(commands.main, ("routes", "salmon.handlers.log", "--test", "user@example.com"))
self.assertEqual(result.exit_code, 0)
self.assertIsNotNone(utils.settings)
# TODO: use groupdict directly once Python 2.7 support has been dropped
match_items = [i for i in
routing.Router.REGISTERED.values()][0][0].match("user@example.com").groupdict().items()
Expand All @@ -332,6 +335,7 @@ def test_no_match(self):
runner = CliRunner()
result = runner.invoke(commands.main, ("routes", "salmon.handlers.log", "--test", "userexample.com"))
self.assertEqual(result.exit_code, 1)
self.assertIsNotNone(utils.settings)
self.assertEqual(result.output,
("Routing ORDER: ['^(?P<to>.+)@(?P<host>.+)$']\n"
"Routing TABLE:\n"
Expand Down

0 comments on commit 68dd4ba

Please sign in to comment.