Skip to content

Commit

Permalink
Write a test
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-finley committed May 15, 2024
1 parent 42e91a0 commit 01566a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def fluff_results():
try:
linted = lint(sql, dialect=dialect)
fixed_sql = fix(sql, dialect=dialect)
except RuntimeError as e: # pragma: no cover
except RuntimeError as e:
linted = [
{
"start_line_no": 1,
Expand Down
15 changes: 15 additions & 0 deletions test/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from app.routes import sql_encode
from bs4 import BeautifulSoup
from unittest.mock import patch


@pytest.fixture
Expand Down Expand Up @@ -95,6 +96,20 @@ def test_newlines_in_error(client):
)


@patch("app.routes.lint")
def test_runtime_error(mock_lint, client):
"""Test that a runtime error is handled."""
mock_lint.side_effect = RuntimeError("This is a test error")
sql_encoded = sql_encode("select * from table")
rv = client.get("/fluffed", query_string=f"""dialect=ansi&sql={sql_encoded}""")
html = rv.data.decode().lower()
assert "sqlfluff online" in html
assert "fixed sql" in html
assert "select * from table" in html
assert "runtimeerror" in html
assert "this is a test error" in html


def test_security_headers(client):
"""Test flask-talisman is setting the security headers"""
rv = client.get("/")
Expand Down

0 comments on commit 01566a1

Please sign in to comment.