Rev 10: Apache2 succesfully plugged in the test suite. in file:///v/home/vila/.bazaar/plugins/local_test_server/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu May 29 21:21:59 BST 2008
At file:///v/home/vila/.bazaar/plugins/local_test_server/
------------------------------------------------------------
revno: 10
revision-id: v.ladeuil+lp at free.fr-20080529202158-syvj27z6fizqn1tw
parent: v.ladeuil+lp at free.fr-20080529073538-rxew7godtq2dau49
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: local_test_server
timestamp: Thu 2008-05-29 22:21:58 +0200
message:
Apache2 succesfully plugged in the test suite.
* tests/test_config.py:
(TestBaseConfig.test_expand_keywords): Add www_dir.
* server.py:
(Apache2HTTPServer): New class interfacing the real server.
(get_test_permutations): First server plugged for one transport.
* configs/apache2.conf:
Activate directory listing and declare the directory containing
the files to be served.
(DocumentRoot): Added.
* __init__.py:
Register a transport to open the door for the test server injection.
modified:
TODO todo-20080526134120-eibvvebw74t8j2xh-1
__init__.py __init__.py-20080521133755-h9wimitytocyyxyv-1
config.py __init__.py-20080523170713-0c8mnxio9r41iyhk-1
configs/apache2.conf apache2.conf-20080522095851-6eixwo2qv9brec67-1
server.py server.py-20080524160639-rqhbexqatjqbwypw-1
tests/test_config.py test_config.py-20080523170715-clr6vz0qdzefftob-1
-------------- next part --------------
=== modified file 'TODO'
--- a/TODO 2008-05-29 07:35:38 +0000
+++ b/TODO 2008-05-29 20:21:58 +0000
@@ -1,3 +1,25 @@
* server.py
+** protect against double start or double stop
+
+** write tests for setUp and tearDown
+
+* config.py
+
+** give better error messages for wrongly written config files
+ (in expand, apache itself gives meaningul lines numbers)
+
+
* plug the server if the corresponding feature is available.
+
+* add support for
+
+** cherokee
+
+** lighttpd
+
+** webdav (for all supporting servers, preferably by using
+ dedicated servers)
+
+** https (for all supporting servers, preferably by using
+ dedicated servers)
=== modified file '__init__.py'
--- a/__init__.py 2008-05-26 19:42:08 +0000
+++ b/__init__.py 2008-05-29 20:21:58 +0000
@@ -66,7 +66,7 @@
"""
from bzrlib import (
- osutils,
+ transport,
)
from bzrlib.plugins.local_test_server import commands
@@ -84,3 +84,11 @@
["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
return basic_tests
+
+# Fake registering a transport so that we can define a get_test_pernutations
+# function (see server.py)
+transport.register_lazy_transport('http://',
+ 'bzrlib.plugins.local_test_server.server',
+ 'HttpTransport_urllib')
+
+
=== modified file 'config.py'
--- a/config.py 2008-05-28 19:10:59 +0000
+++ b/config.py 2008-05-29 20:21:58 +0000
@@ -59,7 +59,8 @@
)
# We need at least a place to put the generated configuration file and
# the pidfile.
- self.required_dirs = dict(etc_dir='etc', var_run_dir='var/run')
+ self.required_dirs = dict(etc_dir='etc', var_run_dir='var/run',
+ www_dir='www')
if required_dirs is not None:
self.required_dirs.update(required_dirs)
=== modified file 'configs/apache2.conf'
--- a/configs/apache2.conf 2008-05-28 19:10:59 +0000
+++ b/configs/apache2.conf 2008-05-29 20:21:58 +0000
@@ -44,6 +44,9 @@
KeepAliveTimeout 5
ErrorLog %(var_log_dir)s/error.log
+LogFormat "%%h %%l %%u %%t \"%%r\" %%>s %%b \"%%{Referer}i\" \"%%{User-Agent}i\"" combined
+CustomLog %(var_log_dir)s/access.log combined
+LogLevel debug
ServerName %(host)s
Listen %(port)s
@@ -55,3 +58,13 @@
StartServers 1
MaxClients 5
ThreadsPerChild 5
+
+# Tests will create a symlink named %(www_dir)s pointing to the
+# appropriate location
+DocumentRoot %(www_dir)s
+
+LoadModule dir_module /usr/lib/apache2/modules/mod_dir.so
+LoadModule autoindex_module /usr/lib/apache2/modules/mod_autoindex.so
+
+# the following may help for debug
+ServerSignature On
=== modified file 'server.py'
--- a/server.py 2008-05-29 07:35:38 +0000
+++ b/server.py 2008-05-29 20:21:58 +0000
@@ -25,8 +25,15 @@
from bzrlib import (
errors,
+ osutils,
tests,
+ transport,
)
+from bzrlib.tests import http_server
+from bzrlib.transport.http import (
+ _urllib,
+ _pycurl,
+ )
from bzrlib.plugins.local_test_server import config
@@ -227,6 +234,61 @@
return port
+class Apache2HTTPServer(transport.Server):
+
+ # used to form the url that connects to this server
+ _url_protocol = 'http'
+
+ def __init__(self):
+ super(Apache2HTTPServer, self).__init__()
+ self._server = get_server('apache2')
+ self.host = self._server.get_config_value('host')
+ self.port = self._server.get_config_value('port')
+ self._http_base_url = '%s://%s:%s/' % (self._url_protocol,
+ self.host, self.port)
+ self._home_dir = None
+
+ def setUp(self, backing_transport_server=None):
+ # redirect to the right url
+ # Hard to believe, but the directory to be served is the current one at
+ # setUp time...
+ self._home_dir = os.getcwdu()
+ www_dir = self._server.get_config_value('www_dir')
+ # We create a symlink in the www_dir to point here. But before that we
+ # put aside the directory created to make apache2 happy (it insists for
+ # a real directory even if it is happy to server through a symlink).
+ osutils.rename(www_dir, www_dir + '.orig')
+ os.symlink(self._home_dir, www_dir)
+
+ def tearDown(self):
+ """See bzrlib.transport.Server.tearDown."""
+ # Restore the original directory
+ www_dir = self._server.get_config_value('www_dir')
+ osutils.delete_any(www_dir)
+ osutils.rename(www_dir + '.orig', www_dir)
+
+ def get_url(self):
+ """See bzrlib.transport.Server.get_url."""
+ return self._http_base_url
+
+ def get_bogus_url(self):
+ """See bzrlib.transport.Server.get_bogus_url."""
+ # this is chosen to try to prevent trouble with proxies, weird dns,
+ # etc
+ return self._url_protocol + '://127.0.0.1:1/'
+
+
+class Apache2_urllib(Apache2HTTPServer):
+ """Subclass of HttpServer that gives http+urllib urls.
+
+ This is for use in testing: connections to this server will always go
+ through urllib where possible.
+ """
+
+ # urls returned by this server should require the urllib client impl
+ _url_protocol = 'http+urllib'
+
+
# The test servers provided use a range of unassigned port numbers as described
# in http://www.iana.org/assignments/port-numbers
@@ -235,4 +297,13 @@
def get_server(name):
return _servers.get(name, None)
-
+# We have registered a transport for the purpose of adding new servers in the
+# test permutations. Registering a transport makes our module appears in the
+# list which is queried for a get_test_permutations function.
+
+HttpTransport_urllib = _urllib. HttpTransport_urllib
+
+
+def get_test_permutations():
+ """Return the permutations to be used in testing."""
+ return [(HttpTransport_urllib, Apache2_urllib)]
=== modified file 'tests/test_config.py'
--- a/tests/test_config.py 2008-05-28 19:10:59 +0000
+++ b/tests/test_config.py 2008-05-29 20:21:58 +0000
@@ -79,17 +79,21 @@
my address is %(host)s:%(port)s
my config is generated under %(etc_dir)s
my pid is somewhere below %(var_run_dir)s
+I will serve document under %(www_dir)s
'''
inf = StringIO(content)
outf = StringIO()
conf.expand(inf, outf)
expanded = outf.getvalue()
+ # FIXME: We can use more precise values now.
self.assertContainsRe(expanded, 'my name is foo\n')
self.assertContainsRe(expanded, 'my address is example.com:0\n')
self.assertContainsRe(
expanded, 'my config is generated under .*/etc\n')
self.assertContainsRe(
expanded, 'my pid is somewhere below .*/var/run\n')
+ self.assertContainsRe(
+ expanded, 'I will serve document under .*/www\n')
class TestConfigApache2(TestConfig):
More information about the bazaar-commits
mailing list