Пример #1
0
def test_help_menu():
    with patch_object(sys, 'argv', ['kq', '--help']):
        with CaptureOutput() as output, pytest.raises(SystemExit):
            cli.entry_point()
        assert len(output) == 1
        assert 'Usage' in output[0]
        assert 'Options' in output[0]
Пример #2
0
def test_worker(worker, logger):
    worker_cls, worker_inst = worker

    test_arguments = [
        'kq',
        'worker',
        '--hosts=host:6000,host:7000',
        '--topic=foo',
        '--timeout=4000',
        '--job-size=3000000',
        '--cafile=/test/files/cafile',
        '--certfile=/test/files/certfile',
        '--keyfile=/test/files/keyfile',
        '--crlfile=/test/files/crlfile',
        '--proc-ttl=1000',
        '--offset=earliest'
    ]
    with patch_object(sys, 'argv', test_arguments):
        cli.entry_point()

    logger.setLevel.assert_called_once_with(logging.WARNING)
    worker_cls.assert_called_once_with(
        hosts='host:6000,host:7000',
        topic='foo',
        timeout=4000,
        callback=None,
        job_size=3000000,
        cafile='/test/files/cafile',
        certfile='/test/files/certfile',
        keyfile='/test/files/keyfile',
        crlfile='/test/files/crlfile',
        proc_ttl=1000,
        offset_policy='earliest'
    )
    worker_inst.start.assert_called_once()
Пример #3
0
def test_callback(worker, logger):
    worker_cls, worker_inst = worker

    test_arguments = [
        'kq',
        'worker',
        '--hosts=host:6000,host:7000',
        '--topic=foo',
        '--timeout=4000',
        '--callback=/invalid/path'
    ]
    with patch_object(sys, 'argv', test_arguments):
        cli.entry_point()

    logger.exception.assert_called_once()
    logger.setLevel.assert_called_once_with(logging.WARNING)
    worker_cls.assert_called_with(
        hosts='host:6000,host:7000',
        topic='foo',
        timeout=4000,
        callback=None,
        job_size=1048576,
        cafile=None,
        certfile=None,
        keyfile=None,
        crlfile=None,
        proc_ttl=5000,
        offset_policy='latest'
    )
    worker_inst.start.assert_called_once()
Пример #4
0
def test_verbose(worker, logger):
    worker_cls, worker_inst = worker

    with patch_object(sys, 'argv', ['kq', 'worker', '--verbose']):
        cli.entry_point()

    logger.setLevel.assert_called_once_with(logging.DEBUG)
    worker_cls.assert_called_with(hosts='127.0.0.1',
                                  topic='default',
                                  timeout=None,
                                  callback=None,
                                  job_size=1048576,
                                  cafile=None,
                                  certfile=None,
                                  keyfile=None,
                                  crlfile=None)
    worker_inst.start.assert_called_once()
Пример #5
0
def test_info(manager, logger):
    manager_cls, manager_inst = manager

    test_arguments = [
        'kq', 'info', '--hosts=host:6000,host:7000',
        '--cafile=/test/files/cafile', '--certfile=/test/files/certfile',
        '--keyfile=/test/files/keyfile', '--crlfile=/test/files/crlfile'
    ]
    with patch_object(sys, 'argv', test_arguments):
        cli.entry_point()

    logger.setLevel.assert_called_once_with(logging.WARNING)
    manager_cls.assert_called_once_with(hosts='host:6000,host:7000',
                                        cafile='/test/files/cafile',
                                        certfile='/test/files/certfile',
                                        keyfile='/test/files/keyfile',
                                        crlfile='/test/files/crlfile')
    manager_inst.info.assert_called_once()
Пример #6
0
def test_version():
    with patch_object(sys, 'argv', ['kq', '--version']):
        with CaptureOutput() as output, pytest.raises(SystemExit):
            cli.entry_point()
        assert len(output) == 1
        assert output[0] == VERSION + '\n'