Skip to content

Commit

Permalink
Final fixes for URLs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Aug 23, 2024
1 parent 598e9e9 commit 9da6723
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 21 deletions.
6 changes: 2 additions & 4 deletions game/end_to_end_tests/base_game_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ def complete_and_check_level(
return page
if next_episode is None:
page.next_level(from_python_den)
page.assert_level_number(level_number + 1)
page.assert_level_number(level_number + 1, from_python_den)
else:
page.next_episode()
page.assert_episode_number(next_episode)
page.assert_episode_number(next_episode, from_python_den)
return page

def go_to_reverse(self, url_reverse):
Expand All @@ -96,8 +96,6 @@ def go_to_level(self, level_name, from_python_den=False):
else "play_default_level"
)

print(viewname)

path = reverse(viewname, kwargs={"level_name": str(level_name)})
self._go_to_path(path)

Expand Down
26 changes: 18 additions & 8 deletions game/end_to_end_tests/game_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def save_solution(self, workspace_name):

def load_solution_by_name(self, solution_name):
self.browser.find_element(By.ID, "load_tab").click()
time.sleep(1)
self.browser.find_element(By.ID, solution_name).click()
self.browser.find_element(By.ID, "loadWorkspace").click()
time.sleep(1)
Expand Down Expand Up @@ -99,18 +100,24 @@ def clear_console_button(self):
self.browser.find_element(By.ID, "clear_console").click()
return self

def assert_level_number(self, level_number):
path = reverse(
"play_default_level", kwargs={"level_name": str(level_number)}
def assert_level_number(self, level_number, from_python_den):
viewname = (
"play_python_default_level"
if from_python_den
else "play_default_level"
)

path = reverse(viewname, kwargs={"level_name": str(level_number)})
assert_that(
self.browser.current_url.replace("#myModal", ""), ends_with(path)
)

def assert_episode_number(self, episode_number):
path = reverse(
"start_episode", kwargs={"episodeId": str(episode_number)}
def assert_episode_number(self, episode_number, from_python_den):
viewname = (
"start_python_episode" if from_python_den else "start_episode"
)

path = reverse(viewname, kwargs={"episodeId": str(episode_number)})
assert_that(
self.browser.current_url.replace("#myModal", ""), ends_with(path)
)
Expand Down Expand Up @@ -239,11 +246,14 @@ def write_to_then_clear_console(self):
assert_that(console.text == "")
return self

def next_episode(self):
def next_episode(self, from_python_den=False):
self.assert_success()
self.browser.find_element(By.ID, "next_episode_button").click()

tabId = "python_tab" if from_python_den else "blockly_tab"

WebDriverWait(self.browser, 10).until(
presence_of_all_elements_located((By.ID, "blockly_tab"))
presence_of_all_elements_located((By.ID, tabId))
)
return self

Expand Down
22 changes: 15 additions & 7 deletions game/end_to_end_tests/test_play_through.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ class TestPlayThrough(BaseGameTest):
def setUp(self):
self.login_once()

def _complete_episode(self, episode_number, level_number, **kwargs):
def _complete_episode(
self, episode_number, level_number, from_python_den=False, **kwargs
):
page = self.go_to_episode(episode_number)
self.complete_and_check_level(level_number, page, **kwargs)
self.complete_and_check_level(
level_number, page, from_python_den, **kwargs
)

def _complete_level(self, level_number, from_python_den=False, **kwargs):
page = self.go_to_level(level_number, from_python_den)
Expand Down Expand Up @@ -282,7 +286,9 @@ def test_level_079(self):
self._complete_level(79, final_level=True)

def test_episode_12(self):
self._complete_episode(12, 1, check_algorithm_score=False)
self._complete_episode(
12, 1, check_algorithm_score=False, from_python_den=True
)

def test_python_level_001(self):
self._complete_level(1, from_python_den=True)
Expand Down Expand Up @@ -338,7 +344,7 @@ def test_python_level_013(self):
)

def test_episode_14(self):
self._complete_episode(14, 14)
self._complete_episode(14, 14, from_python_den=True)

def test_python_level_014(self):
self._complete_level(14, from_python_den=True)
Expand Down Expand Up @@ -391,7 +397,7 @@ def test_python_level_025(self):
)

