← Back to team overview

launchpad-dev team mailing list archive

Gone - hard coded url port for running tests

 

Hi

As part of the effort towards full support for running parallel tests, a
branch to remove the hard coded url port (8085) for the various test
urls (eg http://launchpad.dev:8085) has been merged. You need to be
aware of the implications of the change when writing your tests. The
main issue: the correct port number is now set during the test setUp()
and is not available before then.

So here's the main viewing highlights. I've added some material to the
wiki:
http://dev.launchpad.net/TestsStyleGuide

Please let me know if there are any questions.

There's a new appserver_root_url() API call.

def appserver_root_url(self, facet='mainsite', ensureSlash=False):
"""Return the correct app server root url for the given facet."""

This is defined on the CanonicalConfig instance and as a convenience is
available as a class method on BaseLayer.

As a concrete example of how things needed to be refactored beyond
simply using the appserver_root_url() API, code like the following:

**************************************************
class CodeWindmillLayer(BaseWindmillLayer):
    """Layer for Code Windmill tests."""

    base_url = 'http://code.launchpad.dev:8085/'
**************************************************

is no longer kosher because the initialisation of the base_url must be
refactored to be done during the test setup().

Here's the main use cases you would be likely to encounter:

1. Doc tests

Old:

    >>> browser.open('http://launchpad.dev:8085/')

New:

    >>> from canonical.testing.layers import BaseLayer
    >>> root_url = BaseLayer.appserver_root_url()
    >>> browser.open(rool_url)

2. Unit tests

Old:

    def aTest(self):
        <snip>
        browser.open('http://launchpad.dev:8085/+login')

New:

    def aTest(self):
        <snip>
        browser.open('%s/+login' % self.layer.appserver_root_url())

3. Windmill tests

Old:

class BugsWindmillLayer(BaseWindmillLayer):
    """Layer for Bugs Windmill tests."""

    base_url = 'http://code.launchpad.dev:8085/'

New:

class BugsWindmillLayer(BaseWindmillLayer):
    """Layer for Bugs Windmill tests."""

    @classmethod
    def setUp(cls):
        cls.base_url = cls.appserver_root_url('bugs')
        super(BugsWindmillLayer, cls).setUp()

Old:

    def test_bug_commenting(self):
        """Test commenting on bugs."""
        client = self.client
        lpuser.NO_PRIV.ensure_login(client)

        client.open(url='http://bugs.launchpad.dev:8085/bugs/1')
New:

    def test_bug_commenting(self):
        """Test commenting on bugs."""
        client = self.client
        lpuser.NO_PRIV.ensure_login(client)

        client.open(url='%s/bugs/1' % BugsWindmillLayer.base_url)



Follow ups