def test_redis_data_info_without_arguments(capfd): set_module_args({}) with pytest.raises(SystemExit): redis_data_info.main() out, err = capfd.readouterr() assert not err assert json.loads(out)['failed']
def test_redis_data_info_absent_key_no_username(capfd, mocker): set_module_args({ 'login_host': 'localhost', 'login_password': '******', 'key': 'foo', '_ansible_check_mode': False }) mocker.patch('redis.Redis.get', return_value=None) with pytest.raises(SystemExit): redis_data_info.main() out, err = capfd.readouterr() print(out) assert not err assert not json.loads(out)['exists'] assert 'value' not in json.loads(out)
def test_redis_data_fail_username(capfd, mocker): set_module_args({ 'login_host': 'localhost', 'login_user': '******', 'login_password': '******', 'key': 'foo', '_ansible_check_mode': False }) with pytest.raises(SystemExit): redis_data_info.main() out, err = capfd.readouterr() print(out) assert not err assert json.loads(out)['failed'] assert json.loads( out )['msg'] == 'The option `username` in only supported with redis >= 3.4.0.'