Skip to content

Commit

Permalink
test(wizard): exercise the permission question
Browse files Browse the repository at this point in the history
  • Loading branch information
joanise committed Jun 12, 2024
1 parent 0f2012b commit 7e1ab2c
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions everyvoice/tests/test_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ def monkey(self):
return self.answer_or_monkey


def find_step(name: Enum, steps: Sequence[Step | list[Step]]):
"""Find a step with the given name in steps, of potentially variable depth"""
for s in steps:
if isinstance(s, list):
try:
return find_step(name, s)
except IndexError:
pass
elif s.name == name.value:
return s
raise IndexError(f"Step {name} not found.") # pragma: no cover


class WizardTest(TestCase):
"""Basic test for the configuration wizard"""

Expand Down Expand Up @@ -218,6 +231,26 @@ def test_bad_contact_email_step(self):
self.assertIn("There must be something after the @-sign", output)
self.assertIn("An email address cannot end with a period", output)

def test_no_permissions(self):
"""Exercise lacking permissions, then trying again"""
tour = get_main_wizard_tour()
permission_step = find_step(SN.dataset_permission_step, tour.steps)
self.assertGreater(len(permission_step.children), 8)
self.assertGreater(len(tour.root.descendants), 14)
self.assertIn("dataset_0", tour.state)
with patch_menu_prompt(0): # 0 is no, I don't have permission
permission_step.run()
self.assertEqual(permission_step.children, ())
self.assertLess(len(tour.root.descendants), 10)
self.assertNotIn("dataset_0", tour.state)

more_dataset_step = find_step(SN.more_datasets_step, tour.steps)
with patch_menu_prompt(1): # 1 is Yes, I have more data
more_dataset_step.run()
self.assertIn("dataset_1", tour.state)
self.assertGreater(len(more_dataset_step.descendants), 8)
self.assertGreater(len(tour.root.descendants), 14)

def test_output_path_step(self):
"""Exercise the OutputPathStep"""
tour = Tour(
Expand Down Expand Up @@ -333,17 +366,6 @@ def test_sample_rate_config(self):
self.assertEqual(step.response, 512)

def test_dataset_subtour(self):
def find_step(name: Enum, steps: Sequence[Step | list[Step]]):
for s in steps:
if isinstance(s, list):
try:
return find_step(name, s)
except IndexError:
pass
elif s.name == name.value:
return s
raise IndexError(f"Step {name} not found.") # pragma: no cover

tour = Tour("unit testing", steps=dataset.get_dataset_steps())

wavs_dir_step = find_step(SN.wavs_dir_step, tour.steps)
Expand All @@ -355,6 +377,14 @@ def find_step(name: Enum, steps: Sequence[Step | list[Step]]):
monkey = monkeypatch(filelist_step, "prompt", Say(filelist))
with monkey:
filelist_step.run()

permission_step = find_step(SN.dataset_permission_step, tour.steps)
with patch_menu_prompt(1): # 1 is "yes, I have permission"
permission_step.run()
self.assertTrue(
permission_step.state[SN.dataset_permission_step].startswith("Yes")
)

format_step = find_step(SN.filelist_format_step, tour.steps)
with patch_menu_prompt(0): # 0 is "psv"
format_step.run()
Expand Down

0 comments on commit 7e1ab2c

Please sign in to comment.