Skip to content

Commit cc6e0d0

Browse files
author
Obada Haddad
committed
add competition tests; update account creation, submission tests
1 parent 842a58a commit cc6e0d0

File tree

5 files changed

+150
-13
lines changed

5 files changed

+150
-13
lines changed

.circleci/config.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ jobs:
4343
docker pull codalab/codalab-legacy:py37
4444
docker pull codalab/codalab-legacy:py3
4545
46+
# TODO: Putting E2E tests earlier to make playwright testing faster. Will remove after the PR is merged
47+
- run:
48+
name: "Tests: Run end-to-end (E2E) tests"
49+
command: |
50+
cd playwrightPython && $HOME/.local/bin/uv run pytest test_auth.py test_account_creation.py test_competition.py test_submission.py
51+
no_output_timeout: 30m
52+
4653
- run:
4754
name: "Tests: Run unit/integration tests (excluding e2e)"
4855
command: docker compose -f docker-compose.yml -f docker-compose.selenium.yml exec django py.test src/ -m "not e2e"
@@ -51,18 +58,21 @@ jobs:
5158
# name: "Tests: Run end-to-end (E2E) tests"
5259
# command: docker compose -f docker-compose.yml -f docker-compose.selenium.yml exec django py.test src/tests/functional/ -m e2e
5360
# no_output_timeout: 60m
54-
- run:
55-
name: "Tests: Run end-to-end (E2E) tests"
56-
command: |
57-
cd playwrightPython && $HOME/.local/bin/uv run pytest test_auth.py test_account_creation.py test_submission.py
58-
no_output_timeout: 30m
61+
62+
# TODO: uncomment this block just before the playwright PR is merged
63+
#- run:
64+
# name: "Tests: Run end-to-end (E2E) tests"
65+
# command: |
66+
# cd playwrightPython && $HOME/.local/bin/uv run pytest test_auth.py test_account_creation.py test_competition.py test_submission.py
67+
# no_output_timeout: 30m
5968

6069
# Example to run specific set of tests (for debugging individual tests from a batch of tests)
6170
# - run:
6271
# name: e2e tests - competitions
6372
# command: docker compose -f docker-compose.yml -f docker-compose.selenium.yml exec django py.test src/tests/functional/test_competitions.py -m e2e
6473
# no_output_timeout: 60m
65-
74+
- store_artifacts:
75+
path: playwrightPython/test-results
6676
- store_artifacts:
6777
path: artifacts/
6878

.github/workflows/tests_pytest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
needs: [build]
3737
steps:
3838
- name: "Lint: Check code style with flake8"
39-
run: docker compose -f docker-compose.yml -f docker-compose.selenium.yml exec django flake8 src/
39+
run: docker compose exec django flake8 src/
4040
unit_tests:
4141
name: Unit test with Selenium
4242
runs-on: self-hosted
@@ -50,7 +50,7 @@ jobs:
5050
needs: [linter,build]
5151
steps:
5252
- name: "Tests: Run end-to-end (E2E) tests"
53-
run: cd playwrightPython && $HOME/.local/bin/uv run pytest test_auth.py test_account_creation.py test_submission.py
53+
run: cd playwrightPython && $HOME/.local/bin/uv run pytest test_auth.py test_account_creation.py test_competition.py test_submission.py
5454
cleanup:
5555
name: Cleanup
5656
runs-on: self-hosted

playwrightPython/test_account_creation.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
import toml
33
from loguru import logger
44
from playwright.sync_api import expect, Page
5+
import random
6+
7+
8+
def randomNumber():
9+
return str(random.randint(0, 1000))
10+
511

