Skip to content

Commit

Permalink
Update everything
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Oct 13, 2023
1 parent 5f6f56b commit c2e6a6d
Show file tree
Hide file tree
Showing 8 changed files with 551 additions and 190 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
pip install pipenv==2022.10.4
pip install pytest-cov
pipenv install --dev --system
pip uninstall -y codeforlife-portal
pip install -U git+https://github.com/ocadotechnology/codeforlife-portal@update_selenium
- name: Collect static
run: python example_project/manage.py collectstatic --noinput
- name: Run Python tests
Expand Down
5 changes: 2 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ ipython = "*"
django-import-export = "*"

[dev-packages]
django-selenium-clean = "==0.3.3"
django-selenium-clean = "==1.0.0"
django-test-migrations = "==1.2.0"
selenium = "==3.141.0"
selenium = "==4.9.0"
pytest-django = "==4.5.2"
pytest = "==7.*"
pytest-xdist = "*"
pytest-order = "*"
codeforlife-portal = "*"
django-import-export = "*"
importlib-metadata = "<5" # Using version 5 causes an issue when trying to run pytest. Not sure why, linked to: https://stackoverflow.com/questions/73929564/entrypoints-object-has-no-attribute-get-digital-ocean
urllib3 = "==1.26.16"

[requires]
python_version = "3.8"
646 changes: 508 additions & 138 deletions Pipfile.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions game/end_to_end_tests/base_game_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
from common.tests.utils.organisation import create_organisation_directly
from common.tests.utils.student import create_school_student_directly
from common.tests.utils.teacher import signup_teacher_directly
from django.test import TestCase
from django.urls import reverse
from portal.tests.pageObjects.portal.home_page import HomePage
from portal.tests.pageObjects.portal.base_page import BasePage
from portal.tests.pageObjects.portal.home_page import HomePage

from game.models import Workspace
from . import custom_handler
Expand Down
4 changes: 2 additions & 2 deletions game/end_to_end_tests/editor_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def _dismiss_initial_dialog(self):

def dismiss_dialog(self, button_id):
self.wait_for_element_to_be_clickable((By.ID, button_id), wait_seconds=15)
self.browser.find_element_by_id(button_id).click()
self.browser.find_element(By.ID, button_id).click()
self.wait_for_element_to_be_invisible((By.ID, button_id), wait_seconds=15)

def go_to_code_tab(self):
self.browser.find_element_by_id("blocks_tab").click()
self.browser.find_element(By.ID, "blocks_tab").click()
55 changes: 28 additions & 27 deletions game/end_to_end_tests/game_page.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import print_function
from builtins import str

import os
import time
from builtins import str

from django.urls import reverse
from hamcrest import assert_that, equal_to, contains_string, ends_with
Expand All @@ -28,32 +29,32 @@ def _dismiss_initial_dialog(self):

def dismiss_dialog(self, button_id):
self.wait_for_element_to_be_clickable((By.ID, button_id), wait_seconds=15)
self.browser.find_element_by_id(button_id).click()
self.browser.find_element(By.ID, button_id).click()
self.wait_for_element_to_be_invisible((By.ID, button_id), wait_seconds=15)

def load_solution(self, workspace_id):
self.browser.find_element_by_id("load_tab").click()
self.browser.find_element(By.ID, "load_tab").click()
selector = "#loadWorkspaceTable tr[value='" + str(workspace_id) + "']"
self.wait_for_element_to_be_clickable((By.CSS_SELECTOR, selector))
self.browser.find_element_by_css_selector(selector).click()
self.browser.find_element_by_id("loadWorkspace").click()
self.browser.find_element(By.CSS_SELECTOR, selector).click()
self.browser.find_element(By.ID, "loadWorkspace").click()
time.sleep(1)
return self

def clear(self):
self.browser.find_element_by_id("clear_tab").click()
self.browser.find_element(By.ID, "clear_tab").click()
return self

def try_again(self):
self.dismiss_dialog("try_again_button")
return self

