Skip to content

Commit 7dbbe3f

Browse files
committed
prevent usage of inputs that are keyboard shortcuts
1 parent 2c03ef7 commit 7dbbe3f

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

tests/test_widgets.py

+21-20
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,21 @@ def test_widget_answer(self, selenium_driver):
232232

233233
assert len(text_inputs) == 1
234234
text_input = text_inputs[0]
235-
text_input.send_keys("test-answers")
235+
text_input.send_keys("test-E")
236236
# wait till typing finished
237237
WebDriverWait(driver, 5).until(
238238
expected_conditions.text_to_be_present_in_element_attribute(
239239
(By.CLASS_NAME, TEXT_INPUT_CLASS_NAME),
240240
"value",
241-
"test-answers",
241+
"test-E",
242242
)
243243
)
244244
# wait till everything is sync with python kernel
245245
time.sleep(0.1)
246246
create_file_button.click()
247247

248248
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
249-
assert output.text == "File 'pytest-test-answers.json' created and loaded."
249+
assert output.text == "File 'pytest-test-E.json' created and loaded."
250250

251251
answer_registry_buttons = nb_cell.find_elements(
252252
By.CLASS_NAME, BUTTON_CLASS_NAME
@@ -286,7 +286,7 @@ def test_widget_answer(self, selenium_driver):
286286
)
287287
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
288288
assert (
289-
output.text == "All answers were saved in file 'pytest-test-answers.json'."
289+
output.text == "All answers were saved in file 'pytest-test-E.json'."
290290
)
291291
# cancel
292292
# wait till everything is sync with python kernel
@@ -321,7 +321,7 @@ def test_widget_answer(self, selenium_driver):
321321
expected_conditions.invisibility_of_element_located(output)
322322
)
323323
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
324-
assert output.text == "All answers loaded from file 'pytest-test-answers.json'."
324+
assert output.text == "All answers loaded from file 'pytest-test-E.json'."
325325

326326
# TODO test interaction of ExerciseWidgets with ExerciseRegistry
327327

@@ -346,7 +346,7 @@ def test_widget_answer(self, selenium_driver):
346346
load_button = answer_buttons[1]
347347

348348
# tests save button
349-
input_answer = "answer text"
349+
input_answer = "T"
350350
text_input.send_keys(input_answer)
351351
# wait till everything is sync with python kernel
352352
time.sleep(0.1)
@@ -378,11 +378,12 @@ def test_widget_answer(self, selenium_driver):
378378
assert text_input.get_attribute("value") == input_answer
379379
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
380380
assert (
381-
output.text == "Exercise has been saved in file 'pytest-test-answers.json'."
381+
output.text == "Exercise has been saved in file 'pytest-test-E.json'."
382382
)
383383

384384
# tests load button
385-
text_input.send_keys(" update")
385+
update_keys = " up"
386+
text_input.send_keys(update_keys)
386387
# wait till everything is sync with python kernel
387388
time.sleep(0.1)
388389
# wait for cued box
@@ -394,7 +395,7 @@ def test_widget_answer(self, selenium_driver):
394395
By.CLASS_NAME, reset_cue_button_class_name("save", True)
395396
)
396397
assert len(reset_cue_buttons) == 2
397-
assert text_input.get_attribute("value") == input_answer + " update"
398+
assert text_input.get_attribute("value") == input_answer + update_keys
398399
#
399400
WebDriverWait(driver, 1).until(
400401
expected_conditions.element_to_be_clickable(load_button)
@@ -419,7 +420,7 @@ def test_widget_answer(self, selenium_driver):
419420
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
420421
assert (
421422
output.text
422-
== "Exercise has been loaded from file 'pytest-test-answers.json'."
423+
== "Exercise has been loaded from file 'pytest-test-E.json'."
423424
)
424425
assert text_input.get_attribute("value") == input_answer
425426

@@ -444,7 +445,7 @@ def test_widget_answer(self, selenium_driver):
444445

445446
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
446447
assert (
447-
output.text == "Exercise has been saved in file 'pytest-test-answers.json'."
448+
output.text == "Exercise has been saved in file 'pytest-test-E.json'."
448449
)
449450
# not cued
450451
cue_box = nb_cell.find_element(By.CLASS_NAME, cue_box_class_name("save", False))
@@ -479,7 +480,7 @@ def test_widget_answer(self, selenium_driver):
479480
output = nb_cell.find_element(By.CLASS_NAME, OUTPUT_CLASS_NAME)
480481
assert (
481482
output.text
482-
== "Exercise has been loaded from file 'pytest-test-answers.json'."
483+
== "Exercise has been loaded from file 'pytest-test-E.json'."
483484
)
484485
# not cued
485486
cue_box = nb_cell.find_element(By.CLASS_NAME, cue_box_class_name("save", False))
@@ -671,9 +672,9 @@ def test_cue_box_cued(nb_cell, cue_box_name, cued_on_init):
671672
# some input that changes the widget
672673

673674
# Check if cue is added once text input is changed
674-
text_input.send_keys("a")
675+
text_input.send_keys("E")
675676
time.sleep(0.1)
676-
assert text_input.get_attribute("value") == "Texta"
677+
assert text_input.get_attribute("value") == "TextE"
677678
assert cue_box_class_name(cue_box_name, True).replace(
678679
".", " "
679680
) == cue_box_widget.get_attribute("class")
@@ -725,9 +726,9 @@ def test_reset_cue_button(
725726
) == RESET_CUE_BUTTON_CLASS_NAME.replace(".", " ")
726727

727728
# Check if unused text input does not effect cueing of button
728-
unused_text_input.send_keys("a")
729+
unused_text_input.send_keys("E")
729730
time.sleep(0.1)
730-
assert unused_text_input.get_attribute("value") == "Unuseda"
731+
assert unused_text_input.get_attribute("value") == "UnusedE"
731732
assert (
732733
sum(
733734
[
@@ -758,8 +759,8 @@ def test_reset_cue_button(
758759
assert reset_cue_button.is_enabled()
759760

760761
# Checks if two more widgets are cued on change
761-
text_input.send_keys("a")
762-
assert text_input.get_attribute("value") == "Texta"
762+
text_input.send_keys("E")
763+
assert text_input.get_attribute("value") == "TextE"
763764

764765
WebDriverWait(driver, 1).until(
765766
expected_conditions.element_to_be_clickable(reset_cue_button)
@@ -1121,7 +1122,7 @@ def test_code_exercise(
11211122
# Issue #22
11221123
# sending keys to code widget does not work at the moment
11231124
# once this works please add this code
1124-
# code_input.send_keys("a=5\n")
1125+
# code_input.send_keys("v=9\n")
11251126
# time.sleep(0.1)
11261127
# assert (scwidget_cue_box_class_name("check", True) in
11271128
# check_code_input.get_attribute("class"))
@@ -1138,7 +1139,7 @@ def test_code_exercise(
11381139
slider_input_box = nb_cell.find_element(By.CLASS_NAME, "widget-readout")
11391140
slider_input_box.send_keys(Keys.BACKSPACE)
11401141
slider_input_box.send_keys(Keys.BACKSPACE)
1141-
slider_input_box.send_keys(2)
1142+
slider_input_box.send_keys(9)
11421143
slider_input_box.send_keys(Keys.ENTER)
11431144
time.sleep(0.2)
11441145

0 commit comments

Comments
 (0)