1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import multiprocessing
import mozunit
import pytest
from tryselect.selectors.chooser.app import create_application
TASKS = [
{
"kind": "build",
"label": "build-windows",
"attributes": {
"build_platform": "windows",
},
},
{
"kind": "test",
"label": "test-windows-xpcshell-e10s",
"attributes": {
"unittest_suite": "xpcshell",
},
},
{
"kind": "mochitest",
"label": "test-windows-mochitest-e10s",
"attributes": {
"unittest_suite": "mochitest-browser-chrome",
"mochitest_try_name": "mochitest-browser-chrome",
},
},
]
@pytest.fixture
def queue():
return multiprocessing.Queue()
@pytest.fixture
def app(tg, queue):
app = create_application(tg, queue)
app.config["TESTING"] = True
ctx = app.app_context()
ctx.push()
yield app
ctx.pop()
def test_try_chooser(app, queue: multiprocessing.Queue):
client = app.test_client()
response = client.get("/")
assert response.status_code == 200
expected_output = [
b"""<title>Try Chooser Enhanced</title>""",
b"""<input class="filter" type="checkbox" id=windows name="build" value='{"build_platform": ["windows"]}' onchange="console.log('checkbox onchange triggered');apply();">""", # noqa
b"""<input class="filter" type="checkbox" id=mochitest-browser-chrome name="test,mochitest,reftest,browsertime,web-platform-tests" value='{"unittest_suite": ["mochitest-browser-chrome"]}' onchange="console.log('checkbox onchange triggered');apply();">""", # noqa
b"""<input class="filter" type="checkbox" id=xpcshell name="test,mochitest,reftest,browsertime,web-platform-tests" value='{"unittest_suite": ["xpcshell"]}' onchange="console.log('checkbox onchange triggered');apply();">""", # noqa
]
for expected in expected_output:
assert expected in response.data
response = client.post("/", data={"action": "Cancel"})
assert response.status_code == 200
assert b"You may now close this page" in response.data
assert queue.get() == []
response = client.post("/", data={"action": "Push", "selected-tasks": ""})
assert response.status_code == 200
assert b"You may now close this page" in response.data
assert queue.get() == []
response = client.post(
"/",
data={
"action": "Push",
"selected-tasks": "build-windows\ntest-windows-mochitest-e10s",
},
)
assert response.status_code == 200
assert b"You may now close this page" in response.data
assert set(queue.get()) == set(["build-windows", "test-windows-mochitest-e10s"])
if __name__ == "__main__":
mozunit.main()
|