summaryrefslogtreecommitdiff
path: root/common/src
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-08-06 12:54:53 -0300
committerBruno Wagner <bwgpro@gmail.com>2015-08-12 17:17:17 -0300
commit775105a8caee2c796121ca1598530af0422060b6 (patch)
treeabb8bd79a3b76fde0e1a38637085ff9c6c07fa8f /common/src
parent8e9c810396b9b9f968234e3e21396814865ee22c (diff)
[test] Change test server to use Twisted
Soledad was being served with python's default wsgi server, which uses HTTP 1.0. Since Soledad server doesn't send length or chunked headers, Twisted HTTP Client gets partial downloads when served with HTTP1.0. Soledad is meant to be used with Twisted WSGI container on HTTP/1.1 and the tests should reflect that.
Diffstat (limited to 'common/src')
-rw-r--r--common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py4
-rw-r--r--common/src/leap/soledad/common/tests/test_server.py3
-rw-r--r--common/src/leap/soledad/common/tests/u1db_tests/__init__.py25
3 files changed, 20 insertions, 12 deletions
diff --git a/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py b/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py
index 32f676ad..3fe6441b 100644
--- a/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py
+++ b/common/src/leap/soledad/common/tests/test_couch_operations_atomicity.py
@@ -69,7 +69,7 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer):
def _put_doc_side_effect(doc):
self._doc_put = doc
- return Soledad(
+ soledad = Soledad(
user,
passphrase,
secrets_path=os.path.join(self.tempdir, prefix, secrets_path),
@@ -79,6 +79,8 @@ class CouchAtomicityTestCase(CouchDBTestCase, TestCaseWithServer):
cert_file=cert_file,
auth_token=auth_token,
shared_db=self.get_default_shared_mock(_put_doc_side_effect))
+ self.addCleanup(soledad.close)
+ return soledad
def make_app(self):
self.request_state = CouchServerState(self._couch_url)
diff --git a/common/src/leap/soledad/common/tests/test_server.py b/common/src/leap/soledad/common/tests/test_server.py
index 3ed23184..bfb4a225 100644
--- a/common/src/leap/soledad/common/tests/test_server.py
+++ b/common/src/leap/soledad/common/tests/test_server.py
@@ -307,6 +307,9 @@ class EncryptedSyncTestCase(
server = getattr(self, 'server', None)
if server:
server_address = getattr(self.server, 'server_address', None)
+ else:
+ host = self.port.getHost()
+ server_address = (host.host, host.port)
if server_address:
server_url = 'http://%s:%d' % (server_address)
diff --git a/common/src/leap/soledad/common/tests/u1db_tests/__init__.py b/common/src/leap/soledad/common/tests/u1db_tests/__init__.py
index 9efe7ebf..132c45e3 100644
--- a/common/src/leap/soledad/common/tests/u1db_tests/__init__.py
+++ b/common/src/leap/soledad/common/tests/u1db_tests/__init__.py
@@ -36,6 +36,9 @@ from StringIO import StringIO
import testscenarios
from twisted.trial import unittest
+from twisted.web.server import Site
+from twisted.web.wsgi import WSGIResource
+from twisted.internet import reactor
from u1db import (
errors,
@@ -338,32 +341,32 @@ class TestCaseWithServer(TestCase):
def setUp(self):
super(TestCaseWithServer, self).setUp()
- self.server = self.server_thread = None
+ self.server = self.server_thread = self.port = None
def tearDown(self):
if self.server is not None:
self.server.shutdown()
self.server_thread.join()
self.server.server_close()
+ if self.port:
+ self.port.stopListening()
super(TestCaseWithServer, self).tearDown()
@property
def url_scheme(self):
- return self.server_def()[-1]
+ return 'http'
def startServer(self):
- server_def = self.server_def()
- server_class, shutdown_meth, _ = server_def
application = self.make_app()
- self.server = server_class(('127.0.0.1', 0), application)
- self.server_thread = threading.Thread(target=self.server.serve_forever,
- kwargs=dict(poll_interval=0.01))
- self.server_thread.start()
- self.addCleanup(self.server_thread.join)
- self.addCleanup(getattr(self.server, shutdown_meth))
+ resource = WSGIResource(reactor, reactor.getThreadPool(), application)
+ site = Site(resource)
+ self.port = reactor.listenTCP(0, site, interface='127.0.0.1')
+ host = self.port.getHost()
+ self.server_address = (host.host, host.port)
+ self.addCleanup(self.port.stopListening)
def getURL(self, path=None):
- host, port = self.server.server_address
+ host, port = self.server_address
if path is None:
path = ''
return '%s://%s:%s/%s' % (self.url_scheme, host, port, path)