provide simple test for processing request using folder structure
This commit is contained in:
		
							parent
							
								
									3d10c45222
								
							
						
					
					
						commit
						a16c1dd469
					
				
					 5 changed files with 34 additions and 3 deletions
				
			
		|  | @ -1,11 +1,9 @@ | |||
| # scopes.server.app | ||||
| 
 | ||||
| import json | ||||
| from zope.publisher.base import DefaultPublication | ||||
| from zope.publisher.browser import BrowserRequest | ||||
| from zope.publisher.interfaces import NotFound | ||||
| from zope.publisher.publish import publish | ||||
| from zope.traversing.publicationtraverse import PublicationTraverser | ||||
| 
 | ||||
| from scopes.interfaces import ITraversable, IView | ||||
| from scopes.server.browser import getView | ||||
|  |  | |||
|  | @ -27,6 +27,7 @@ def getView(request, ob, name): | |||
| 
 | ||||
| 
 | ||||
| @register(None, 'index.html') | ||||
| @register(None, 'index.json') | ||||
| @implementer(IView) | ||||
| class DefaultView: | ||||
| 
 | ||||
|  | @ -39,5 +40,6 @@ class DefaultView: | |||
|         result = dict(head=ob.head, data=ob.data) | ||||
|         if IContainer.providedBy(ob): | ||||
|             result['items'] = list(ob.keys()) | ||||
|         print('***', result) | ||||
|         return json.dumps(result) | ||||
| 
 | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ | |||
| """Tests for the 'scopes.storage' package.""" | ||||
| 
 | ||||
| import unittest | ||||
| import tlib_storage | ||||
| import tlib_server, tlib_storage | ||||
| 
 | ||||
| from scopes.storage.common import StorageFactory | ||||
| import config | ||||
|  | @ -21,6 +21,10 @@ class Test(unittest.TestCase): | |||
|     def test_002_folder(self): | ||||
|         tlib_storage.test_folder(self, config) | ||||
| 
 | ||||
|     def test_003_server(self): | ||||
|         tlib_server.test_app(self, config) | ||||
| 
 | ||||
| 
 | ||||
| def suite(): | ||||
|     return unittest.TestSuite(( | ||||
|         unittest.TestLoader().loadTestsFromTestCase(Test), | ||||
|  |  | |||
							
								
								
									
										26
									
								
								tests/tlib_server.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								tests/tlib_server.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| # tests/tlib_server.py | ||||
| 
 | ||||
| """Test implementation for the `scopes.server` package.""" | ||||
| 
 | ||||
| import json | ||||
| from zope.publisher.browser import TestRequest | ||||
| from zope.publisher.publish import publish | ||||
| 
 | ||||
| from scopes.server.app import Publication | ||||
| from scopes.storage.folder import Root | ||||
| 
 | ||||
| 
 | ||||
| def publishRequest(config, storage, path): | ||||
|     appRoot = Root(storage, config) | ||||
|     request = TestRequest(environ=dict(PATH_INFO=path)) | ||||
|     request.setPublication(Publication(appRoot)) | ||||
|     request = publish(request, False) | ||||
|     return request.response | ||||
| 
 | ||||
| 
 | ||||
| def test_app(self, config): | ||||
|     storage = config.storageFactory(config.dbschema) | ||||
|     response = publishRequest(config, storage, '/top') | ||||
|     result = json.loads(response.consumeBody()) | ||||
|     self.assertEqual(result['items'], ['child1']) | ||||
| 
 | ||||
|  | @ -1,4 +1,5 @@ | |||
| # tests/tlib_storage.py | ||||
| 
 | ||||
| """Test implementation for the `scopes.storage` package.""" | ||||
| 
 | ||||
| from datetime import datetime | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue