How to use spectacles - 10 common examples

To help you get started, we’ve selected a few spectacles examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spectacles-ci / spectacles / tests / test_utils.py View on Github external
def test_compose_url_one_path_component():
    url = utils.compose_url(TEST_BASE_URL, ["api"])
    assert url == "https://test.looker.com/api"
github spectacles-ci / spectacles / tests / test_utils.py View on Github external
def test_compose_url_with_extra_slashes():
    url = utils.compose_url(TEST_BASE_URL + "/", ["/api//", "3.0/login/"])
    assert url == "https://test.looker.com/api/3.0/login"
github spectacles-ci / spectacles / tests / test_client.py View on Github external
def test_bad_requests_should_raise_looker_api_errors(
    mock_request, method_name, looker_client, client_kwargs, mock_404_response
):
    """Tests each method of LookerClient for how it handles a 404 response"""
    mock_request.return_value = mock_404_response
    client_method = getattr(looker_client, method_name)
    with pytest.raises(LookerApiError):
        client_method(**client_kwargs[method_name])
github spectacles-ci / spectacles / tests / test_utils.py View on Github external
def test_log_SQL(self):
        with self.assertLogs(logger=logger, level="INFO") as cm:
            func = MagicMock()
            func.__name__ = "run_sql"
            decorated_func = utils.log_duration(func)
            decorated_func()
        self.assertIn("INFO:spectacles:Completed SQL validation in", cm.output[0])
github spectacles-ci / spectacles / tests / test_select.py View on Github external
def test_invalid_format_should_raise_value_error():
    with pytest.raises(SpectaclesException):
        selector_to_pattern("model_a.explore_a")

    with pytest.raises(SpectaclesException):
        selector_to_pattern("model_a/")

    with pytest.raises(SpectaclesException):
        selector_to_pattern("explore_a")
github spectacles-ci / spectacles / tests / test_data_test_validator.py View on Github external
def test_no_data_tests_should_raise_error(validator):
    with pytest.raises(SpectaclesException):
        validator.build_project(exclusions=["*/*"])
        validator.validate()
github spectacles-ci / spectacles / tests / test_sql_validator.py View on Github external
validator._running_queries = [
        Query(
            query_id="12345",
            lookml_ref=None,
            query_task_id="abc",
            explore_url="https://example.looker.com/x/12345",
        )
    ]
    mock_create_queries = create_autospec(validator._create_queries)
    mock_create_queries.side_effect = KeyboardInterrupt()
    validator._create_queries = mock_create_queries
    mock_cancel_queries = create_autospec(validator._cancel_queries)
    validator._cancel_queries = mock_cancel_queries
    try:
        validator._create_and_run(mode="batch")
    except SpectaclesException:
        mock_cancel_queries.assert_called_once_with(query_task_ids=["abc"])
github spectacles-ci / spectacles / tests / test_cli.py View on Github external
def raise_exception():
        if exception == SpectaclesException:
            raise exception(
                name="exception-name",
                title="An exception occurred.",
                detail="Couldn't handle the truth. Please try again.",
            )
        elif exception == GenericValidationError:
            raise GenericValidationError
        else:
            raise exception(f"This is a {exception.__class__.__name__}.")
github spectacles-ci / spectacles / tests / test_cli.py View on Github external
def test_parse_args_with_incomplete_env_vars(limited_env, capsys):
    parser = create_parser()
    with pytest.raises(SystemExit):
        parser.parse_args(["connect"])
    captured = capsys.readouterr()
    assert "the following arguments are required: --client-secret" in captured.err
github spectacles-ci / spectacles / tests / test_cli.py View on Github external
def test_parse_args_with_only_config_file(mock_parse_config, clean_env):
    parser = create_parser()
    mock_parse_config.return_value = {
        "base_url": "BASE_URL_CONFIG",
        "client_id": "CLIENT_ID_CONFIG",
        "client_secret": "CLIENT_SECRET_CONFIG",
    }
    args = parser.parse_args(["connect", "--config-file", "config.yml"])
    assert args.base_url == "BASE_URL_CONFIG"
    assert args.client_id == "CLIENT_ID_CONFIG"
    assert args.client_secret == "CLIENT_SECRET_CONFIG"