diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2014-10-02 10:59:34 +0200 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2014-10-02 10:59:34 +0200 |
commit | 9b48cf1a85ced79a22a8668e2da3a84947c4e97c (patch) | |
tree | d49f5bce93b4a54ea9f983f725ffe70ccf8ca6f2 | |
parent | effec78faacc4def3cd1f1f7fbedf79eaeb824f5 (diff) |
Added config file command line parameter to user agent.
-rw-r--r-- | service/pixelated/user_agent.py | 5 | ||||
-rw-r--r-- | service/test/user_agent_test.py | 37 |
2 files changed, 41 insertions, 1 deletions
diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py index 8c7440b0..bee0035b 100644 --- a/service/pixelated/user_agent.py +++ b/service/pixelated/user_agent.py @@ -185,17 +185,20 @@ def start_user_agent(debug_enabled): def setup(): try: + default_config_path = os.path.join(os.environ['HOME'], '.pixelated') + parser = argparse.ArgumentParser(description='Pixelated user agent.') parser.add_argument('--debug', action='store_true', help='DEBUG mode.') parser.add_argument('--register', metavar='username', help='register user with name.') + parser.add_argument('-c', '--config', metavar='configfile', default=default_config_path, help='use specified config file. Default is ~/.pixelated.') args = parser.parse_args() debug_enabled = args.debug or os.environ.get('DEBUG', False) reactor_manager.start_reactor(logging=debug_enabled) crochet.setup() - app.config.from_pyfile(os.path.join(os.environ['HOME'], '.pixelated')) + app.config.from_pyfile(args.config) if args.register: register_new_user(args.register) diff --git a/service/test/user_agent_test.py b/service/test/user_agent_test.py index d0cfc5a9..fea8393a 100644 --- a/service/test/user_agent_test.py +++ b/service/test/user_agent_test.py @@ -19,9 +19,13 @@ import pixelated.user_agent from pixelated.adapter.pixelated_mail import PixelatedMail from pixelated.adapter.pixelated_mail import InputMail from mockito import * +import crochet +import pixelated.reactor_manager as reactor_manager import test.adapter.test_helper as test_helper import json import pixelated.adapter.pixelated_mail +import sys +import os class UserAgentTest(unittest.TestCase): @@ -35,6 +39,9 @@ class UserAgentTest(unittest.TestCase): self.input_mail = None pixelated.adapter.pixelated_mail.input_mail_from_dict = lambda x: self.input_mail + def tearDown(self): + unstub() + def test_create_or_send_draft_should_create_draft_if_mail_has_no_ident(self): self.input_mail = self.draft() @@ -60,3 +67,33 @@ class UserAgentTest(unittest.TestCase): def draft(self): return test_helper.input_mail() + + def test_that_default_config_file_is_home_dot_pixelated(self): + orig_config = pixelated.user_agent.app.config + try: + when(crochet).setup().thenReturn(None) + when(reactor_manager).start_reactor().thenReturn(None) + when(pixelated.user_agent).start_user_agent().thenReturn(None) + pixelated.user_agent.app.config = mock() + + sys.argv = ['/tmp/does_not_exist'] + pixelated.user_agent.setup() + + verify(pixelated.user_agent.app.config).from_pyfile(os.path.join(os.environ['HOME'], '.pixelated')) + finally: + pixelated.user_agent.app.config = orig_config + + def test_that_config_file_can_be_specified_on_command_line(self): + orig_config = pixelated.user_agent.app.config + try: + when(crochet).setup().thenReturn(None) + when(reactor_manager).start_reactor().thenReturn(None) + when(pixelated.user_agent).start_user_agent().thenReturn(None) + pixelated.user_agent.app.config = mock() + + sys.argv = ['/tmp/does_not_exist', '--config', '/tmp/some/config/file'] + pixelated.user_agent.setup() + + verify(pixelated.user_agent.app.config).from_pyfile('/tmp/some/config/file') + finally: + pixelated.user_agent.app.config = orig_config |