Merge lp:~canonical-platform-qa/url-dispatcher/fake_dispatcher into lp:url-dispatcher/14.10

Proposed by Brendan Donegan
Status: Superseded
Proposed branch: lp:~canonical-platform-qa/url-dispatcher/fake_dispatcher
Merge into: lp:url-dispatcher/14.10
Diff against target: 221 lines (+160/-3)
8 files modified
debian/control (+11/-1)
debian/rules (+0/-1)
debian/url-dispatcher-testability.install (+1/-0)
tests/CMakeLists.txt (+1/-1)
tests/url_dispatcher_testability/CMakeLists.txt (+13/-0)
tests/url_dispatcher_testability/fake_dispatcher.py (+67/-0)
tests/url_dispatcher_testability/fixture_setup.py (+30/-0)
tests/url_dispatcher_testability/test_fake_dispatcher.py.in (+37/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/url-dispatcher/fake_dispatcher
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Ted Gould (community) Needs Fixing
Leo Arias (community) code review Needs Fixing
Ubuntu Core Development Team Pending
Review via email: mp+226829@code.launchpad.net

This proposal has been superseded by a proposal from 2014-07-22.

Commit message

Add url-dispatcher-testability binary package

Description of the change

Create a new url-dispatcher-testability binary package which provides a helper for writing tests which interact with the url dispatcher.

To post a comment you must log in.
Revision history for this message
Leo Arias (elopio) wrote :

165 + call(['url-dispatcher', 'test://testurl'])

In order to run this test you need the package url-dispatcher-tools, so it needs to be part of the dependencies.

review: Needs Fixing (code review)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
62. By Brendan Donegan

Add url-dispatcher-tools to control file

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

This builds and the tests pass now.

Revision history for this message
Ted Gould (ted) wrote :

Some discussion on IRC putting here for tracking:

* The tests need to be run by CTest not by debian/rules
* We shouldn't override autotest here to run it under dbus, that should be in the individual test
* The package shouldn't have a build-dep on a binary it produces

review: Needs Fixing
Revision history for this message
Ted Gould (ted) wrote :

I think that this should use the CMake python module:

http://www.cmake.org/cmake/help/cmake2.6docs.html#module:FindPythonLibs

Instead of exec'ing Python. Also the build dep for python should probably be Python3. Not a change in this MR, but noticing with the addition of all the python modules :-)

63. By Brendan Donegan

Refactor fake dispatcher to split into two modules

64. By Brendan Donegan

CMake changes to get url_dispatcher_testability tested with CMake

Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

> Some discussion on IRC putting here for tracking:
>
> * The tests need to be run by CTest not by debian/rules
> * We shouldn't override autotest here to run it under dbus, that should be in
> the individual test
> * The package shouldn't have a build-dep on a binary it produces

All good points - CMake is proving very difficult to work with at the moment though. I updated the branch with some CMake changes, but they don't result in my python code being copied to build/tests/url_dispatcher_testability as I'd expect.

From reading about FindPythonLibs, I think it's intended as being useful in the case where one wants to create C/C++ extensions for python. I don't think it helps in this situation - all I have is some python modules that I want to test and install.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
65. By Brendan Donegan

CTest works now

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

Using CTest now and the build passes.

Revision history for this message
Ted Gould (ted) wrote :

Looks good. One small thing tough, can you change the interface to be (ss) instead of (s) to match this branch? https://code.launchpad.net/~ted/url-dispatcher/test-url/+merge/226765 That way I can silo them all together

Revision history for this message
Ted Gould (ted) wrote :

tests/url_dispatcher_testability/test_fake_dispatcher.py:

Needs a copyright statement on top of it.

And the call to url-dispatcher command line utility needs to adjust based on the bindir. If you just make it a command line parameter then your test can pass it as the first parameter, that's pretty easy.

66. By Brendan Donegan

Update signature

67. By Brendan Donegan

Add copyright header

Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

As far as I know, no test runner supports command line arguments for tests. Can you explain the motivation by needing to adjust the call? Is it so that it can be run outside the build system as well? Just trying to understand why so I can come up with another solution.

Revision history for this message
Leo Arias (elopio) wrote :

There's an open bug for autopilot to do just that:
https://bugs.launchpad.net/autopilot/+bug/1266589

Currently, we are doing it with env vars.
like: BIN_DIR='../../' autopilot run ...

Revision history for this message
Ted Gould (ted) wrote :

The problem is that you don't know that it's going to be "../../" always. I could do:

cmake . ; make

Or I could do:

mkdir build ; cd build ; cmake .. ; make

Or I could do:

mkdir -p foo/bar/foo/bar ; cd foo/bar/foo/bar ; cmake ../../../.. ; make

The way that is kept track of is the variables in CMake. So when people starting doing things like cross compilation the variables get complex.

I figured command line is easier, but setting an environment variable works as well. Just some something that can get information from the build system as the path to the binaries that isn't hard coded. You can also make the python file a .py.in and have the build system do the substitution.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

The problem is CTest sucks, so I've not been able to figure out either how to set the environment (the setting seems to take effect only during the actual execution of cmake), or set the PATH in the test command - CTest automatically thinks the first word in the add_test line is a command. The .in substitution could work, maybe - but that might depend on getting these files copied into the build directory, which I've had no success with so far.

68. By Brendan Donegan

Use .in file to set bin_dir

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
69. By Leo Arias

Added python3:Depends as suggested by Colin.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2014-05-26 12:56:47 +0000
+++ debian/control 2014-07-22 13:09:58 +0000
@@ -16,8 +16,11 @@
16 libgtest-dev,16 libgtest-dev,
17 libsqlite3-dev,17 libsqlite3-dev,
18 libubuntu-app-launch2-dev (>= 0.3),18 libubuntu-app-launch2-dev (>= 0.3),
19 python,19 python3,
20 python3-dbusmock,20 python3-dbusmock,
21 python3-fixtures,
22 python3-nose,
23 python3-testtools,
21 sqlite3,24 sqlite3,
22Standards-Version: 3.9.425Standards-Version: 3.9.4
23Homepage: http://launchpad.net/url-dispatcher26Homepage: http://launchpad.net/url-dispatcher
@@ -83,3 +86,10 @@
83 starting them inside its own Application Confinement.86 starting them inside its own Application Confinement.
84 .87 .
85 This package contains files that are needed to build applications.88 This package contains files that are needed to build applications.
89
90Package: url-dispatcher-testability
91Architecture: all
92Depends: ${misc:Depends},
93 python3-dbusmock,
94 python3-dbus,
95Description: A fake URL dispatcher for use in testing.
8696
=== modified file 'debian/rules'
--- debian/rules 2014-06-06 16:06:24 +0000
+++ debian/rules 2014-07-22 13:09:58 +0000
@@ -12,4 +12,3 @@
12 mkdir -p debian/url-dispatcher/etc/apport/crashdb.conf.d/12 mkdir -p debian/url-dispatcher/etc/apport/crashdb.conf.d/
13 install -m 644 debian/url-dispatcher-crashdb.conf debian/url-dispatcher/etc/apport/crashdb.conf.d/13 install -m 644 debian/url-dispatcher-crashdb.conf debian/url-dispatcher/etc/apport/crashdb.conf.d/
14 dh_install --fail-missing14 dh_install --fail-missing
15
1615
=== added file 'debian/url-dispatcher-testability.install'
--- debian/url-dispatcher-testability.install 1970-01-01 00:00:00 +0000
+++ debian/url-dispatcher-testability.install 2014-07-22 13:09:58 +0000
@@ -0,0 +1,1 @@
1/usr/lib/python*/dist-packages/url_dispatcher_testability/*
02
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2014-05-26 13:09:00 +0000
+++ tests/CMakeLists.txt 2014-07-22 13:09:58 +0000
@@ -131,4 +131,4 @@
131 ${GTEST_LIBS})131 ${GTEST_LIBS})
132132
133add_test (url-db-test url-db-test)133add_test (url-db-test url-db-test)
134134add_subdirectory(url_dispatcher_testability)
135135
=== added directory 'tests/url_dispatcher_testability'
=== added file 'tests/url_dispatcher_testability/CMakeLists.txt'
--- tests/url_dispatcher_testability/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/url_dispatcher_testability/CMakeLists.txt 2014-07-22 13:09:58 +0000
@@ -0,0 +1,13 @@
1execute_process(COMMAND python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
2 OUTPUT_VARIABLE PYTHON_PACKAGE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
3
4install(FILES fixture_setup.py fake_dispatcher.py test_fake_dispatcher.py
5 DESTINATION ${PYTHON_PACKAGE_DIR}/url_dispatcher_testability
6)
7
8configure_file(
9 "${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py.in"
10 "${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py"
11 )
12
13add_test(fake-dispatcher dbus-launch --exit-with-session nosetests3 ${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py)
014
=== added file 'tests/url_dispatcher_testability/__init__.py'
=== added file 'tests/url_dispatcher_testability/fake_dispatcher.py'
--- tests/url_dispatcher_testability/fake_dispatcher.py 1970-01-01 00:00:00 +0000
+++ tests/url_dispatcher_testability/fake_dispatcher.py 2014-07-22 13:09:58 +0000
@@ -0,0 +1,67 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
3# Copyright (C) 2014 Canonical Ltd.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published by
7# the Free Software Foundation; version 3.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import dbus
18import dbusmock
19import subprocess
20
21
22class FakeDispatcherException(Exception):
23 pass
24
25
26class FakeURLDispatcherService:
27
28 """Fake URL Dispatcher service using a dbusmock interface."""
29
30 def __init__(self):
31 super(FakeURLDispatcherService, self).__init__()
32 self.dbus_connection = dbusmock.DBusTestCase.get_dbus(system_bus=False)
33
34 def start(self):
35 """Start the fake URL Dispatcher service."""
36 # Stop the real url-dispatcher.
37 subprocess.call(['initctl', 'stop', 'url-dispatcher'])
38 self.dbus_mock_server = dbusmock.DBusTestCase.spawn_server(
39 'com.canonical.URLDispatcher',
40 '/com/canonical/URLDispatcher',
41 'com.canonical.URLDispatcher',
42 system_bus=False,
43 stdout=subprocess.PIPE)
44 self.mock = self._get_mock_interface()
45 self.mock.AddMethod(
46 'com.canonical.URLDispatcher', 'DispatchURL', 'ss', '', '')
47
48 def _get_mock_interface(self):
49 return dbus.Interface(
50 self.dbus_connection.get_object(
51 'com.canonical.URLDispatcher',
52 '/com/canonical/URLDispatcher'),
53 dbusmock.MOCK_IFACE)
54
55 def stop(self):
56 """Stop the fake URL Dispatcher service."""
57 self.dbus_mock_server.terminate()
58 self.dbus_mock_server.wait()
59
60 def get_last_dispatch_url_call_parameter(self):
61 """Return the parameter used in the last call to dispatch URL."""
62 calls = self.mock.GetCalls()
63 if len(calls) == 0:
64 raise FakeDispatcherException(
65 'URL dispatcher has not been called.')
66 last_call = self.mock.GetCalls()[-1]
67 return last_call[2][0]
068
=== added file 'tests/url_dispatcher_testability/fixture_setup.py'
--- tests/url_dispatcher_testability/fixture_setup.py 1970-01-01 00:00:00 +0000
+++ tests/url_dispatcher_testability/fixture_setup.py 2014-07-22 13:09:58 +0000
@@ -0,0 +1,30 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
3# Copyright (C) 2014 Canonical Ltd.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published by
7# the Free Software Foundation; version 3.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import fixtures
18from url_dispatcher_testability import fake_dispatcher
19
20
21class FakeURLDispatcher(fixtures.Fixture):
22
23 def setUp(self):
24 super(FakeURLDispatcher, self).setUp()
25 self.fake_service = fake_dispatcher.FakeURLDispatcherService()
26 self.addCleanup(self.fake_service.stop)
27 self.fake_service.start()
28
29 def get_last_dispatch_url_call_parameter(self):
30 return self.fake_service.get_last_dispatch_url_call_parameter()
031
=== added file 'tests/url_dispatcher_testability/test_fake_dispatcher.py.in'
--- tests/url_dispatcher_testability/test_fake_dispatcher.py.in 1970-01-01 00:00:00 +0000
+++ tests/url_dispatcher_testability/test_fake_dispatcher.py.in 2014-07-22 13:09:58 +0000
@@ -0,0 +1,37 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2#
3# Copyright (C) 2014 Canonical Ltd.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as published by
7# the Free Software Foundation; version 3.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Lesser General Public License for more details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17import testtools
18from url_dispatcher_testability import fixture_setup, fake_dispatcher
19
20from subprocess import call, CalledProcessError
21
22
23class FakeDispatcherTestCase(testtools.TestCase):
24
25 def setUp(self):
26 super(FakeDispatcherTestCase, self).setUp()
27 self.dispatcher = fixture_setup.FakeURLDispatcher()
28 self.useFixture(self.dispatcher)
29
30 def test_url_dispatcher(self):
31 bin_dir = "@PROJECT_BINARY_DIR@"
32 call([bin_dir + '/tools/url-dispatcher', 'test://testurl'])
33 try:
34 last_url = self.dispatcher.get_last_dispatch_url_call_parameter()
35 except fake_dispatcher.FakeDispatcherException:
36 last_url = None
37 self.assertEqual(last_url, 'test://testurl')

Subscribers

People subscribed via source and target branches