Skip to content

Commit

Permalink
Strengthen end-to-end test (#19)
Browse files Browse the repository at this point in the history
* test clicking through tabs

* rm unused imports

* assert that download works

* add link to issue

* Update button name to match
  • Loading branch information
mccalluc authored Oct 2, 2024
1 parent dc3eb10 commit 9816989
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dp_creator_ii/app/analysis_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def analysis_ui():
return ui.nav_panel(
"Perform Analysis",
"Define Analysis",
"TODO: Define analysis",
ui.input_action_button("go_to_results", "Download results"),
value="analysis_panel",
Expand Down
25 changes: 16 additions & 9 deletions dp_creator_ii/app/dataset_panel.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
from pathlib import Path
import json
from sys import argv

from shiny import ui, reactive, render

from dp_creator_ii import get_arg_parser


def dataset_ui():
return ui.nav_panel(
"Select Dataset",
"TODO: Pick dataset",
ui.output_text("csv_path_text"),
ui.output_text("unit_of_privacy_text"),
ui.input_action_button("go_to_analysis", "Perform analysis"),
ui.input_action_button("go_to_analysis", "Define analysis"),
value="dataset_panel",
)


def dataset_server(input, output, session):
config_path = Path(__file__).parent / "config.json"
config = json.loads(config_path.read_text())
config_path.unlink()

csv_path = reactive.value(config["csv_path"])
unit_of_privacy = reactive.value(config["unit_of_privacy"])
if argv[1:3] == ["run", "--port"]:
# Started by playwright
arg_csv_path = None
arg_unit_of_privacy = None
else:
args = get_arg_parser().parse_args()
arg_csv_path = args.csv_path
arg_unit_of_privacy = args.unit_of_privacy

csv_path = reactive.value(arg_csv_path)
unit_of_privacy = reactive.value(arg_unit_of_privacy)

@render.text
def csv_path_text():
Expand Down
4 changes: 2 additions & 2 deletions dp_creator_ii/app/results_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

def results_ui():
return ui.nav_panel(
"Download Results",
"TODO: Download Results",
"Download results",
"TODO: Download results",
ui.download_button("download_script", "Download script"),
# TODO: Notebook code is badly formatted
# ui.download_button(
Expand Down
31 changes: 30 additions & 1 deletion dp_creator_ii/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,36 @@


# TODO: Why is incomplete coverage reported here?
# https://github.com/opendp/dp-creator-ii/issues/18
def test_app(page: Page, app: ShinyAppProc): # pragma: no cover
pick_dataset_text = "TODO: Pick dataset"
perform_analysis_text = "TODO: Define analysis"
download_results_text = "TODO: Download results"

def expect_visible(text):
expect(page.get_by_text(text)).to_be_visible()

def expect_not_visible(text):
expect(page.get_by_text(text)).not_to_be_visible()

page.goto(app.url)
expect(page).to_have_title("DP Creator II")
expect(page.locator("body")).to_contain_text("TODO: Pick dataset")
expect_visible(pick_dataset_text)
expect_not_visible(perform_analysis_text)
expect_not_visible(download_results_text)

page.get_by_role("button", name="Define analysis").click()
expect_not_visible(pick_dataset_text)
expect_visible(perform_analysis_text)
expect_not_visible(download_results_text)

page.get_by_role("button", name="Download results").click()
expect_not_visible(pick_dataset_text)
expect_not_visible(perform_analysis_text)
expect_visible(download_results_text)

with page.expect_download() as download_info:
page.get_by_text("Download script").click()
download = download_info.value
script = download.path().read_text()
assert "privacy_unit=dp.unit_of(contributions=1)" in script

0 comments on commit 9816989

Please sign in to comment.