Skip to content

Commit

Permalink
fix dialog selector, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanbconaway committed Sep 30, 2024
1 parent 27a1379 commit ea7214d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,22 @@ def fluff_results():
# dialect must be a dialect label for `load_raw_dialect`. VALID_DIALECTS is a
# dictionary of dialect labels to dialect names. If we have a name, we need to
# get the label.
#
# However, the frontend logic runs on dialect names, so we need to convert the
# label back to a name for the frontend.
dialect = request.args["dialect"]
if dialect in VALID_DIALECTS.values():
dialect = next(
dialect_name = dialect
dialect_label = next(
label for label, name in VALID_DIALECTS.items() if name == dialect
)
else:
dialect_label = dialect
dialect_name = VALID_DIALECTS[dialect]

try:
linted = lint(sql, dialect=dialect)
fixed_sql = fix(sql, dialect=dialect)
linted = lint(sql, dialect=dialect_label)
fixed_sql = fix(sql, dialect=dialect_label)
except RuntimeError as e:
linted = [
{
Expand All @@ -70,7 +77,7 @@ def fluff_results():
"index.html",
results=True,
sql=sql,
dialect=dialect,
dialect=dialect_name,
lint_errors=linted,
fixed_sql=fixed_sql,
)
10 changes: 9 additions & 1 deletion test/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_post_redirect(client):
@pytest.mark.parametrize("dialect", ["sparksql", "Apache Spark SQL"])
def test_results_no_errors(client, dialect):
"""Test that the results is good to go when there is no error.
Parameterized dialect asserts that either the formatted name or label can be used
as the dialect parameter.
"""
Expand All @@ -50,6 +50,14 @@ def test_results_no_errors(client, dialect):
assert "fixed sql" in html
assert "select * from table" in html

# Test that the dialect is correctly selected in the results page.
selected_dialect = (
BeautifulSoup(html, "html.parser")
.find("select", {"id": "sql_dialect"})
.find("option", {"selected": "selected"})
)
assert selected_dialect.text.strip() == "apache spark sql"


def test_results_some_errors(client):
"""Test that the results is good to go with one obvious error."""
Expand Down

0 comments on commit ea7214d

Please sign in to comment.