def step(self):
self.browser.find_element_by_id("step_tab").click()
self.browser.find_element(By.ID, "step_tab").click()
return self

def solution_button(self):
self.browser.find_element_by_id("solution_tab").click()
self.browser.find_element(By.ID, "solution_tab").click()
solution_loaded = self.browser.execute_script("return ocargo.solutionLoaded;")
timeout = time.time() + 30

Expand All @@ -66,11 +67,11 @@ def solution_button(self):
return self

def python_commands_button(self):
self.browser.find_element_by_id("van_commands_help").click()
self.browser.find_element(By.ID, "van_commands_help").click()
return self

def clear_console_button(self):
self.browser.find_element_by_id("clear_console").click()
self.browser.find_element(By.ID, "clear_console").click()
return self

def assert_level_number(self, level_number):
Expand All @@ -88,14 +89,14 @@ def assert_is_red_light(self, traffic_light_index):
self._assert_light_is_on(traffic_light_index, "red")

def _assert_light_is_on(self, traffic_light_index, colour):
image = self.browser.find_element_by_id(
image = self.browser.find_element(By.ID,
"trafficLight_%s_%s" % (traffic_light_index, colour)
)

assert_that(image.get_attribute("opacity"), equal_to("1"))

def run_program(self, wait_for_element_id="modal-content"):
self.browser.find_element_by_id("fast_tab").click()
self.browser.find_element(By.ID, "fast_tab").click()

try:
self.wait_for_element_to_be_clickable((By.ID, wait_for_element_id), 45)
Expand All @@ -115,9 +116,9 @@ def run_program(self, wait_for_element_id="modal-content"):

def run_retry_program(self):
self.run_program("try_again_button")
modal_content = self.browser.find_element_by_id("modal-content").text
modal_content = self.browser.find_element(By.ID, "modal-content").text
assert_that(modal_content, contains_string("Try creating a simpler program."))
self.browser.find_element_by_id("try_again_button").click()
self.browser.find_element(By.ID, "try_again_button").click()
time.sleep(1)
return self

Expand Down Expand Up @@ -173,7 +174,7 @@ def run_invalid_import_program(self):
def check_python_commands(self):
self.python_commands_button()
time.sleep(1)
python_commands = self.browser.find_element_by_id("myModal-lead").text
python_commands = self.browser.find_element(By.ID, "myModal-lead").text
assert_that(
python_commands,
contains_string("Run the following commands on the van object v"),
Expand All @@ -182,48 +183,48 @@ def check_python_commands(self):

def write_to_then_clear_console(self):
self._write_code("my_van.")
self.browser.find_element_by_id("fast_tab").click()
self.browser.find_element(By.ID, "fast_tab").click()
time.sleep(1)
console = self.browser.find_element_by_id("consoleOutput")
console = self.browser.find_element(By.ID, "consoleOutput")
self.clear_console_button()
assert_that(console.text == "")
return self

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

Check warning on line 195 in game/end_to_end_tests/game_page.py

View check run for this annotation

Codecov / codecov/patch

game/end_to_end_tests/game_page.py#L195

Added line #L195 was not covered by tests
WebDriverWait(self.browser, 10).until(
presence_of_all_elements_located((By.ID, "blockly_tab"))
)
return self

def next_level(self):
self.assert_success()
self.browser.find_element_by_id("next_level_button").click()
self.browser.find_element(By.ID, "next_level_button").click()
WebDriverWait(self.browser, 10).until(
presence_of_all_elements_located((By.ID, "blockly_tab"))
)
return self

def _run_failing_program(self, text):
self.run_program("try_again_button")
error_message = self.browser.find_element_by_id("myModal-lead").text
error_message = self.browser.find_element(By.ID, "myModal-lead").text
assert_that(error_message, contains_string(text))
return self

def _run_failing_python_program_console(self, code, console_message):
self._write_code(code)
self.browser.find_element_by_id("fast_tab").click()
self.browser.find_element(By.ID, "fast_tab").click()
time.sleep(1)
console = self.browser.find_element_by_id("consoleOutput")
console = self.browser.find_element(By.ID, "consoleOutput")
assert_that(console.text, contains_string(console_message))
return self

def _run_failing_python_program_popup(self, code, text):
self._write_code(code)
self.browser.find_element_by_id("fast_tab").click()
self.browser.find_element(By.ID, "fast_tab").click()
time.sleep(1)
error_message = self.browser.find_element_by_id("myModal-lead").text
error_message = self.browser.find_element(By.ID, "myModal-lead").text
assert_that(error_message, contains_string(text))
return self

Expand All @@ -235,17 +236,17 @@ def _write_code(self, code):

def _run_procedure_error_program(self, text):
self.run_program("close_button")
error_message = self.browser.find_element_by_id("myModal-mainText").text
error_message = self.browser.find_element(By.ID, "myModal-mainText").text
assert_that(error_message, contains_string(text))

def _assert_score(self, element_id, score):
score_text = self.browser.find_element_by_id(element_id).text
score_text = self.browser.find_element(By.ID, element_id).text
score_number = score_text.split("/")[0]
assert_that(score_number, equal_to(str(score)))
return self

def assert_success(self):
modal_content = self.browser.find_element_by_id("modal-content").text
modal_content = self.browser.find_element(By.ID, "modal-content").text
assert_that(modal_content, contains_string("Congratulations"))
return self

Expand Down
17 changes: 5 additions & 12 deletions game/end_to_end_tests/test_level_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
from common.tests.utils.organisation import create_organisation_directly
from common.tests.utils.student import create_school_student_directly
from common.tests.utils.teacher import signup_teacher_directly

from hamcrest import assert_that, ends_with, equal_to

from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

from game.end_to_end_tests.base_game_test import BaseGameTest
from game.models import Attempt, Episode
Expand Down Expand Up @@ -35,9 +34,7 @@ def test_coins(self):
page = self.go_to_reverse("levels")

# The coin images for the levels
level_coin_images = page.browser.find_elements_by_css_selector(
"#collapse-4 div img"
)
level_coin_images = page.browser.find_elements(By.CSS_SELECTOR, ("#collapse-4 div img"))
# There are 4 levels in this episode, each with gold coin
assert_that(len(level_coin_images), equal_to(4))

Expand All @@ -48,17 +45,13 @@ def test_coins(self):
)

# So the episode has a gold coin too
episode_coin_image = page.browser.find_element_by_css_selector(
"#episode-4 > p > img"
)
episode_coin_image = page.browser.find_element(By.CSS_SELECTOR, "#episode-4 > p > img")
assert_that(
episode_coin_image.get_attribute("src"),
ends_with("/static/game/image/coins/coin_gold.svg"),
)

try:
image_for_uncomplete_episode = page.browser.find_element_by_css_selector(
"#episode-3 > p > img"
)
image_for_uncomplete_episode = page.browser.find_element(By.CSS_SELECTOR, "#episode-3 > p > img")
except NoSuchElementException as this_should_happen:
pass
pass
9 changes: 3 additions & 6 deletions game/end_to_end_tests/test_python_levels.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from time import sleep
from game.end_to_end_tests.base_game_test import BaseGameTest
from portal.tests.pageObjects.portal.base_page import BasePage

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException

from game.end_to_end_tests.base_game_test import BaseGameTest

DELAY_TIME = 10

Expand All @@ -31,7 +28,7 @@ def test_invalid_import(self):

def test_run_code(self):
self.go_to_level(92)
run_code = self.selenium.find_element_by_id("run-code-button")
run_code = self.selenium.find_element(By.ID, "run-code-button")
run_code.click()
assert WebDriverWait(self.selenium, DELAY_TIME).until(
EC.presence_of_all_elements_located((By.ID, "myModal-lead"))
Expand Down

0 comments on commit c2e6a6d

Please sign in to comment.