Changeset View
Changeset View
Standalone View
Standalone View
swh/core/tests/test_cli.py
Show First 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | with patch('sentry_sdk.init') as sentry_sdk_init: | ||||
result = runner.invoke(swhmain, ['--sentry-dsn', 'test_dsn', 'test']) | result = runner.invoke(swhmain, ['--sentry-dsn', 'test_dsn', 'test']) | ||||
assert result.exit_code == 0 | assert result.exit_code == 0 | ||||
assert result.output.strip() == '''Hello SWH!''' | assert result.output.strip() == '''Hello SWH!''' | ||||
sentry_sdk_init.assert_called_once_with( | sentry_sdk_init.assert_called_once_with( | ||||
dsn='test_dsn', | dsn='test_dsn', | ||||
debug=False, | debug=False, | ||||
integrations=[], | integrations=[], | ||||
release=None, | release=None, | ||||
environment=None, | |||||
) | ) | ||||
def test_sentry_debug(swhmain): | def test_sentry_debug(swhmain): | ||||
@swhmain.command(name='test') | @swhmain.command(name='test') | ||||
@click.pass_context | @click.pass_context | ||||
def swhtest(ctx): | def swhtest(ctx): | ||||
click.echo('Hello SWH!') | click.echo('Hello SWH!') | ||||
runner = CliRunner() | runner = CliRunner() | ||||
with patch('sentry_sdk.init') as sentry_sdk_init: | with patch('sentry_sdk.init') as sentry_sdk_init: | ||||
result = runner.invoke( | result = runner.invoke( | ||||
swhmain, ['--sentry-dsn', 'test_dsn', '--sentry-debug', 'test']) | swhmain, ['--sentry-dsn', 'test_dsn', '--sentry-debug', 'test']) | ||||
assert result.exit_code == 0 | assert result.exit_code == 0 | ||||
assert result.output.strip() == '''Hello SWH!''' | assert result.output.strip() == '''Hello SWH!''' | ||||
sentry_sdk_init.assert_called_once_with( | sentry_sdk_init.assert_called_once_with( | ||||
dsn='test_dsn', | dsn='test_dsn', | ||||
debug=True, | debug=True, | ||||
integrations=[], | integrations=[], | ||||
release=None, | release=None, | ||||
environment=None, | |||||
) | ) | ||||
def test_sentry_env(swhmain): | def test_sentry_env(swhmain): | ||||
@swhmain.command(name='test') | @swhmain.command(name='test') | ||||
@click.pass_context | @click.pass_context | ||||
def swhtest(ctx): | def swhtest(ctx): | ||||
click.echo('Hello SWH!') | click.echo('Hello SWH!') | ||||
runner = CliRunner() | runner = CliRunner() | ||||
with patch('sentry_sdk.init') as sentry_sdk_init: | with patch('sentry_sdk.init') as sentry_sdk_init: | ||||
env = { | env = { | ||||
'SWH_SENTRY_DSN': 'test_dsn', | 'SWH_SENTRY_DSN': 'test_dsn', | ||||
'SWH_SENTRY_DEBUG': '1', | 'SWH_SENTRY_DEBUG': '1', | ||||
} | } | ||||
result = runner.invoke( | result = runner.invoke( | ||||
swhmain, ['test'], env=env, auto_envvar_prefix='SWH') | swhmain, ['test'], env=env, auto_envvar_prefix='SWH') | ||||
assert result.exit_code == 0 | assert result.exit_code == 0 | ||||
assert result.output.strip() == '''Hello SWH!''' | assert result.output.strip() == '''Hello SWH!''' | ||||
sentry_sdk_init.assert_called_once_with( | sentry_sdk_init.assert_called_once_with( | ||||
dsn='test_dsn', | dsn='test_dsn', | ||||
debug=True, | debug=True, | ||||
integrations=[], | integrations=[], | ||||
release=None, | release=None, | ||||
environment=None, | |||||
) | ) | ||||
def test_sentry_env_main_package(swhmain): | def test_sentry_env_main_package(swhmain): | ||||
@swhmain.command(name='test') | @swhmain.command(name='test') | ||||
@click.pass_context | @click.pass_context | ||||
def swhtest(ctx): | def swhtest(ctx): | ||||
click.echo('Hello SWH!') | click.echo('Hello SWH!') | ||||
runner = CliRunner() | runner = CliRunner() | ||||
with patch('sentry_sdk.init') as sentry_sdk_init: | with patch('sentry_sdk.init') as sentry_sdk_init: | ||||
env = { | env = { | ||||
'SWH_SENTRY_DSN': 'test_dsn', | 'SWH_SENTRY_DSN': 'test_dsn', | ||||
'SWH_MAIN_PACKAGE': 'swh.core', | 'SWH_MAIN_PACKAGE': 'swh.core', | ||||
'SWH_SENTRY_ENVIRONMENT': 'tests', | |||||
} | } | ||||
result = runner.invoke( | result = runner.invoke( | ||||
swhmain, ['test'], env=env, auto_envvar_prefix='SWH') | swhmain, ['test'], env=env, auto_envvar_prefix='SWH') | ||||
assert result.exit_code == 0 | assert result.exit_code == 0 | ||||
version = pkg_resources.get_distribution('swh.core').version | version = pkg_resources.get_distribution('swh.core').version | ||||
assert result.output.strip() == '''Hello SWH!''' | assert result.output.strip() == '''Hello SWH!''' | ||||
sentry_sdk_init.assert_called_once_with( | sentry_sdk_init.assert_called_once_with( | ||||
dsn='test_dsn', | dsn='test_dsn', | ||||
debug=False, | debug=False, | ||||
integrations=[], | integrations=[], | ||||
release='swh.core@' + version, | release='swh.core@' + version, | ||||
environment='tests', | |||||
) | ) | ||||
@pytest.fixture | @pytest.fixture | ||||
def log_config_path(tmp_path): | def log_config_path(tmp_path): | ||||
log_config = textwrap.dedent('''\ | log_config = textwrap.dedent('''\ | ||||
--- | --- | ||||
version: 1 | version: 1 | ||||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |