1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
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,
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
91
101