Test ReplicaSetConnection with mod_wsgi WEBSITE-598

This commit is contained in:
A. Jesse Jiryu Davis 2012-08-23 14:12:01 -04:00
parent a010192d69
commit 3da05fb12b
3 changed files with 68 additions and 3 deletions

View File

@ -14,14 +14,26 @@
# Minimal test of PyMongo in a WSGI application, see bug PYTHON-353
LoadModule wsgi_module modules/mod_wsgi.so
# Avoid permissions issues
WSGISocketPrefix /tmp/
<VirtualHost *>
ServerName localhost
WSGIDaemonProcess mod_wsgi_test processes=1 threads=15 display-name=mod_wsgi_test
WSGIProcessGroup mod_wsgi_test
# For the convienience of unittests, rather than hard-code the location of
# mod_wsgi_test.wsgi, include it in the URL, so
# http://localhost/location-of-pymongo-checkout will work.
WSGIScriptAliasMatch ^(.+) $1/test/mod_wsgi_test/mod_wsgi_test.wsgi
# mod_wsgi_test_single_server.wsgi and mod_wsgi_test_replica_set.wsgi,
# include it in the URL, so
# http://localhost/single_server/location-of-pymongo-checkout will work:
WSGIScriptAliasMatch ^/single_server(.+) $1/test/mod_wsgi_test/mod_wsgi_test_single_server.wsgi
WSGIScriptAliasMatch ^/replica_set(.+) $1/test/mod_wsgi_test/mod_wsgi_test_replica_set.wsgi
</VirtualHost>

View File

@ -0,0 +1,53 @@
# Copyright 2012 10gen, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Minimal test of PyMongo in a WSGI application with ReplicaSetConnection, see
bug PYTHON-353.
"""
import os
import sys
this_path = os.path.dirname(os.path.join(os.getcwd(), __file__))
# Location of PyMongo checkout
repository_path = os.path.normpath(os.path.join(this_path, '..', '..'))
sys.path.insert(0, repository_path)
import pymongo
from pymongo.replica_set_connection import ReplicaSetConnection
connection = ReplicaSetConnection(replicaSet='repl0')
collection = connection.test.test
ndocs = 20
collection.drop()
collection.insert([{'i': i} for i in range(ndocs)], safe=True)
connection.disconnect() # discard main thread's request socket
try:
from mod_wsgi import version as mod_wsgi_version
except:
mod_wsgi_version = None
def application(environ, start_response):
results = list(collection.find().batch_size(10))
assert len(results) == ndocs
output = 'python %s, mod_wsgi %s, pymongo %s' % (
sys.version, mod_wsgi_version, pymongo.version)
response_headers = [('Content-Length', str(len(output)))]
start_response('200 OK', response_headers)
return [output]