Bug 1533043 - [chooser] Add a test for |mach try chooser|, r=gbrown
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 12 Mar 2019 13:49:25 +0000
changeset 521878 e6c8edad26bf
parent 521877 8a144ea41396
child 521879 59cde22537a4
push id10870
push usernbeleuzu@mozilla.com
push dateFri, 15 Mar 2019 20:00:07 +0000
treeherdermozilla-beta@c594aee5b7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgbrown
bugs1533043
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1533043 - [chooser] Add a test for |mach try chooser|, r=gbrown Depends on D22785 Differential Revision: https://phabricator.services.mozilla.com/D22788
tools/tryselect/selectors/chooser/app.py
tools/tryselect/test/conftest.py
tools/tryselect/test/python.ini
tools/tryselect/test/test_chooser.py
--- a/tools/tryselect/selectors/chooser/app.py
+++ b/tools/tryselect/selectors/chooser/app.py
@@ -179,12 +179,13 @@ def create_application(tg):
         if request.method == 'GET':
             return render_template('chooser.html', **context)
 
         if request.form['action'] == 'Push':
             labels = request.form['selected-tasks'].splitlines()
             app.tasks.extend(labels)
 
         shutdown = request.environ.get('werkzeug.server.shutdown')
-        shutdown()
+        if shutdown:
+            shutdown()
         return render_template('close.html')
 
     return app
--- a/tools/tryselect/test/conftest.py
+++ b/tools/tryselect/test/conftest.py
@@ -5,21 +5,38 @@
 from __future__ import absolute_import, print_function, unicode_literals
 
 import os
 
 import pytest
 import yaml
 from mock import MagicMock
 from moztest.resolve import TestResolver
+from taskgraph.graph import Graph
+from taskgraph.task import Task
+from taskgraph.taskgraph import TaskGraph
 
 from tryselect import push
 
 
 @pytest.fixture
+def tg(request):
+    if not hasattr(request.module, 'TASKS'):
+        pytest.fail("'tg' fixture used from a module that didn't define the TASKS variable")
+
+    tasks = request.module.TASKS
+    for task in tasks:
+        task.setdefault('task', {})
+        task['task'].setdefault('tags', {})
+
+    tasks = {t['label']: Task(**t) for t in tasks}
+    return TaskGraph(tasks, Graph(tasks.keys(), set()))
+
+
+@pytest.fixture
 def patch_resolver(monkeypatch):
     def inner(suites, tests):
         def fake_test_metadata(*args, **kwargs):
             return suites, tests
         monkeypatch.setattr(TestResolver, 'resolve_metadata', fake_test_metadata)
     return inner
 
 
--- a/tools/tryselect/test/python.ini
+++ b/tools/tryselect/test/python.ini
@@ -1,9 +1,11 @@
 [DEFAULT]
 subsuite=try
 skip-if = python == 3
 
 [test_again.py]
+[test_chooser.py]
+requirements = tools/tryselect/selectors/chooser/requirements.txt
 [test_fuzzy.py]
 [test_presets.py]
 [test_tasks.py]
 [test_templates.py]
new file mode 100644
--- /dev/null
+++ b/tools/tryselect/test/test_chooser.py
@@ -0,0 +1,79 @@
+# 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/.
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+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-mochitest-e10s',
+        'attributes': {
+            'unittest_suite': 'mochitest',
+            'unittest_flavor': 'browser-chrome',
+            'mochitest_try_name': 'mochitest',
+        },
+    },
+]
+
+
+@pytest.fixture
+def app(tg):
+    app = create_application(tg)
+    app.config['TESTING'] = True
+
+    ctx = app.app_context()
+    ctx.push()
+    yield app
+    ctx.pop()
+
+
+def test_try_chooser(app):
+    client = app.test_client()
+
+    response = client.get('/')
+    assert response.status_code == 200
+
+    expected_output = [
+        """<title>Try Chooser Enhanced</title>""",
+        """<input class="filter" type="checkbox" id=windows name="build" value='{"build_platform": ["windows"]}' onchange="console.log('checkbox onchange triggered');apply();">""",  # noqa
+        """<input class="filter" type="checkbox" id=mochitest-browser-chrome name="test" value='{"unittest_flavor": ["browser-chrome"], "unittest_suite": ["mochitest"]}' 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 "You may now close this page" in response.data
+    assert app.tasks == []
+
+    response = client.post('/', data={'action': 'Push', 'selected-tasks': ''})
+    assert response.status_code == 200
+    assert "You may now close this page" in response.data
+    assert app.tasks == []
+
+    response = client.post('/', data={
+        'action': 'Push',
+        'selected-tasks': 'build-windows\ntest-windows-mochitest-e10s'
+    })
+    assert response.status_code == 200
+    assert "You may now close this page" in response.data
+    assert set(app.tasks) == set(['build-windows', 'test-windows-mochitest-e10s'])
+
+
+if __name__ == '__main__':
+    mozunit.main()