def test_episode_13(self):
self._complete_episode(13, 26)
self._complete_episode(13, 26, from_python_den=True)

def test_python_level_026(self):
self._complete_level(26, from_python_den=True)
Expand Down Expand Up @@ -457,7 +463,9 @@ def test_python_level_041(self):
self._complete_level(41, from_python_den=True)

def test_episode_15(self):
self._complete_episode(15, 42, check_algorithm_score=False)
self._complete_episode(
15, 42, check_algorithm_score=False, from_python_den=True
)

def test_python_level_042(self):
self._complete_level(
Expand Down Expand Up @@ -498,7 +506,7 @@ def test_python_level_049(self):
)

def test_episode_22(self):
self._complete_episode(22, 50)
self._complete_episode(22, 50, from_python_den=True)

def test_python_level_050(self):
self._complete_level(50, from_python_den=True)
Expand Down
3 changes: 2 additions & 1 deletion game/end_to_end_tests/test_saving_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def test_save_and_load_workspace(self):
self.login_once()
level = 10
random_save_entry_name = "".join(
random.choice(string.ascii_uppercase + string.digits) for _ in range(10)
random.choice(string.ascii_uppercase + string.digits)
for _ in range(10)
)
return (
self.go_to_level(level)
Expand Down
18 changes: 18 additions & 0 deletions game/migrations/0100_reorder_python_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def set_level_order(apps: Apps, *args):
level79.next_level = None
level79.save()

level109 = Level.objects.get(name="109", default=True)
level109.next_level = None
level109.save()

level1013 = Level.objects.get(name="1013", default=True)
level1013.next_level = Level.objects.get(name="1014", default=True)
level1013.save()
Expand All @@ -94,6 +98,10 @@ def reset_level_order(apps: Apps, *args):
level79.next_level = Level.objects.get(name="80", default=True)
level79.save()

level109 = Level.objects.get(name="109", default=True)
level109.next_level = Level.objects.get(name="1001", default=True)
level109.save()

level1013 = Level.objects.get(name="1013", default=True)
level1013.next_level = None
level1013.save()
Expand All @@ -102,6 +110,11 @@ def reset_level_order(apps: Apps, *args):
def update_level_score_fields(apps: Apps, *args):
Level = apps.get_model("game", "Level")

level1001 = Level.objects.get(name="1001", default=True)
level1001.disable_algorithm_score = False
level1001.model_solution = "[5]"
level1001.save()

level1002 = Level.objects.get(name="1002", default=True)
level1002.disable_algorithm_score = False
level1002.model_solution = "[10]"
Expand All @@ -111,6 +124,11 @@ def update_level_score_fields(apps: Apps, *args):
def revert_level_score_fields(apps: Apps, *args):
Level = apps.get_model("game", "Level")

level1001 = Level.objects.get(name="1001", default=True)
level1001.disable_algorithm_score = True
level1001.model_solution = ""
level1001.save()

level1002 = Level.objects.get(name="1002", default=True)
level1002.disable_algorithm_score = True
level1002.model_solution = ""
Expand Down
2 changes: 1 addition & 1 deletion game/templates/game/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
var COWS = $('#data').data('cows')
var EPISODE = $('#data').data('episode')
var LEVEL_ID = $('#data').data('levelId')
var LEVEL_NAME = $('#data').data('level_name')
var LEVEL_NAME = $('#data').data('levelName')
var PREV_LEVEL_URL = "{% if prev_level_url %}{{prev_level_url}}{% else %}{% endif %}"
var NEXT_LEVEL_URL = "{% if next_level_url %}{{next_level_url}}{% else %}{% endif %}"
var MODEL_SOLUTION = {{model_solution|default:"[]"}}
Expand Down

0 comments on commit 9da6723

Please sign in to comment.