diff options
author | drebs <drebs@leap.se> | 2017-01-27 20:30:02 -0200 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2017-02-09 17:41:54 +0100 |
commit | 53b5a6788ad8416f78b24cc9880d02da73c52d70 (patch) | |
tree | 7fe973bbaa783abbaa8cf2dde9d6b777e2f56cc1 /testing/tests/server/test__resource.py | |
parent | 1f1a9847117d23a767e99fe80484baf232375d36 (diff) |
[refacor] make proper use of twisted web dyamic resources in server
Diffstat (limited to 'testing/tests/server/test__resource.py')
-rw-r--r-- | testing/tests/server/test__resource.py | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/testing/tests/server/test__resource.py b/testing/tests/server/test__resource.py index 2a387416..30ef782d 100644 --- a/testing/tests/server/test__resource.py +++ b/testing/tests/server/test__resource.py @@ -19,8 +19,8 @@ Tests for Soledad server main resource. """ from twisted.trial import unittest from twisted.web.test.test_web import DummyRequest -from twisted.web.error import Error from twisted.web.wsgi import WSGIResource +from twisted.web.resource import getChildForRequest from twisted.internet import reactor from leap.soledad.server._resource import SoledadResource @@ -37,33 +37,30 @@ class SoledadResourceTestCase(unittest.TestCase): def test_get_root(self): conf = {'soledad-server': {'blobs': None}} # doesn't matter resource = SoledadResource(conf, sync_pool=_pool) - path = '' - request = DummyRequest([]) - child = resource.getChild(path, request) + request = DummyRequest(['']) + child = getChildForRequest(resource, request) self.assertIsInstance(child, ServerInfo) def test_get_blobs_enabled(self): conf = {'soledad-server': {'blobs': True}} resource = SoledadResource(conf, sync_pool=_pool) - path = 'blobs' - request = DummyRequest([]) - child = resource.getChild(path, request) + request = DummyRequest(['blobs']) + child = getChildForRequest(resource, request) self.assertIsInstance(child, BlobsResource) def test_get_blobs_disabled(self): conf = {'soledad-server': {'blobs': False}} resource = SoledadResource(conf, sync_pool=_pool) - path = 'blobs' - request = DummyRequest([]) - with self.assertRaises(Error): - resource.getChild(path, request) + request = DummyRequest(['blobs']) + child = getChildForRequest(resource, request) + # if blobs is disabled, the request should be routed to sync + self.assertIsInstance(child, WSGIResource) + self.assertIsInstance(child._application, GzipMiddleware) def test_get_sync(self): conf = {'soledad-server': {'blobs': None}} # doesn't matter resource = SoledadResource(conf, sync_pool=_pool) - path = 'sync' # if not 'blobs' or '', should be routed to sync - request = DummyRequest([]) - request.prepath = ['user-db'] - child = resource.getChild(path, request) + request = DummyRequest(['user-db', 'sync-from', 'source-id']) + child = getChildForRequest(resource, request) self.assertIsInstance(child, WSGIResource) self.assertIsInstance(child._application, GzipMiddleware) |