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
1=== modified file 'debian/control'
2--- debian/control 2014-05-26 12:56:47 +0000
3+++ debian/control 2014-07-22 13:09:58 +0000
4@@ -16,8 +16,11 @@
5 libgtest-dev,
6 libsqlite3-dev,
7 libubuntu-app-launch2-dev (>= 0.3),
8- python,
9+ python3,
10 python3-dbusmock,
11+ python3-fixtures,
12+ python3-nose,
13+ python3-testtools,
14 sqlite3,
15 Standards-Version: 3.9.4
16 Homepage: http://launchpad.net/url-dispatcher
17@@ -83,3 +86,10 @@
18 starting them inside its own Application Confinement.
19 .
20 This package contains files that are needed to build applications.
21+
22+Package: url-dispatcher-testability
23+Architecture: all
24+Depends: ${misc:Depends},
25+ python3-dbusmock,
26+ python3-dbus,
27+Description: A fake URL dispatcher for use in testing.
28
29=== modified file 'debian/rules'
30--- debian/rules 2014-06-06 16:06:24 +0000
31+++ debian/rules 2014-07-22 13:09:58 +0000
32@@ -12,4 +12,3 @@
33 mkdir -p debian/url-dispatcher/etc/apport/crashdb.conf.d/
34 install -m 644 debian/url-dispatcher-crashdb.conf debian/url-dispatcher/etc/apport/crashdb.conf.d/
35 dh_install --fail-missing
36-
37
38=== added file 'debian/url-dispatcher-testability.install'
39--- debian/url-dispatcher-testability.install 1970-01-01 00:00:00 +0000
40+++ debian/url-dispatcher-testability.install 2014-07-22 13:09:58 +0000
41@@ -0,0 +1,1 @@
42+/usr/lib/python*/dist-packages/url_dispatcher_testability/*
43
44=== modified file 'tests/CMakeLists.txt'
45--- tests/CMakeLists.txt 2014-05-26 13:09:00 +0000
46+++ tests/CMakeLists.txt 2014-07-22 13:09:58 +0000
47@@ -131,4 +131,4 @@
48 ${GTEST_LIBS})
49
50 add_test (url-db-test url-db-test)
51-
52+add_subdirectory(url_dispatcher_testability)
53
54=== added directory 'tests/url_dispatcher_testability'
55=== added file 'tests/url_dispatcher_testability/CMakeLists.txt'
56--- tests/url_dispatcher_testability/CMakeLists.txt 1970-01-01 00:00:00 +0000
57+++ tests/url_dispatcher_testability/CMakeLists.txt 2014-07-22 13:09:58 +0000
58@@ -0,0 +1,13 @@
59+execute_process(COMMAND python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
60+ OUTPUT_VARIABLE PYTHON_PACKAGE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
61+
62+install(FILES fixture_setup.py fake_dispatcher.py test_fake_dispatcher.py
63+ DESTINATION ${PYTHON_PACKAGE_DIR}/url_dispatcher_testability
64+)
65+
66+configure_file(
67+ "${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py.in"
68+ "${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py"
69+ )
70+
71+add_test(fake-dispatcher dbus-launch --exit-with-session nosetests3 ${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py)
72
73=== added file 'tests/url_dispatcher_testability/__init__.py'
74=== added file 'tests/url_dispatcher_testability/fake_dispatcher.py'
75--- tests/url_dispatcher_testability/fake_dispatcher.py 1970-01-01 00:00:00 +0000
76+++ tests/url_dispatcher_testability/fake_dispatcher.py 2014-07-22 13:09:58 +0000
77@@ -0,0 +1,67 @@
78+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
79+#
80+# Copyright (C) 2014 Canonical Ltd.
81+#
82+# This program is free software; you can redistribute it and/or modify
83+# it under the terms of the GNU Lesser General Public License as published by
84+# the Free Software Foundation; version 3.
85+#
86+# This program is distributed in the hope that it will be useful,
87+# but WITHOUT ANY WARRANTY; without even the implied warranty of
88+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89+# GNU Lesser General Public License for more details.
90+#
91+# You should have received a copy of the GNU Lesser General Public License
92+# along with this program. If not, see <http://www.gnu.org/licenses/>.
93+
94+import dbus
95+import dbusmock
96+import subprocess
97+
98+
99+class FakeDispatcherException(Exception):
100+ pass
101+
102+
103+class FakeURLDispatcherService:
104+
105+ """Fake URL Dispatcher service using a dbusmock interface."""
106+
107+ def __init__(self):
108+ super(FakeURLDispatcherService, self).__init__()
109+ self.dbus_connection = dbusmock.DBusTestCase.get_dbus(system_bus=False)
110+
111+ def start(self):
112+ """Start the fake URL Dispatcher service."""
113+ # Stop the real url-dispatcher.
114+ subprocess.call(['initctl', 'stop', 'url-dispatcher'])
115+ self.dbus_mock_server = dbusmock.DBusTestCase.spawn_server(
116+ 'com.canonical.URLDispatcher',
117+ '/com/canonical/URLDispatcher',
118+ 'com.canonical.URLDispatcher',
119+ system_bus=False,
120+ stdout=subprocess.PIPE)
121+ self.mock = self._get_mock_interface()
122+ self.mock.AddMethod(
123+ 'com.canonical.URLDispatcher', 'DispatchURL', 'ss', '', '')
124+
125+ def _get_mock_interface(self):
126+ return dbus.Interface(
127+ self.dbus_connection.get_object(
128+ 'com.canonical.URLDispatcher',
129+ '/com/canonical/URLDispatcher'),
130+ dbusmock.MOCK_IFACE)
131+
132+ def stop(self):
133+ """Stop the fake URL Dispatcher service."""
134+ self.dbus_mock_server.terminate()
135+ self.dbus_mock_server.wait()
136+
137+ def get_last_dispatch_url_call_parameter(self):
138+ """Return the parameter used in the last call to dispatch URL."""
139+ calls = self.mock.GetCalls()
140+ if len(calls) == 0:
141+ raise FakeDispatcherException(
142+ 'URL dispatcher has not been called.')
143+ last_call = self.mock.GetCalls()[-1]
144+ return last_call[2][0]
145
146=== added file 'tests/url_dispatcher_testability/fixture_setup.py'
147--- tests/url_dispatcher_testability/fixture_setup.py 1970-01-01 00:00:00 +0000
148+++ tests/url_dispatcher_testability/fixture_setup.py 2014-07-22 13:09:58 +0000
149@@ -0,0 +1,30 @@
150+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
151+#
152+# Copyright (C) 2014 Canonical Ltd.
153+#
154+# This program is free software; you can redistribute it and/or modify
155+# it under the terms of the GNU Lesser General Public License as published by
156+# the Free Software Foundation; version 3.
157+#
158+# This program is distributed in the hope that it will be useful,
159+# but WITHOUT ANY WARRANTY; without even the implied warranty of
160+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
161+# GNU Lesser General Public License for more details.
162+#
163+# You should have received a copy of the GNU Lesser General Public License
164+# along with this program. If not, see <http://www.gnu.org/licenses/>.
165+
166+import fixtures
167+from url_dispatcher_testability import fake_dispatcher
168+
169+
170+class FakeURLDispatcher(fixtures.Fixture):
171+
172+ def setUp(self):
173+ super(FakeURLDispatcher, self).setUp()
174+ self.fake_service = fake_dispatcher.FakeURLDispatcherService()
175+ self.addCleanup(self.fake_service.stop)
176+ self.fake_service.start()
177+
178+ def get_last_dispatch_url_call_parameter(self):
179+ return self.fake_service.get_last_dispatch_url_call_parameter()
180
181=== added file 'tests/url_dispatcher_testability/test_fake_dispatcher.py.in'
182--- tests/url_dispatcher_testability/test_fake_dispatcher.py.in 1970-01-01 00:00:00 +0000
183+++ tests/url_dispatcher_testability/test_fake_dispatcher.py.in 2014-07-22 13:09:58 +0000
184@@ -0,0 +1,37 @@
185+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
186+#
187+# Copyright (C) 2014 Canonical Ltd.
188+#
189+# This program is free software; you can redistribute it and/or modify
190+# it under the terms of the GNU Lesser General Public License as published by
191+# the Free Software Foundation; version 3.
192+#
193+# This program is distributed in the hope that it will be useful,
194+# but WITHOUT ANY WARRANTY; without even the implied warranty of
195+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
196+# GNU Lesser General Public License for more details.
197+#
198+# You should have received a copy of the GNU Lesser General Public License
199+# along with this program. If not, see <http://www.gnu.org/licenses/>.
200+
201+import testtools
202+from url_dispatcher_testability import fixture_setup, fake_dispatcher
203+
204+from subprocess import call, CalledProcessError
205+
206+
207+class FakeDispatcherTestCase(testtools.TestCase):
208+
209+ def setUp(self):
210+ super(FakeDispatcherTestCase, self).setUp()
211+ self.dispatcher = fixture_setup.FakeURLDispatcher()
212+ self.useFixture(self.dispatcher)
213+
214+ def test_url_dispatcher(self):
215+ bin_dir = "@PROJECT_BINARY_DIR@"
216+ call([bin_dir + '/tools/url-dispatcher', 'test://testurl'])
217+ try:
218+ last_url = self.dispatcher.get_last_dispatch_url_call_parameter()
219+ except fake_dispatcher.FakeDispatcherException:
220+ last_url = None
221+ self.assertEqual(last_url, 'test://testurl')

Subscribers

People subscribed via source and target branches