Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 37975b9

Browse files
committed
✅ Adding unittest for horizontal parsons problems
1 parent d192101 commit 37975b9

File tree

3 files changed

+92
-220
lines changed

3 files changed

+92
-220
lines changed

runestone/hparsons/test/_sources/database_hparsons.rst

Lines changed: 0 additions & 197 deletions
This file was deleted.
Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,49 @@
1-
=========================
2-
Horizontal Parsons Test
3-
=========================
1+
==========================================
2+
Test: Horizontal Parsons Problems with SQL
3+
==========================================
44

5-
.. Testing horizontal Parsons problems.
65

7-
Horizontal Parsons + SQL
6+
Examples
7+
========
8+
Randomized Block
89
--------------------------------------
9-
.. hparsons:: test_activecode_6
10+
.. hparsons:: test_hparsons_sql_1
1011
:language: sql
1112
:dburl: /_static/test.db
1213
:randomize:
1314

14-
1515
This is a horizontal Parsons problem! Feedback is based on code execution.
1616
The blocks are randomized, but cannot be reused ;)
1717
~~~~
1818
--blocks--
19-
select
19+
SELECT
2020
*
21-
from
21+
FROM
2222
test
2323
--unittest--
2424
assert 1,1 == world
2525
assert 0,1 == hello
2626
assert 2,1 == 42
2727

28-
.. :dburl: http://localhost:8000/_static/test.db
29-
3028

31-
.. hparsons:: teasfasfas
29+
Reusable Block
30+
--------------------------------------
31+
.. hparsons:: test_hparsons_sql_2
3232
:language: sql
3333
:dburl: /_static/test.db
3434
:reuse:
3535

36-
3736
This is a horizontal parsons problem! Feedback is base on code execution.
3837
The blocks are set as the original order, and can be used multiple times.
3938
To delete a block, simply drag out of the input area.
4039
These features might not be so useful in the context of SQL, but might be useful in regex.
4140
~~~~
4241
--blocks--
43-
select
42+
SELECT
4443
*
45-
from
44+
FROM
4645
test
4746
--unittest--
4847
assert 1,1 == world
4948
assert 0,1 == hello
5049
assert 2,1 == 42
51-
52-
.. :dburl: http://localhost:8000/_static/test.db
53-
54-
55-
.. toctree::
56-
:maxdepth: 3
57-
58-
database_hparsons.rst
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""
2+
Test horizontal Parsons problems directive
3+
"""
4+
5+
__author__ = "zihan wu"
6+
7+
import time
8+
from selenium.webdriver import ActionChains
9+
from selenium.webdriver.common.by import By
10+
11+
def find_hp_question(selenium_utils, div_id):
12+
selenium_utils.wait_until_ready(div_id)
13+
return selenium_utils.driver.find_element(By.ID, div_id)
14+
15+
16+
'''
17+
Test if the blocks are properly randomized.
18+
1. Assert the sequence of the blocks is not the same as set in .rst file.
19+
'''
20+
def test_randomize_block(selenium_utils_get):
21+
div_id = "test_hparsons_sql_1"
22+
hp = find_hp_question(selenium_utils_get, div_id).find_element(By.CSS_SELECTOR, 'horizontal-parsons')
23+
original_sequence = ['SELECT','*','FROM','test']
24+
randomized_sequence = []
25+
for block in hp.shadow_root.find_element(By.CSS_SELECTOR,'.drag-area').find_elements(By.CSS_SELECTOR, '.parsons-block'):
26+
randomized_sequence.append(block.text)
27+
assert len(original_sequence) == len(randomized_sequence)
28+
is_same_order = True
29+
for i in range(len(original_sequence)):
30+
if original_sequence[i] != randomized_sequence[i]:
31+
is_same_order = False
32+
break
33+
assert not is_same_order
34+
35+
36+
# # Test adding and removing blocks by clicking in non-duplicating blocks
37+
# """
38+
# 1. Click on the first block and make sure it is moved to the bottom
39+
# 2. Click on the first block in the bottom and make sure it is put back
40+
# """
41+
# def test_add_and_remove_blocks(selenium_utils_get):
42+
# div_id = "test_hparsons_sql_1"
43+
# hp = find_hp_question(selenium_utils_get, div_id).find_element(By.CSS_SELECTOR, 'horizontal-parsons')
44+
# drag_area = hp.shadow_root.find_element(By.CSS_SELECTOR, '.drag-area')
45+
# drop_area = hp.shadow_root.find_element(By.CSS_SELECTOR, '.drop-area')
46+
47+
# # 1. Click on the first block and make sure it is added to the bottom
48+
# block1 = drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[0]
49+
# block1.click()
50+
# assert block1 not in drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')
51+
# assert block1 == drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[-1]
52+
53+
54+
# # 2. Drag the remaining first block and make sure it is added to the bottom
55+
# drag = [x.text for x in drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')]
56+
# print(drag)
57+
# block2 = drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[0]
58+
# # ActionChains(selenium_utils_get.driver).drag_and_drop(
59+
# # block2, drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[-1]
60+
# # ).perform()
61+
# ActionChains(selenium_utils_get.driver).drag_and_drop(
62+
# block2, drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[-1]
63+
# ).perform()
64+
# time.sleep(2)
65+
66+
# drag = [x.text for x in drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')]
67+
# print(drag)
68+
69+
# # assert block2 not in drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')
70+
# # assert block2 == drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[-1]
71+
# assert block2 in drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')
72+
73+
# # 2. Click on the moved block and make sure it is returned to the top
74+
# # block2 and block1 are the same object
75+
# block2 = drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[0]
76+
# block2.click()
77+
# assert block2 not in drop_area.find_elements(By.CSS_SELECTOR, '.parsons-block')
78+
# assert block2 == drag_area.find_elements(By.CSS_SELECTOR, '.parsons-block')[-1]

0 commit comments

Comments
 (0)