1
+ # Copyright 2012 10gen, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Minimal test of PyMongo in a WSGI application with ReplicaSetConnection, see
16
+ bug PYTHON-353.
17
+ """
18
+
19
+ import os
20
+ import sys
21
+
22
+ this_path = os .path .dirname (os .path .join (os .getcwd (), __file__ ))
23
+
24
+ # Location of PyMongo checkout
25
+ repository_path = os .path .normpath (os .path .join (this_path , '..' , '..' ))
26
+ sys .path .insert (0 , repository_path )
27
+
28
+ import pymongo
29
+ from pymongo .replica_set_connection import ReplicaSetConnection
30
+
31
+ connection = ReplicaSetConnection (replicaSet = 'repl0' )
32
+ collection = connection .test .test
33
+
34
+ ndocs = 20
35
+
36
+ collection .drop ()
37
+ collection .insert ([{'i' : i } for i in range (ndocs )], safe = True )
38
+ connection .disconnect () # discard main thread's request socket
39
+
40
+ try :
41
+ from mod_wsgi import version as mod_wsgi_version
42
+ except :
43
+ mod_wsgi_version = None
44
+
45
+
46
+ def application (environ , start_response ):
47
+ results = list (collection .find ().batch_size (10 ))
48
+ assert len (results ) == ndocs
49
+ output = 'python %s, mod_wsgi %s, pymongo %s' % (
50
+ sys .version , mod_wsgi_version , pymongo .version )
51
+ response_headers = [('Content-Length' , str (len (output )))]
52
+ start_response ('200 OK' , response_headers )
53
+ return [output ]
0 commit comments