612
data = toml.load("config/config.toml")
7-
test_user = data["test_user"]["username"]
8-
test_password = data["test_user"]["password"]
13+
test_user = data["test_user"]["username"] + randomNumber()
14+
test_password = data["test_user"]["password"] + randomNumber()
915
test_email = test_user + "@email.com"
1016
test_failed_user = data["test_failed_user"]["username"]
1117
db_host = data["database"]["host"]
@@ -55,8 +61,8 @@ def test_account_creation(page: Page):
5561
# Execute a command: this creates a new table
5662
cur.execute("SELECT username FROM profiles_user;")
5763
for row in cur:
58-
logger.debug(row)
59-
if row[0] in test_user:
64+
logger.debug(row[0])
65+
if row[0] == test_user:
6066
assert row[0] == test_user
6167
found = "true"
6268
break
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
from playwright.sync_api import expect, Page
2+
import toml
3+
import pytest
4+
import random
5+
6+
data = toml.load("config/config.toml")
7+
8+
titleNum = random.randint(0, 1000)
9+
10+
11+
# This allows us to autologin with a cookie in all tests instead of having to login each time
12+
@pytest.fixture(scope="session")
13+
def browser_context_args(browser_context_args):
14+
""" """
15+
browser_context_args.update(storage_state="config/state.json",)
16+
return browser_context_args
17+
18+
19+
def test_competition_upload(page: Page):
20+
page.goto("http://localhost/")
21+
page.get_by_role("link", name=" Benchmarks/Competitions").click()
22+
page.get_by_role("link", name=" Upload").click()
23+
with page.expect_file_chooser() as fc_info:
24+
page.get_by_role("button", name="").click()
25+
file_chooser = fc_info.value
26+
file_chooser.set_files("test_files/competitions/competition.zip")
27+
expect(page.get_by_text("Competition created!")).to_be_visible()
28+
29+
30+
def task_creation(page):
31+
page.goto("http://localhost/")
32+
page.get_by_text("codabench Admin management").click()
33+
page.get_by_role("link", name=" Resources").click()
34+
page.get_by_text("Datasets and programs").first.click()
35+
page.get_by_role("button", name=" Add Dataset/Program").click()
36+
page.get_by_role("textbox", name="Name").click()
37+
page.get_by_role("textbox", name="Name").fill(str(titleNum) + "Playwright Scoring Program")
38+
page.get_by_role("textbox", name="Description").click()
39+
page.get_by_role("textbox", name="Description").fill("Test Dataset Description")
40+
page.locator(".ui.form > div > .ui").click()
41+
page.get_by_text("Scoring Program", exact=True).nth(5).click()
42+
with page.expect_file_chooser() as fc_info:
43+
page.get_by_role("button", name="").click()
44+
file_chooser = fc_info.value
45+
file_chooser.set_files("test_files/Task/Scoring Program/scoring_program.zip")
46+
page.get_by_role("button", name=" Upload").click()
47+
page.get_by_text("Tasks", exact=True).click()
48+
page.get_by_text("Create Task").first.click()
49+
page.get_by_role("textbox", name="Name", exact=True).click()
50+
page.get_by_role("textbox", name="Name", exact=True).fill(str(titleNum) + "Playwright Task")
51+
page.get_by_role("textbox", name="Description").click()
52+
page.get_by_role("textbox", name="Description").fill("Test Descirption Task")
53+
page.get_by_text("Datasets and programs").nth(3).click()
54+
page.locator("#scoring_program").click()
55+
page.locator("#scoring_program").fill("test")
56+
page.locator("a").filter(has_text=str(titleNum) + "Playwright Scoring Program").click()
57+
page.get_by_text("Create", exact=True).click()
58+
59+
60+
def test_manual_competition_creation(page: Page):
61+
task_creation(page)
62+
page.goto("http://localhost/")
63+
page.get_by_role("link", name=" Benchmarks/Competitions").click()
64+
page.get_by_role("link", name=" Create").click()
65+
page.get_by_role("textbox").nth(1).click()
66+
page.get_by_role("textbox").nth(1).fill("Test")
67+
with page.expect_file_chooser() as fc_info:
68+
page.get_by_role("button", name="").click()
69+
file_chooser = fc_info.value
70+
file_chooser.set_files("test_files/competition/test_logo.png")
71+
page.locator(".CodeMirror-scroll").first.click()
72+
page.get_by_role("application").get_by_role("textbox").fill("on")
73+
page.get_by_role("textbox", name="Example: codalab/codalab-").click()
74+
page.get_by_role("textbox", name="Example: codalab/codalab-").fill("codalab/codalab-legacy:py37")
75+
page.get_by_text("Participation").click()
76+
page.locator("pre").nth(3).click()
77+
page.get_by_role("application").filter(has_text="|||xxxxxxxxxx 101:").get_by_role("textbox").fill("Test Terms")
78+
page.locator("input[name=\"registration_auto_approve\"]").check()
79+
page.locator("a").filter(has_text="Pages").click()
80+
page.get_by_role("button", name=" Add page").click()
81+
page.get_by_role("textbox").nth(1).fill("Test Title")
82+
page.locator("div:nth-child(2) > .EasyMDEContainer > .CodeMirror > .CodeMirror-scroll").click()
83+
page.get_by_role("application").get_by_role("textbox").fill("Test Content")
84+
page.get_by_text("Save").nth(1).click()
85+
page.locator("a").filter(has_text="Phases").click()
86+
page.get_by_role("button", name=" Add phase").click()
87+
page.locator("input[name=\"name\"]").click()
88+
page.locator("input[name=\"name\"]").fill(str(titleNum) + "Playwright Task")
89+
page.locator("input[name=\"start_date\"]").click()
90+
page.get_by_role("cell", name="12").click()
91+
page.locator("input[name=\"start_time\"]").click()
92+
page.get_by_role("cell", name="10:").click()
93+
page.get_by_role("cell", name=":00").click()
94+
page.locator("input[name=\"end_date\"]").click()
95+
page.locator("input[name=\"end_date\"]").fill("")
96+
page.locator("div:nth-child(7) > .EasyMDEContainer > .CodeMirror > .CodeMirror-scroll").click()
97+
page.locator(".CodeMirror.cm-s-easymde.CodeMirror-wrap.CodeMirror-focused > div > textarea").fill("Phase")
98+
page.locator(".ui.search.selection.dropdown.multiple").first.click()
99+
page.locator(".ui.search.selection.dropdown.multiple > .search").first.fill(str(titleNum) + "Playwright Task")
100+
page.get_by_text(str(titleNum) + "Playwright Task").nth(1).click()
101+
page.get_by_text("Save").nth(3).click()
102+
page.get_by_text("Leaderboard", exact=True).click()
103+
page.get_by_role("button", name=" Add leaderboard").click()
104+
page.locator("input[name=\"title\"]").click()
105+
page.locator("input[name=\"title\"]").fill("Test title LEaderboard")
106+
page.locator("input[name=\"key\"]").click()
107+
page.locator("input[name=\"key\"]").fill("Test Key")
108+
page.locator(".ui.plus").click()
109+
page.locator("input[name=\"column_key_0\"]").click()
110+
page.locator("input[name=\"column_key_0\"]").fill("Test Key")
111+
page.locator("input[name=\"key\"]").click()
112+
page.locator("input[name=\"key\"]").press("ControlOrMeta+a")
113+
page.locator("input[name=\"key\"]").fill("Key")
114+
page.locator("input[name=\"column_key_0\"]").click()
115+
page.get_by_text("Save").nth(4).click()
116+
page.get_by_role("button", name="Save").click()
117+
expect(page.get_by_text("Test", exact=True)).to_be_visible()
118+
expect(page.get_by_text("Test Content")).to_be_visible()
119+
120+
# TODO Verify a few more items from the created competition

playwrightPython/test_submission.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def wait_for_finished(page, time_out):
2222

2323

2424
def test_submission_basic(page: Page) -> None:
25+
page.set_default_timeout(300000)
2526
page.goto("http://localhost/")
2627
page.get_by_role("link", name=" Benchmarks/Competitions").click()
2728
page.get_by_role("link", name=" Upload").click()
@@ -124,7 +125,7 @@ def test_submission_v18(page: Page) -> None:
124125
with page.expect_file_chooser() as fc_info:
125126
page.get_by_role("button", name="").click()
126127
file_chooser = fc_info.value
127-
file_chooser.set_files("test_files/competitions/competition_18.zip`")
128+
file_chooser.set_files("test_files/competitions/competition_18.zip")
128129
page.get_by_role("link", name="View").click()
129130
page.get_by_text("My Submissions").click()
130131
with page.expect_file_chooser() as fc_info:

0 commit comments

Comments
 (0)