49 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| # tests/tlib_web.py
 | |
| 
 | |
| """Test implementation for the `scopes.web` package."""
 | |
| 
 | |
| import json
 | |
| import logging
 | |
| from zope.publisher.browser import TestRequest
 | |
| from zope.publisher.publish import publish
 | |
| 
 | |
| from scopes.web.app import Publication
 | |
| from scopes.storage.folder import Root
 | |
| 
 | |
| logger = logging.getLogger('tlib_web')
 | |
| 
 | |
| 
 | |
| def publishRequest(config, storage, path):
 | |
|     appRoot = Root(storage)
 | |
|     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')
 | |
|     logger.info('test_app: response %s %s', response.getStatus(), response.getHeaders())
 | |
|     result = json.loads(response.consumeBody())
 | |
|     self.assertEqual(result['items'][0]['head']['name'], 'level2-item1')
 | |
| 
 | |
| def test_auth(self, config):
 | |
|     from scopes.web.auth import oidc
 | |
|     oidc.startup()  # todo: use generic app.startServices()
 | |
|     self.assertEqual(len(config.oidc_params['op_uris']), 8)
 | |
|     storage = config.storageFactory(config.dbschema)
 | |
|     response = publishRequest(config, storage, '/top/auth/login')
 | |
|     headers = dict(response.getHeaders())
 | |
|     logger.info('test_auth: response %s %s', response.getStatus(), headers)
 | |
|     self.assertEqual(response.getStatus(), 302)
 | |
|     uri = config.oidc_params['op_uris']['jwks_uri']
 | |
|     keys = oidc.loadOidcKeys(uri)
 | |
|     logger.info('test_auth keys: %s', keys)
 | |
| 
 | |
| def test_user_data(self, config):
 | |
|     from scopes.org import user
 | |
|     u1 = user.User(login='tst9', email='tst9@example.com',
 | |
|                    firstName='Test', lastName='User')
 | |
|     xu1 = user.ExtUser(u1, idPrefix='test.')
 | |
|     xu1.create(updateIfExists=True)
 |