From da26a7f22c6ea77bc417d1184c2a0a4f976669a2 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Tue, 29 Aug 2017 17:05:02 -0300 Subject: [style] improve naming and fixes from code review -- Related: #8867 --- testing/tests/conftest.py | 2 +- testing/tests/server/test__resource.py | 15 ++++++++------- testing/tests/server/test_auth.py | 6 +++--- testing/tests/server/test_tac.py | 7 ++++--- 4 files changed, 16 insertions(+), 14 deletions(-) (limited to 'testing') diff --git a/testing/tests/conftest.py b/testing/tests/conftest.py index 817a43b0..87742dfe 100644 --- a/testing/tests/conftest.py +++ b/testing/tests/conftest.py @@ -126,7 +126,7 @@ class SoledadServer(object): '--logfile=%s' % self._logfile, '--pidfile=%s' % self._pidfile, 'web', - '--class=leap.soledad.server.entrypoint.SoledadEntrypoint', + '--class=leap.soledad.server.entrypoints.SoledadEntrypoint', '--port=tcp:2424' ]) diff --git a/testing/tests/server/test__resource.py b/testing/tests/server/test__resource.py index f5331e35..a43ac19f 100644 --- a/testing/tests/server/test__resource.py +++ b/testing/tests/server/test__resource.py @@ -23,7 +23,7 @@ from twisted.web.wsgi import WSGIResource from twisted.web.resource import getChildForRequest from twisted.internet import reactor -from leap.soledad.server._resource import SoledadResource +from leap.soledad.server._resource import PublicResource from leap.soledad.server._resource import LocalResource from leap.soledad.server._server_info import ServerInfo from leap.soledad.server._blobs import BlobsResource @@ -34,11 +34,11 @@ from leap.soledad.server.gzip_middleware import GzipMiddleware _pool = reactor.getThreadPool() -class SoledadResourceTestCase(unittest.TestCase): +class PublicResourceTestCase(unittest.TestCase): def test_get_root(self): blobs_resource = None # doesn't matter - resource = SoledadResource( + resource = PublicResource( blobs_resource=blobs_resource, sync_pool=_pool) request = DummyRequest(['']) child = getChildForRequest(resource, request) @@ -46,7 +46,7 @@ class SoledadResourceTestCase(unittest.TestCase): def test_get_blobs_enabled(self): blobs_resource = BlobsResource("filesystem", '/tmp') - resource = SoledadResource( + resource = PublicResource( blobs_resource=blobs_resource, sync_pool=_pool) request = DummyRequest(['blobs']) child = getChildForRequest(resource, request) @@ -54,7 +54,7 @@ class SoledadResourceTestCase(unittest.TestCase): def test_get_blobs_disabled(self): blobs_resource = None - resource = SoledadResource( + resource = PublicResource( blobs_resource=blobs_resource, sync_pool=_pool) request = DummyRequest(['blobs']) child = getChildForRequest(resource, request) @@ -64,7 +64,7 @@ class SoledadResourceTestCase(unittest.TestCase): def test_get_sync(self): blobs_resource = None # doesn't matter - resource = SoledadResource( + resource = PublicResource( blobs_resource=blobs_resource, sync_pool=_pool) request = DummyRequest(['user-db', 'sync-from', 'source-id']) child = getChildForRequest(resource, request) @@ -72,9 +72,10 @@ class SoledadResourceTestCase(unittest.TestCase): self.assertIsInstance(child._application, GzipMiddleware) def test_no_incoming_on_public_resource(self): - resource = SoledadResource(None, sync_pool=_pool) + resource = PublicResource(None, sync_pool=_pool) request = DummyRequest(['incoming']) child = getChildForRequest(resource, request) + # WSGIResource is returned if a path is unknown self.assertIsInstance(child, WSGIResource) def test_get_incoming(self): diff --git a/testing/tests/server/test_auth.py b/testing/tests/server/test_auth.py index 85dd5ecf..78cf20ab 100644 --- a/testing/tests/server/test_auth.py +++ b/testing/tests/server/test_auth.py @@ -36,7 +36,7 @@ from leap.soledad.server.auth import SoledadRealm from leap.soledad.server.auth import CouchDBTokenChecker from leap.soledad.server.auth import FileTokenChecker from leap.soledad.server.auth import TokenCredentialFactory -from leap.soledad.server._resource import SoledadResource +from leap.soledad.server._resource import PublicResource class SoledadRealmTestCase(unittest.TestCase): @@ -47,7 +47,7 @@ class SoledadRealmTestCase(unittest.TestCase): pool = reactor.getThreadPool() realm = SoledadRealm(conf=conf, sync_pool=pool) iface, avatar, logout = realm.requestAvatar('any', None, IResource) - self.assertIsInstance(avatar, SoledadResource) + self.assertIsInstance(avatar, PublicResource) self.assertIsNone(logout()) @@ -69,7 +69,7 @@ def dummy_server(token): yield collections.defaultdict(lambda: DummyServer(token)) -class DatabaseTokenCheckerTestCase(unittest.TestCase): +class CouchDBTokenCheckerTestCase(unittest.TestCase): @inlineCallbacks def test_good_creds(self): diff --git a/testing/tests/server/test_tac.py b/testing/tests/server/test_tac.py index e825a9ce..7bb50e35 100644 --- a/testing/tests/server/test_tac.py +++ b/testing/tests/server/test_tac.py @@ -45,7 +45,7 @@ class TacServerTestCase(unittest.TestCase): @defer.inlineCallbacks def test_local_public_default_ports_on_server_tac(self): yield self._spawnServer() - result = yield self._get('http://localhost:2323/incoming') + result = yield self._get('http://localhost:2525/incoming') fail_msg = "Localhost endpoint must require authentication!" self.assertEquals(401, result.code, fail_msg) @@ -56,7 +56,7 @@ class TacServerTestCase(unittest.TestCase): result = yield self._get(public_endpoint_url + 'other') self.assertEquals(401, result.code, "public server lacks auth!") - public_using_local_port_url = 'http://%s:2323/' % self._get_public_ip() + public_using_local_port_url = 'http://%s:2525/' % self._get_public_ip() with pytest.raises(Exception): yield self._get(public_using_local_port_url) @@ -66,7 +66,8 @@ class TacServerTestCase(unittest.TestCase): executable = os.path.join(env, 'bin', 'twistd') no_pid_argument = '--pidfile=' args = [executable, no_pid_argument, '-noy', TAC_FILE_PATH] - t = reactor.spawnProcess(protocol, executable, args) + env = {'DEBUG_SERVER': 'yes'} + t = reactor.spawnProcess(protocol, executable, args, env=env) self.addCleanup(os.kill, t.pid, signal.SIGKILL) self.addCleanup(t.loseConnection) return self._sleep(1) # it takes a while to start server -- cgit v1.2.3