Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install m01.stub

How to install m01.stub

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install m01.stub
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.5.5
0.5.7Never BuiltWhy not?
0.5.5 Available View build log
0.5.3 Available View build log
0.5.2 Available View build log
0.5.0 Available View build log
Windows (64-bit)
0.5.3
0.5.7Never BuiltWhy not?
0.5.3 Available View build log
0.5.2 Available View build log
0.5.0 Available View build log
Mac OS X (10.5+)
0.5.5
0.5.7Never BuiltWhy not?
0.5.5 Available View build log
0.5.3 Available View build log
0.5.2 Available View build log
0.5.0 Available View build log
Linux (32-bit)
0.5.5
0.5.7Never BuiltWhy not?
0.5.5 Available View build log
0.5.3 Available View build log
0.5.2 Available View build log
0.5.0 Available View build log
Linux (64-bit)
0.5.7 Available View build log
0.5.5 Available View build log
0.5.3 Available View build log
0.5.2 Available View build log
0.5.0 Available View build log
 
License
ZPL 2.1
Dependencies
Imports
Lastest release
version 0.5.7 on Jan 9th, 2014

This package provides a mongodb server stub setup for python doctests.

README

This package provides a mongo database server testing stub. You can simply setup such a mongodb stub server in a doctest like:

import doctest
import unittest

from m01.stub import testing

def test_suite():
    return unittest.TestSuite((
        doctest.DocFileSuite('README.txt',
            setUp=testing.doctestSetUp,
            tearDown=testing.doctestTearDown,
            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
        ))


if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')

The m01/stub/testing.py module provides a start and stop method which will download, install, start and stop a mongodb server. All this is done in the m01/stub/testing/sandbox folder. Everytime a test get started the mongodb/data folder get removed and a fresh empty database get used.

Note: Also see the zipFolder and unZipFile methods in testing.py which allows you to setup mongodb data and before remove them store them as a zip file for a next test run. Such a zipped data folder can get used in another test run by set the path to the zip file as dataSource argument. Also check the m01.mongo package for more test use cases.

Testing

Let's use the pymongo package for test our mongodb server stub setup. Note we use a different port for our stub server setup (45017 instead of 27017):

>>> from pprint import pprint
>>> import pymongo
>>> conn = pymongo.Connection('localhost', 45017)

Let's test our mongodb stub setup:

>>> pprint(conn.server_info())
{u'bits': ...,
 u'debug': False,
 u'gitVersion': u'...',
 u'maxBsonObjectSize': ...,
 u'ok': 1.0,
 u'sysInfo': ...,
 u'version': u'2.2.1',
 u'versionArray': [2, 2, 1, 0]}
>>> conn.database_names()
[u'local']

setup an index:

>>> conn.testing.test.collection.ensure_index('dummy')
u'dummy_1'

add an object:

>>> _id = conn.testing.test.save({'__name__': u'foo', 'dummy': u'object'})
>>> _id
ObjectId('...')

remove them:

>>> conn.testing.test.remove({'_id': _id})

and check the database names again:

>>> conn.database_names()
[u'testing', u'local']

Let's drop the database:

>>> conn.drop_database("testing")
>>> conn.database_names()
[u'local']

CHANGES

0.5.7 (2012-12-10)
  • bugfix: didn't shutdown with sleep lower the 1
  • improve server setup, use unique log files for each startup
  • run tests with pymongo 2.4.1
0.5.6 (2012-12-09)
  • switch to mongodb 2.2.2 and support version property in startMongoDBServer
0.5.5 (2012-11-18)
  • bugfix: fix start and stop observer methods. Replaced javascript calls with simpler pymongo connectionn calls for startup check and shutdown
0.5.4 (2012-11-18)
  • update to mongodb 2.2.0
  • switch to bson import
  • force 64 bit download by default
  • use "sleep" value only for files and directories, use flexible wait for process
  • bugfix: mongo results comes back with a line break
  • bugfix: string cmd only on Windows
  • use shell=False to start mongodb, even on posix (safer). This changes the "options" argument: it has to be a list now
  • to stop mongodb, we are now sending a command through the "mongo shell", we do not use a pid file any more, all we need is the port, which we keep in a global
  • we are now repeatedly checking till the mongodb server starts up and answers to an admin query
  • move flexible sub-version tests to accomodate OpenBSD
  • fixed detection of being on a Mac for mongo db download for tests
  • added MANIFEST.in file
0.5.3 (2011-08-26)
  • Fix 32bit linux download (Albertas)
  • Remove temp files after download
  • Fix 64bit linux
0.5.2 (2011-08-24)
  • Still fixing on linux
0.5.1 (2011-08-24)
  • fix on linux
0.5.0 (2011-08-19)
  • initial release tested on win 32bit. NOT tested on win 64bit, mac 32/64bit and posix 32/64bit systems. Please report if something doesn't work on this systems.

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.