Ejemplo n.º 1
0
    def test_args_optional(self):
        with captured(out(), err()) as (stdout, stderr):
            with mock_args([]):
                TestCommand.main()
        self.assertIn('opt=None', stdout.getvalue())

        with captured(out(), err()) as (stdout, stderr):
            with mock_args(['--opt', 'OPT']):
                TestCommand.main()
        self.assertIn('opt=OPT', stdout.getvalue())
Ejemplo n.º 2
0
    def test_args_logging_level(self):
        with captured(out(), err()) as (stdout, stderr):
            with mock_args([]):
                TestCommand.main()
        self.assertIn('logging_level=%s' % logging.WARNING, stdout.getvalue())

        with captured(out(), err()) as (stdout, stderr):
            with mock_args(['--verbose']):
                TestCommand.main()
        self.assertIn('logging_level=%s' % logging.INFO, stdout.getvalue())

        with captured(out(), err()) as (stdout, stderr):
            with mock_args(['--debug']):
                TestCommand.main()
        self.assertIn('logging_level=%s' % logging.DEBUG, stdout.getvalue())
Ejemplo n.º 3
0
    def test_nominal(self, m_worker_cls):
        m_worker = m_worker_cls.return_value
        m_worker.run.side_effect = [None, None, KeyboardInterrupt('KILLTEST')]

        args = [
            '-d', 'DOMAIN', '-m', 'caravan.tests.fixtures', '-t', 'TASKLIST',
            ]

        with mock_args(args):
            with self.assertRaises(SystemExit) as exc:
                Command.main()

        self.assertEqual(exc.exception.code, 1)
        self.assertEqual(m_worker.run.call_count, 3)

        args, kwargs = m_worker_cls.call_args
        self.assertEqual(kwargs['domain'], 'DOMAIN')
        self.assertEqual(kwargs['task_list'], 'TASKLIST')
        self.assertEqual(kwargs['workflows'],
                         [fixtures.TestWorkflow1, fixtures.TestWorkflow2])

        # Boto3 client object are dynamically forged...
        swf_connection = kwargs['connection']
        self.assertEqual(swf_connection.__class__.__name__, 'SWF')
        self.assertEqual(swf_connection.__class__.__module__, 'botocore.client')
Ejemplo n.º 4
0
def run_command(additional_args):
    httpretty_register()

    args = ["-d", "DOMAIN"]
    args += additional_args
    with captured(out(), err()) as (stdout, stderr):
        with mock_args(args):
            Command.main()

    return stdout, stderr
Ejemplo n.º 5
0
    def test_args_missing(self):
        with captured(out(), err()) as (stdout, stderr):
            with mock_args([]):
                with self.assertRaises(SystemExit):
                    RequiredArgCommand.main()

        # Py2 and Py3 argparse have different messages
        self.assertIn('error: ', stderr.getvalue())
        self.assertIn('-r/--req', stderr.getvalue())
        self.assertIn('required', stderr.getvalue())
Ejemplo n.º 6
0
def run_command(additional_args):
    httpretty_register()

    args = ['-d', 'DOMAIN', '-n', 'NAME', '-v', 'VERSION', '-i', 'ID']
    args += additional_args
    with captured(out(), err()) as (stdout, stderr):
        with mock_args(args):
            Command.main()

    return stdout, stderr
Ejemplo n.º 7
0
    def test_args_logging_config(self):
        with InTempDir():
            with open('logging.conf', 'w') as fd:
                fd.write(LOGGING_CONFIG_FILE_DATA)

            args = ['--logging-config', 'logging.conf']
            with captured(out(), err()) as (stdout, stderr):
                with mock_args(args):
                    TestCommand.main()

        self.assertIn('EndOfOutput', stdout.getvalue())
Ejemplo n.º 8
0
    def test_nominal(self):
        args = ["--name", "DOMAIN", "--retention-days", "10"]

        headers = {"x-amzn-RequestId": "d68969c7-3f0d-11e1-9b11-7182192d0b57"}
        httpretty.register_uri(
            httpretty.POST,
            "https://swf.us-east-1.amazonaws.com/",
            content_type="application/json",
            adding_headers=headers,
            body="",
        )

        with captured(out(), err()) as (stdout, stderr):
            with mock_args(args):
                Command.main()

        request = httpretty.last_request()
        self.assertEqual(request.headers.get("x-amz-target"), "SimpleWorkflowService.RegisterDomain")
        expected = {"name": "DOMAIN", "workflowExecutionRetentionPeriodInDays": "10"}
        self.assertEqual(json.loads(request.parsed_body), expected)

        self.assertIn("Success.", stdout.getvalue())
Ejemplo n.º 9
0
    def test_register_workflows(self, m_get_conn, m_register, m_worker_cls):
        m_worker = m_worker_cls.return_value
        m_worker.run.side_effect = KeyboardInterrupt('KILLTEST')

        m_conn = m_get_conn.return_value

        args = [
            '-d', 'DOMAIN', '-m', 'caravan.tests.fixtures', '-t', 'TASKLIST',
            '--register-workflows',
            ]

        with mock_args(args):
            with self.assertRaises(SystemExit):
                Command.main()

        expected = [
            mock.call(connection=m_conn,
                      domain='DOMAIN',
                      workflow=fixtures.TestWorkflow1),
            mock.call(connection=m_conn,
                      domain='DOMAIN',
                      workflow=fixtures.TestWorkflow2),
            ]
        self.assertEqual(m_register.call_args_list, expected)
Ejemplo n.º 10
0
 def test_keyboard_interrupt(self):
     with captured(out(), err()) as (stdout, stderr):
         with mock_args([]):
             with self.assertRaises(SystemExit) as exc:
                 KeyboardInterruptCommand.main()
     self.assertEqual(str(exc.exception), '1')
Ejemplo n.º 11
0
 def test_args_help(self):
     with captured(out(), err()) as (stdout, stderr):
         with mock_args(['--help']):
             with self.assertRaises(SystemExit):
                 TestCommand.main()
     self.assertIn(TestCommand.description, stdout.getvalue())