Skip to content

Commit

Permalink
error handling on contributions
Browse files Browse the repository at this point in the history
  • Loading branch information
mccalluc committed Nov 25, 2024
1 parent 20f6012 commit 2f40315
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dp_wizard/app/dataset_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def dataset_ui():
cli_info.contributions,
min=1,
),
ui.output_text("contributions_error"),
ui.output_ui("python_tooltip_ui"),
output_code_sample("Unit of Privacy", "unit_of_privacy_python"),
ui.output_ui("define_analysis_button_ui"),
Expand Down Expand Up @@ -58,7 +59,7 @@ def _on_contributions_change():

@reactive.calc
def button_enabled():
contributions_is_set = input.contributions() is not None
contributions_is_set = int(input.contributions() or 0) >= 1
csv_path_is_set = (
input.csv_path() is not None and len(input.csv_path()) > 0
) or is_demo
Expand All @@ -80,6 +81,11 @@ def contributions_demo_tooltip_ui():
f"can occur at most {contributions()} times in the dataset. ",
)

@render.text
def contributions_error():
if not int(input.contributions() or 0) >= 1:
raise Exception("Contributions must be at least 1.")

@render.ui
def python_tooltip_ui():
return demo_tooltip(
Expand Down
14 changes: 14 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,26 @@ def expect_no_error():
# Button disabled until upload:
define_analysis_button = page.get_by_role("button", name="Define analysis")
assert define_analysis_button.is_disabled()
button_error = "Choose CSV and Contributions before proceeding"
expect_visible(button_error)

# Now upload:
csv_path = Path(__file__).parent / "fixtures" / "fake.csv"
page.get_by_label("Choose CSV file").set_input_files(csv_path.resolve())
expect_no_error()

# Contributions error checks:
contributions_error = "Contributions must be at least 1"
page.get_by_label("Contributions").fill("")
expect_visible(contributions_error)
expect_visible(button_error)
page.get_by_label("Contributions").fill("0")
expect_visible(contributions_error)
expect_visible(button_error)
page.get_by_label("Contributions").fill("42")
expect_not_visible(contributions_error)
expect_not_visible(button_error)

# -- Define analysis --
define_analysis_button.click()
expect_not_visible(pick_dataset_text)
Expand Down

0 comments on commit 2f40315

Please sign in to comment.