Skip to content

Commit 3da05fb

Browse files
author
A. Jesse Jiryu Davis
committed
Test ReplicaSetConnection with mod_wsgi WEBSITE-598
1 parent a010192 commit 3da05fb

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

test/mod_wsgi_test/mod_wsgi_test.conf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@
1414

1515
# Minimal test of PyMongo in a WSGI application, see bug PYTHON-353
1616

17+
LoadModule wsgi_module modules/mod_wsgi.so
18+
19+
# Avoid permissions issues
20+
WSGISocketPrefix /tmp/
21+
1722
<VirtualHost *>
23+
1824
ServerName localhost
1925

2026
WSGIDaemonProcess mod_wsgi_test processes=1 threads=15 display-name=mod_wsgi_test
27+
2128
WSGIProcessGroup mod_wsgi_test
2229

2330
# For the convienience of unittests, rather than hard-code the location of
24-
# mod_wsgi_test.wsgi, include it in the URL, so
25-
# http://localhost/location-of-pymongo-checkout will work.
26-
WSGIScriptAliasMatch ^(.+) $1/test/mod_wsgi_test/mod_wsgi_test.wsgi
31+
# mod_wsgi_test_single_server.wsgi and mod_wsgi_test_replica_set.wsgi,
32+
# include it in the URL, so
33+
# http://localhost/single_server/location-of-pymongo-checkout will work:
34+
35+
WSGIScriptAliasMatch ^/single_server(.+) $1/test/mod_wsgi_test/mod_wsgi_test_single_server.wsgi
36+
37+
WSGIScriptAliasMatch ^/replica_set(.+) $1/test/mod_wsgi_test/mod_wsgi_test_replica_set.wsgi
38+
2739
</VirtualHost>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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]
File renamed without changes.

0 commit comments

Comments
 (0)