Skip to content
Browse files

updated and tested cmd line option parser

  • Loading branch information...
1 parent 8c850cc commit 369d60f237efa03709dbef299e4727b80f154fab @theduderog theduderog committed Aug 1, 2012
Showing with 37 additions and 2 deletions.
  1. +17 −2 superlance/process_state_email_monitor.py
  2. +20 −0 superlance/tests/process_state_email_monitor_test.py
View
19 superlance/process_state_email_monitor.py
@@ -30,7 +30,7 @@ class ProcessStateEmailMonitor(ProcessStateMonitor):
COMMASPACE = ', '
@classmethod
- def create_from_cmd_line(cls):
+ def parse_cmd_line_options(cls):
from optparse import OptionParser
parser = OptionParser()
@@ -48,13 +48,28 @@ def create_from_cmd_line(cls):
help="TICK event name (defaults to TICK_60)")
(options, args) = parser.parse_args()
-
+ return options
+
+ @classmethod
+ def validate_cmd_line_options(cls, options):
if not options.to_emails:
parser.print_help()
sys.exit(1)
if not options.from_email:
parser.print_help()
sys.exit(1)
+
+ validated = copy.copy(options)
+ validated.to_emails = [x.strip() for x in options.to_emails.split(",")]
+ return validated
+
+ @classmethod
+ def get_cmd_line_options(cls):
+ return cls.validate_cmd_line_options(cls.parse_cmd_line_options())
+
+ @classmethod
+ def create_from_cmd_line(cls):
+ options = cls.get_cmd_line_options()
if not 'SUPERVISOR_SERVER_URL' in os.environ:
sys.stderr.write('Must run as a supervisor event listener\n')
View
20 superlance/tests/process_state_email_monitor_test.py
@@ -37,6 +37,26 @@ def _make_one_mock_send_smtp(self, **kwargs):
obj = self._make_one(**kwargs)
obj.send_smtp = mock.Mock()
return obj
+
+ def test_validate_cmd_line_options_single_to_email_ok(self):
+ klass = self._get_target_class()
+
+ options = mock.Mock()
+ options.from_email = 'blah'
+ options.to_emails = 'frog'
+
+ validated = klass.validate_cmd_line_options(options)
+ self.assertEquals(['frog'], validated.to_emails)
+
+ def test_validate_cmd_line_options_multi_to_emails_ok(self):
+ klass = self._get_target_class()
+
+ options = mock.Mock()
+ options.from_email = 'blah'
+ options.to_emails = 'frog, log,dog'
+
+ validated = klass.validate_cmd_line_options(options)
+ self.assertEquals(['frog', 'log', 'dog'], validated.to_emails)
def test_send_email_ok(self):
email = {

0 comments on commit 369d60f

Please sign in to comment.
Something went wrong with that request. Please try again.