Package omeroweb :: Package webclient :: Package tests :: Module unittests
[hide private]
[frames] | no frames]

Source Code for Module omeroweb.webclient.tests.unittests

  1  #!/usr/bin/env python 
  2  # 
  3  # 
  4  # Copyright (C) 2011 University of Dundee & Open Microscopy Environment. 
  5  # All rights reserved. 
  6  # 
  7  # This program is free software: you can redistribute it and/or modify 
  8  # it under the terms of the GNU Affero General Public License as 
  9  # published by the Free Software Foundation, either version 3 of the 
 10  # License, or (at your option) any later version. 
 11  # 
 12  # This program is distributed in the hope that it will be useful, 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 15  # GNU Affero General Public License for more details. 
 16  # 
 17  # You should have received a copy of the GNU Affero General Public License 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 19  # 
 20   
 21  import unittest, time, os, datetime 
 22  import tempfile 
 23   
 24  from webgateway import views 
 25  from webgateway import views 
 26   
 27  import omero 
 28  from omero.gateway.scripts.testdb_create import * 
 29   
 30  from django.test.client import Client 
 31  from django.core.handlers.wsgi import WSGIRequest 
 32  from django.conf import settings 
 33  from django.http import QueryDict 
 34   
 35  CLIENT_BASE='test' 
 36   
37 -def fakeRequest (**kwargs):
38 def bogus_request(self, **request): 39 """ 40 The master request method. Composes the environment dictionary 41 and passes to the handler, returning the result of the handler. 42 Assumes defaults for the query environment, which can be overridden 43 using the arguments to the request. 44 """ 45 environ = { 46 'HTTP_COOKIE': self.cookies, 47 'PATH_INFO': '/', 48 'QUERY_STRING': '', 49 'REQUEST_METHOD': 'GET', 50 'SCRIPT_NAME': '', 51 'SERVER_NAME': 'testserver', 52 'SERVER_PORT': '80', 53 'SERVER_PROTOCOL': 'HTTP/1.1', 54 'HTTP_HOST': 'localhost', 55 'wsgi.version': (1,0), 56 'wsgi.url_scheme': 'http', 57 'wsgi.errors': None,#self.errors, 58 'wsgi.multiprocess': True, 59 'wsgi.multithread': False, 60 'wsgi.run_once': False, 61 } 62 environ.update(self.defaults) 63 environ.update(request) 64 r = WSGIRequest(environ) 65 if 'django.contrib.sessions' in settings.INSTALLED_APPS: 66 engine = __import__(settings.SESSION_ENGINE, {}, {}, ['']) 67 r.session = engine.SessionStore() 68 qlen = len(r.REQUEST.dicts) 69 def setQuery (**query): 70 r.REQUEST.dicts = r.REQUEST.dicts[:qlen] 71 q = QueryDict('', mutable=True) 72 q.update(query) 73 r.REQUEST.dicts += (q,)
74 r.setQuery = setQuery 75 return r 76 Client.bogus_request = bogus_request 77 c = Client() 78 return c.bogus_request(**kwargs) 79
80 -class WGTest (GTest):
81 - def doLogin (self, user):
82 r = fakeRequest() 83 q = QueryDict('', mutable=True) 84 q.update({'username': user.name, 'password': user.passwd}) 85 r.REQUEST.dicts += (q,) 86 self.gateway = views.getBlitzConnection(r, 1, group=user.groupname, try_super=user.admin) 87 if self.gateway is None: 88 # If the login framework was customized (using this app outside omeroweb) the above fails 89 super(WGTest, self).doLogin(user) 90 self.gateway.user = views.UserProxy(self.gateway)
91
92 -class UserProxyTest (WGTest):
93 - def test (self):
94 self.loginAsAuthor() 95 user = self.gateway.user 96 self.assertEqual(user.isAdmin(), False) 97 int(user.getId()) 98 self.assertEqual(user.getName(), self.AUTHOR.name) 99 self.assertEqual(user.getFirstName(), self.AUTHOR.firstname) 100 views._purge(True)
101