From 46f5eb69bbf3b9ad741b6cc7140a2b889aa55752 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Thu, 23 May 2024 14:36:29 +0000 Subject: [PATCH 01/30] fix scoring for custom levels --- .../custom_level_scoring_solution_file.xml | 7 ++++ game/end_to_end_tests/game_page.py | 6 ++++ game/end_to_end_tests/test_level_win.py | 35 +++++++++++++++++++ game/views/level.py | 1 + 4 files changed, 49 insertions(+) create mode 100644 game/end_to_end_tests/data/blockly_solutions/custom_level_scoring_solution_file.xml diff --git a/game/end_to_end_tests/data/blockly_solutions/custom_level_scoring_solution_file.xml b/game/end_to_end_tests/data/blockly_solutions/custom_level_scoring_solution_file.xml new file mode 100644 index 000000000..ecf5481f4 --- /dev/null +++ b/game/end_to_end_tests/data/blockly_solutions/custom_level_scoring_solution_file.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/game/end_to_end_tests/game_page.py b/game/end_to_end_tests/game_page.py index e76a7d7d8..747212790 100644 --- a/game/end_to_end_tests/game_page.py +++ b/game/end_to_end_tests/game_page.py @@ -134,6 +134,12 @@ def run_retry_program(self): self.browser.find_element(By.ID, "try_again_button").click() time.sleep(1) return self + + def run_custom_level_program(self): + self.run_program() + modal_content = self.browser.find_element(By.ID, "modal-content").text + assert_that(modal_content, not(contains_string("Algorithm score:"))) + return self def run_crashing_program(self): return self._run_failing_program("What went wrong") diff --git a/game/end_to_end_tests/test_level_win.py b/game/end_to_end_tests/test_level_win.py index ec10d9391..d6df27746 100644 --- a/game/end_to_end_tests/test_level_win.py +++ b/game/end_to_end_tests/test_level_win.py @@ -1,7 +1,10 @@ from game.end_to_end_tests.base_game_test import BaseGameTest +from game.models import Level class TestLevelWin(BaseGameTest): + custom_level = None + def test_deliver_everywhere(self): self.deliver_everywhere_test(level=16) @@ -10,3 +13,35 @@ def test_try_again_if_not_full_score(self): level=19, workspace_file="complete_level_not_with_full_score" ) self.complete_and_check_level(19, page) + + def test_custom_level_scoring(self): + user_profile = self.login_once() + TestLevelWin.custom_level.owner = user_profile + TestLevelWin.custom_level.save() + workspace_id = self.use_workspace("custom_level_scoring_solution_file", user_profile) + self.go_to_custom_level(TestLevelWin.custom_level).load_solution(workspace_id).run_custom_level_program() + + @classmethod + def setUpClass(cls): + BaseGameTest.setUpClass() + + TestLevelWin.custom_level = Level( + name="Custom level", + anonymous=False, + blocklyEnabled=True, + character=van, + cows='[]', + default=False, + destinations="[[3,4]]", + direct_drive=True, + fuel_gauge=False, + max_fuel=50, + model_solution="[1]", + origin='{"coordinate":[3,5],"direction":"S"}', + path='[{"coordinate":[3,5],"connectedNodes":[1]},{"coordinate":[3,4],' '"connectedNodes":[0]}]', + pythonEnabled=False, + theme=grass, + threads=1, + traffic_lights="[]", + ) + diff --git a/game/views/level.py b/game/views/level.py index d6808f99a..29287f821 100644 --- a/game/views/level.py +++ b/game/views/level.py @@ -38,6 +38,7 @@ def play_custom_level_from_editor(request, levelId): def play_custom_level(request, levelId, from_editor=False): level = cached_custom_level(levelId) + level.disable_algorithm_score = True if level.default: raise Http404 From 260b9623858ad0e2140ef205f78f4842b6b7b793 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Thu, 23 May 2024 14:42:48 +0000 Subject: [PATCH 02/30] debug test --- game/end_to_end_tests/test_level_win.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/game/end_to_end_tests/test_level_win.py b/game/end_to_end_tests/test_level_win.py index d6df27746..bc2d14cdd 100644 --- a/game/end_to_end_tests/test_level_win.py +++ b/game/end_to_end_tests/test_level_win.py @@ -1,6 +1,7 @@ from game.end_to_end_tests.base_game_test import BaseGameTest from game.models import Level +from game.character import get_character class TestLevelWin(BaseGameTest): custom_level = None @@ -29,7 +30,7 @@ def setUpClass(cls): name="Custom level", anonymous=False, blocklyEnabled=True, - character=van, + character=get_character("Van"), cows='[]', default=False, destinations="[[3,4]]", From 5f9d16da57f30deb80d6f0dae348126160462088 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Thu, 23 May 2024 14:49:37 +0000 Subject: [PATCH 03/30] debug test --- game/end_to_end_tests/test_level_win.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/game/end_to_end_tests/test_level_win.py b/game/end_to_end_tests/test_level_win.py index bc2d14cdd..380755fef 100644 --- a/game/end_to_end_tests/test_level_win.py +++ b/game/end_to_end_tests/test_level_win.py @@ -2,6 +2,7 @@ from game.models import Level from game.character import get_character +from game.theme import get_theme class TestLevelWin(BaseGameTest): custom_level = None @@ -41,7 +42,7 @@ def setUpClass(cls): origin='{"coordinate":[3,5],"direction":"S"}', path='[{"coordinate":[3,5],"connectedNodes":[1]},{"coordinate":[3,4],' '"connectedNodes":[0]}]', pythonEnabled=False, - theme=grass, + theme=get_theme(name="grass"), threads=1, traffic_lights="[]", ) From 914feb87fdf04c608c36ce97245063d33275baec Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Thu, 23 May 2024 15:02:39 +0000 Subject: [PATCH 04/30] debug test --- game/end_to_end_tests/game_page.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/end_to_end_tests/game_page.py b/game/end_to_end_tests/game_page.py index 747212790..3706f1b3c 100644 --- a/game/end_to_end_tests/game_page.py +++ b/game/end_to_end_tests/game_page.py @@ -136,7 +136,7 @@ def run_retry_program(self): return self def run_custom_level_program(self): - self.run_program() + self.run_program("close_button") modal_content = self.browser.find_element(By.ID, "modal-content").text assert_that(modal_content, not(contains_string("Algorithm score:"))) return self From 7beb67cd238b23519b2bab62201655b2ae12df7e Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Thu, 23 May 2024 15:21:15 +0000 Subject: [PATCH 05/30] debug test --- game/end_to_end_tests/test_level_win.py | 12 ++++++------ game/tests/test_level_editor.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/game/end_to_end_tests/test_level_win.py b/game/end_to_end_tests/test_level_win.py index 380755fef..4ec2d8502 100644 --- a/game/end_to_end_tests/test_level_win.py +++ b/game/end_to_end_tests/test_level_win.py @@ -16,12 +16,12 @@ def test_try_again_if_not_full_score(self): ) self.complete_and_check_level(19, page) - def test_custom_level_scoring(self): - user_profile = self.login_once() - TestLevelWin.custom_level.owner = user_profile - TestLevelWin.custom_level.save() - workspace_id = self.use_workspace("custom_level_scoring_solution_file", user_profile) - self.go_to_custom_level(TestLevelWin.custom_level).load_solution(workspace_id).run_custom_level_program() + # def test_custom_level_scoring(self): + # user_profile = self.login_once() + # TestLevelWin.custom_level.owner = user_profile + # TestLevelWin.custom_level.save() + # workspace_id = self.use_workspace("custom_level_scoring_solution_file", user_profile) + # self.go_to_custom_level(TestLevelWin.custom_level).load_solution(workspace_id).run_custom_level_program() @classmethod def setUpClass(cls): diff --git a/game/tests/test_level_editor.py b/game/tests/test_level_editor.py index a4c538ff6..0ed33ee8a 100644 --- a/game/tests/test_level_editor.py +++ b/game/tests/test_level_editor.py @@ -392,6 +392,20 @@ def test_level_loading_with_multiple_houses(self): assert response.status_code == 200 assert response_data["level"]["destinations"] == "[[3,4], [3,3]]" + def test_custom_level_scoring(self): + email1, password1 = signup_teacher_directly() + + teacher1 = Teacher.objects.get(new_user__email=email1) + + self.login(email1, password1) + level = create_save_level_with_multiple_houses(teacher1) + url = reverse("load_level_for_editor", kwargs={"levelID": level.id}) + response = self.client.get(url) + response_data = response.json() + + assert response.status_code == 200 + assert response_data["level"]["disable_algorithm_score"] == True + def test_level_of_anonymised_teacher_is_hidden(self): # Create 2 teacher accounts email1, password1 = signup_teacher_directly() From 218c47a0b40dc3cbfc0fcb03a88695cdd62191a9 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Thu, 23 May 2024 15:39:42 +0000 Subject: [PATCH 06/30] debug test --- game/tests/test_level_editor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/game/tests/test_level_editor.py b/game/tests/test_level_editor.py index 0ed33ee8a..dfe38ab2a 100644 --- a/game/tests/test_level_editor.py +++ b/game/tests/test_level_editor.py @@ -399,7 +399,8 @@ def test_custom_level_scoring(self): self.login(email1, password1) level = create_save_level_with_multiple_houses(teacher1) - url = reverse("load_level_for_editor", kwargs={"levelID": level.id}) + url = reverse("play_custom_level", kwargs={"levelId": level.id}) + response = self.client.get(url) response_data = response.json() From c7897ed965966e987f359231ba47b7183fb12a80 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Thu, 23 May 2024 16:07:51 +0000 Subject: [PATCH 07/30] debug test --- game/tests/test_level_editor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/tests/test_level_editor.py b/game/tests/test_level_editor.py index dfe38ab2a..d78e0d024 100644 --- a/game/tests/test_level_editor.py +++ b/game/tests/test_level_editor.py @@ -402,10 +402,10 @@ def test_custom_level_scoring(self): url = reverse("play_custom_level", kwargs={"levelId": level.id}) response = self.client.get(url) - response_data = response.json() + # response_data = response.json() assert response.status_code == 200 - assert response_data["level"]["disable_algorithm_score"] == True + # assert response_data["level"]["disable_algorithm_score"] == True def test_level_of_anonymised_teacher_is_hidden(self): # Create 2 teacher accounts From 8ff5851d39b462dc229009b14fa971bab9b7bf5d Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Thu, 23 May 2024 16:15:07 +0000 Subject: [PATCH 08/30] debug test --- game/tests/test_level_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/tests/test_level_editor.py b/game/tests/test_level_editor.py index d78e0d024..cd023d616 100644 --- a/game/tests/test_level_editor.py +++ b/game/tests/test_level_editor.py @@ -402,7 +402,7 @@ def test_custom_level_scoring(self): url = reverse("play_custom_level", kwargs={"levelId": level.id}) response = self.client.get(url) - # response_data = response.json() + response_data = response.json() assert response.status_code == 200 # assert response_data["level"]["disable_algorithm_score"] == True From 216e8b7f957fbb1580e893211929aa821caf3ef3 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Thu, 23 May 2024 16:51:41 +0000 Subject: [PATCH 09/30] debug test --- game/templates/game/game.html | 3 ++- game/tests/test_level_editor.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/game/templates/game/game.html b/game/templates/game/game.html index c4e8df780..eb724e318 100644 --- a/game/templates/game/game.html +++ b/game/templates/game/game.html @@ -15,7 +15,8 @@ data-cows="{{level.cows|trim}}" data-episode="{{level.episode.id|trim}}" data-level-id="{{level.id|default_if_none:''|trim}}" - data-level-name="{{level.name|trim}}" + data-level-name="{{level.name|trim}}" + data-disable-algorithm-score="{{level.disable_algorithm_score|booltojs}}" > var ANONYMOUS = {{level.anonymous|booltojs}} var PATH = $('#data').data('path') diff --git a/game/tests/test_level_editor.py b/game/tests/test_level_editor.py index cd023d616..f8eac7b14 100644 --- a/game/tests/test_level_editor.py +++ b/game/tests/test_level_editor.py @@ -402,7 +402,7 @@ def test_custom_level_scoring(self): url = reverse("play_custom_level", kwargs={"levelId": level.id}) response = self.client.get(url) - response_data = response.json() + response_data = response.getElementById("data") assert response.status_code == 200 # assert response_data["level"]["disable_algorithm_score"] == True From 2bd70de6cf8f7e88db49f6207865a6bc66daac4f Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Fri, 24 May 2024 10:19:11 +0000 Subject: [PATCH 10/30] debug test --- game/tests/test_level_editor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/game/tests/test_level_editor.py b/game/tests/test_level_editor.py index f8eac7b14..8332c0990 100644 --- a/game/tests/test_level_editor.py +++ b/game/tests/test_level_editor.py @@ -402,9 +402,11 @@ def test_custom_level_scoring(self): url = reverse("play_custom_level", kwargs={"levelId": level.id}) response = self.client.get(url) - response_data = response.getElementById("data") + response_text = response.content + print(response_text) assert response.status_code == 200 + assert_that(type(response_text), str) # assert response_data["level"]["disable_algorithm_score"] == True def test_level_of_anonymised_teacher_is_hidden(self): From 7db1d81c53a9a20ad98cdffb49b11c3cb643d14b Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Fri, 24 May 2024 10:34:07 +0000 Subject: [PATCH 11/30] debug test --- game/tests/test_level_editor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/game/tests/test_level_editor.py b/game/tests/test_level_editor.py index 8332c0990..87f1eb5ed 100644 --- a/game/tests/test_level_editor.py +++ b/game/tests/test_level_editor.py @@ -403,10 +403,9 @@ def test_custom_level_scoring(self): response = self.client.get(url) response_text = response.content - print(response_text) assert response.status_code == 200 - assert_that(type(response_text), str) + assert type(response_text) == str # assert response_data["level"]["disable_algorithm_score"] == True def test_level_of_anonymised_teacher_is_hidden(self): From 164a6c624677d174ea32b673d86916e8067dfd33 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Fri, 24 May 2024 10:42:01 +0000 Subject: [PATCH 12/30] debug test --- game/templates/game/game.html | 1 - game/tests/test_level_editor.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/game/templates/game/game.html b/game/templates/game/game.html index eb724e318..3dd17ae15 100644 --- a/game/templates/game/game.html +++ b/game/templates/game/game.html @@ -16,7 +16,6 @@ data-episode="{{level.episode.id|trim}}" data-level-id="{{level.id|default_if_none:''|trim}}" data-level-name="{{level.name|trim}}" - data-disable-algorithm-score="{{level.disable_algorithm_score|booltojs}}" > var ANONYMOUS = {{level.anonymous|booltojs}} var PATH = $('#data').data('path') diff --git a/game/tests/test_level_editor.py b/game/tests/test_level_editor.py index 87f1eb5ed..39b0240b6 100644 --- a/game/tests/test_level_editor.py +++ b/game/tests/test_level_editor.py @@ -402,11 +402,11 @@ def test_custom_level_scoring(self): url = reverse("play_custom_level", kwargs={"levelId": level.id}) response = self.client.get(url) - response_text = response.content + decoded_response = response.content.decode("utf-8") + disabled_algorithm_score = decoded_response.find("var DISABLE_ALGORITHM_SCORE = true") assert response.status_code == 200 - assert type(response_text) == str - # assert response_data["level"]["disable_algorithm_score"] == True + assert disabled_algorithm_score > 0 def test_level_of_anonymised_teacher_is_hidden(self): # Create 2 teacher accounts From 2f3c6ee9def01062c34afb9289e7245cb3150d94 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Fri, 24 May 2024 10:51:17 +0000 Subject: [PATCH 13/30] tidy code --- .../custom_level_scoring_solution_file.xml | 7 ---- game/end_to_end_tests/game_page.py | 6 ---- game/end_to_end_tests/test_level_win.py | 36 ------------------- 3 files changed, 49 deletions(-) delete mode 100644 game/end_to_end_tests/data/blockly_solutions/custom_level_scoring_solution_file.xml diff --git a/game/end_to_end_tests/data/blockly_solutions/custom_level_scoring_solution_file.xml b/game/end_to_end_tests/data/blockly_solutions/custom_level_scoring_solution_file.xml deleted file mode 100644 index ecf5481f4..000000000 --- a/game/end_to_end_tests/data/blockly_solutions/custom_level_scoring_solution_file.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/game/end_to_end_tests/game_page.py b/game/end_to_end_tests/game_page.py index 3706f1b3c..e76a7d7d8 100644 --- a/game/end_to_end_tests/game_page.py +++ b/game/end_to_end_tests/game_page.py @@ -134,12 +134,6 @@ def run_retry_program(self): self.browser.find_element(By.ID, "try_again_button").click() time.sleep(1) return self - - def run_custom_level_program(self): - self.run_program("close_button") - modal_content = self.browser.find_element(By.ID, "modal-content").text - assert_that(modal_content, not(contains_string("Algorithm score:"))) - return self def run_crashing_program(self): return self._run_failing_program("What went wrong") diff --git a/game/end_to_end_tests/test_level_win.py b/game/end_to_end_tests/test_level_win.py index 4ec2d8502..9f227d8f1 100644 --- a/game/end_to_end_tests/test_level_win.py +++ b/game/end_to_end_tests/test_level_win.py @@ -1,11 +1,6 @@ from game.end_to_end_tests.base_game_test import BaseGameTest -from game.models import Level - -from game.character import get_character -from game.theme import get_theme class TestLevelWin(BaseGameTest): - custom_level = None def test_deliver_everywhere(self): self.deliver_everywhere_test(level=16) @@ -16,34 +11,3 @@ def test_try_again_if_not_full_score(self): ) self.complete_and_check_level(19, page) - # def test_custom_level_scoring(self): - # user_profile = self.login_once() - # TestLevelWin.custom_level.owner = user_profile - # TestLevelWin.custom_level.save() - # workspace_id = self.use_workspace("custom_level_scoring_solution_file", user_profile) - # self.go_to_custom_level(TestLevelWin.custom_level).load_solution(workspace_id).run_custom_level_program() - - @classmethod - def setUpClass(cls): - BaseGameTest.setUpClass() - - TestLevelWin.custom_level = Level( - name="Custom level", - anonymous=False, - blocklyEnabled=True, - character=get_character("Van"), - cows='[]', - default=False, - destinations="[[3,4]]", - direct_drive=True, - fuel_gauge=False, - max_fuel=50, - model_solution="[1]", - origin='{"coordinate":[3,5],"direction":"S"}', - path='[{"coordinate":[3,5],"connectedNodes":[1]},{"coordinate":[3,4],' '"connectedNodes":[0]}]', - pythonEnabled=False, - theme=get_theme(name="grass"), - threads=1, - traffic_lights="[]", - ) - From c6093c869936516026c30edb02a112f12dc5697c Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Fri, 24 May 2024 10:57:22 +0000 Subject: [PATCH 14/30] tidy code pt 2 --- game/end_to_end_tests/test_level_win.py | 3 +-- game/templates/game/game.html | 18 +++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/game/end_to_end_tests/test_level_win.py b/game/end_to_end_tests/test_level_win.py index 9f227d8f1..ec10d9391 100644 --- a/game/end_to_end_tests/test_level_win.py +++ b/game/end_to_end_tests/test_level_win.py @@ -1,7 +1,7 @@ from game.end_to_end_tests.base_game_test import BaseGameTest -class TestLevelWin(BaseGameTest): +class TestLevelWin(BaseGameTest): def test_deliver_everywhere(self): self.deliver_everywhere_test(level=16) @@ -10,4 +10,3 @@ def test_try_again_if_not_full_score(self): level=19, workspace_file="complete_level_not_with_full_score" ) self.complete_and_check_level(19, page) - diff --git a/game/templates/game/game.html b/game/templates/game/game.html index 3dd17ae15..ace7b34d0 100644 --- a/game/templates/game/game.html +++ b/game/templates/game/game.html @@ -7,15 +7,15 @@ {% block scripts %} {{block.super}} -