Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate contributions #214

Merged
merged 6 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions dp_wizard/app/dataset_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ def dataset_ui():
"How many rows of the CSV can one individual contribute to? "
'This is the "unit of privacy" which will be protected.'
),
ui.input_numeric(
"contributions",
["Contributions", ui.output_ui("contributions_demo_tooltip_ui")],
cli_info.contributions,
min=1,
ui.row(
ui.input_numeric(
"contributions",
["Contributions", ui.output_ui("contributions_demo_tooltip_ui")],
cli_info.contributions,
min=1,
),
ui.output_ui("contributions_validation_ui"),
),
ui.output_ui("python_tooltip_ui"),
output_code_sample("Unit of Privacy", "unit_of_privacy_python"),
Expand Down Expand Up @@ -163,6 +166,18 @@ def contributions_demo_tooltip_ui():
f"can occur at most {contributions()} times in the dataset. ",
)

@reactive.calc
def contributions_valid():
contributions = input.contributions()
return isinstance(contributions, int) and contributions >= 1

@render.ui
def contributions_validation_ui():
return hide_if(
contributions_valid(),
info_box(ui.markdown("Contributions must be 1 or greater.")),
)

@render.ui
def python_tooltip_ui():
return demo_tooltip(
Expand All @@ -178,7 +193,7 @@ def define_analysis_button_ui():
button = ui.input_action_button(
"go_to_analysis", "Define analysis", disabled=not button_enabled()
)
if button_enabled():
if button_enabled() and contributions_valid():
return button
return [
button,
Expand Down
13 changes: 13 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ def expect_no_error():
# Now upload:
csv_path = Path(__file__).parent / "fixtures" / "fake.csv"
page.get_by_label("Choose Public CSV").set_input_files(csv_path.resolve())

# Check validation of contributions:
# Playwright itself won't let us fill non-numbers in this field.
# "assert define_analysis_button.is_enabled()" has spurious errors.
mccalluc marked this conversation as resolved.
Show resolved Hide resolved
# https://github.com/opendp/dp-wizard/issues/221
page.get_by_label("Contributions").fill("0")
expect_visible("Contributions must be 1 or greater")
expect_visible("Choose CSV and Contributions before proceeding")

page.get_by_label("Contributions").fill("42")
expect_not_visible("Contributions must be 1 or greater")
expect_not_visible("Choose CSV and Contributions before proceeding")

expect_no_error()

# -- Define analysis --
Expand Down
Loading