m01.stub


Namem01.stub JSON
Version 3.13.1 PyPI version JSON
download
home_pagehttp://pypi.python.org/pypi/m01.stub
SummaryMongoDB server stub setup
upload_time2025-07-10 13:23:50
maintainerNone
docs_urlNone
authorRoger Ineichen, Projekt01 GmbH
requires_pythonNone
licenseZPL 2.1
keywords zope3 z3c p01 m01 mongodb server stub setup
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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

  import m01.stub.testing

  def test_suite():
      return unittest.TestSuite((
          doctest.DocFileSuite('README.txt',
              setUp=m01.stub.testing.setUpStubMongo,
              tearDown=m01.stub.testing.tearDownStubMongo,
              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
  >>> from pymongo.periodic_executor import _shutdown_executors
  >>> import m01.stub.testing

Let's test our mongodb stub setup:

  >>> conn = m01.stub.testing.getTestClient()

  >>> pprint(conn.server_info())
  {...,
   ...'ok': 1.0,
   ...}

  >>> sorted([i for i in conn.list_database_names()])
  [...'admin', ...'local']

setup an index:

  >>> print(conn.m01_stub_testing.test.collection.create_index('dummy'))
  dummy_1

add an object:

  >>> result = conn.m01_stub_testing.test.insert_one({'__name__': 'foo', 'dummy': 'object'})
  >>> 'InsertOneResult' in str(result)
  True

  >>> _id = result.inserted_id
  >>> _id
  ObjectId('...')

remove them:

  >>> result = conn.m01_stub_testing.test.delete_one({'_id': _id})
  >>> 'DeleteResult' in str(result)
  True

  >>> result.acknowledged
  True

  >> m01.fake.pprint(result.raw_result)
  {'n': 1, 'ok': 1.0}

  >>> result.deleted_count
  1

and check the databsae names again:

  >>> sorted([i for i in list(conn.list_database_names())])
  [...'admin', ...'local', ...'m01_stub_testing']

Let's drop the database:

  >>> conn.drop_database("m01_stub_testing")
  >>> sorted([i for i in conn.list_database_names()])
  [...'admin', ...'local']


Close client:

  >>> conn.close()
  >>> _shutdown_executors()


=======
CHANGES
=======


3.13.1 (2025-07-10)
-------------------

- make code python 3 compatible


3.13.0 (2025-06-26)
-------------------

- make m01.stub compatible with pymongo 3.13.0

- migration: python 2.7/3 version compatibility

- bugfix: fix downloadURL, ensure urls list if given. Add additional urls
  argument which allows to provide a list of download urls


3.1.0 (2018-01-29)
------------------

- bugfix: support different download urls for windows. Not every option is
  released. We will try different urls for windows 64 bit versions.
  Note, you will probably run into a MemoryError during download if your try
  to download a large mongodb release with a non 64 bit python version.


3.0.1 (2015-11-10)
------------------

- support pymongo >= 3.0.0 and use 3.0.0 as package version and reflect
  pymongo >= 3.0.0 compatibility


3.0.0 (2015-09-28)
------------------

- pymongo > 3.0.0 compatibility. Support pymongo > 3.0.0 use MongoClient instead
  of Connection etc. Use 3.0.0 as package version and reflect pymongo > 3.0.0
  compatibility.

- switch default mongodb download version to 3.0.6

- improve shutdown mongodb server, cleanup client weakref


0.5.8 (2015-03-17)
------------------

- update default mongodb version to 2.4.10

- changed default mongodb allocation space from 100MB to 10MB for faster server
  startup

- bugfix: startup check didn't fit and it was forced 16 times to sleep for one
  second. Fix server status ok check from '1.0' to 1


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 startMongoServer


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.
            

Raw data

            {
    "_id": null,
    "home_page": "http://pypi.python.org/pypi/m01.stub",
    "name": "m01.stub",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "Zope3 z3c p01 m01 mongodb server stub setup",
    "author": "Roger Ineichen, Projekt01 GmbH",
    "author_email": "dev@projekt01.ch",
    "download_url": "https://files.pythonhosted.org/packages/c6/00/d2487acf6be2b2b20c673e89f0315259fbd4c9f007c519391a1818692203/m01.stub-3.13.1.tar.gz",
    "platform": null,
    "description": "This package provides a mongodb server stub setup for python doctests.\n\n\n======\nREADME\n======\n\nThis package provides a mongo database server testing stub. You can simply\nsetup such a mongodb stub server in a doctest like::\n\n  import doctest\n  import unittest\n\n  import m01.stub.testing\n\n  def test_suite():\n      return unittest.TestSuite((\n          doctest.DocFileSuite('README.txt',\n              setUp=m01.stub.testing.setUpStubMongo,\n              tearDown=m01.stub.testing.tearDownStubMongo,\n              optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),\n          ))\n\n\n  if __name__ == '__main__':\n      unittest.main(defaultTest='test_suite')\n\nThe m01/stub/testing.py module provides a start and stop method which will\ndownload, install, start and stop a mongodb server. All this is done in the\nm01/stub/testing/sandbox folder. Everytime a test get started the mongodb/data\nfolder get removed and a fresh empty database get used.\n\nNote: Also see the zipFolder and unZipFile methods in testing.py which allows\nyou to setup mongodb data and before remove them store them as a zip file\nfor a next test run. Such a zipped data folder can get used in another test run\nby set the path to the zip file as dataSource argument. Also check the\nm01.mongo package for more test use cases.\n\n\nTesting\n-------\n\nLet's use the pymongo package for test our mongodb server stub setup. Note we\nuse a different port for our stub server setup (45017 instead of 27017):\n\n  >>> from pprint import pprint\n  >>> from pymongo.periodic_executor import _shutdown_executors\n  >>> import m01.stub.testing\n\nLet's test our mongodb stub setup:\n\n  >>> conn = m01.stub.testing.getTestClient()\n\n  >>> pprint(conn.server_info())\n  {...,\n   ...'ok': 1.0,\n   ...}\n\n  >>> sorted([i for i in conn.list_database_names()])\n  [...'admin', ...'local']\n\nsetup an index:\n\n  >>> print(conn.m01_stub_testing.test.collection.create_index('dummy'))\n  dummy_1\n\nadd an object:\n\n  >>> result = conn.m01_stub_testing.test.insert_one({'__name__': 'foo', 'dummy': 'object'})\n  >>> 'InsertOneResult' in str(result)\n  True\n\n  >>> _id = result.inserted_id\n  >>> _id\n  ObjectId('...')\n\nremove them:\n\n  >>> result = conn.m01_stub_testing.test.delete_one({'_id': _id})\n  >>> 'DeleteResult' in str(result)\n  True\n\n  >>> result.acknowledged\n  True\n\n  >> m01.fake.pprint(result.raw_result)\n  {'n': 1, 'ok': 1.0}\n\n  >>> result.deleted_count\n  1\n\nand check the databsae names again:\n\n  >>> sorted([i for i in list(conn.list_database_names())])\n  [...'admin', ...'local', ...'m01_stub_testing']\n\nLet's drop the database:\n\n  >>> conn.drop_database(\"m01_stub_testing\")\n  >>> sorted([i for i in conn.list_database_names()])\n  [...'admin', ...'local']\n\n\nClose client:\n\n  >>> conn.close()\n  >>> _shutdown_executors()\n\n\n=======\nCHANGES\n=======\n\n\n3.13.1 (2025-07-10)\n-------------------\n\n- make code python 3 compatible\n\n\n3.13.0 (2025-06-26)\n-------------------\n\n- make m01.stub compatible with pymongo 3.13.0\n\n- migration: python 2.7/3 version compatibility\n\n- bugfix: fix downloadURL, ensure urls list if given. Add additional urls\n  argument which allows to provide a list of download urls\n\n\n3.1.0 (2018-01-29)\n------------------\n\n- bugfix: support different download urls for windows. Not every option is\n  released. We will try different urls for windows 64 bit versions.\n  Note, you will probably run into a MemoryError during download if your try\n  to download a large mongodb release with a non 64 bit python version.\n\n\n3.0.1 (2015-11-10)\n------------------\n\n- support pymongo >= 3.0.0 and use 3.0.0 as package version and reflect\n  pymongo >= 3.0.0 compatibility\n\n\n3.0.0 (2015-09-28)\n------------------\n\n- pymongo > 3.0.0 compatibility. Support pymongo > 3.0.0 use MongoClient instead\n  of Connection etc. Use 3.0.0 as package version and reflect pymongo > 3.0.0\n  compatibility.\n\n- switch default mongodb download version to 3.0.6\n\n- improve shutdown mongodb server, cleanup client weakref\n\n\n0.5.8 (2015-03-17)\n------------------\n\n- update default mongodb version to 2.4.10\n\n- changed default mongodb allocation space from 100MB to 10MB for faster server\n  startup\n\n- bugfix: startup check didn't fit and it was forced 16 times to sleep for one\n  second. Fix server status ok check from '1.0' to 1\n\n\n0.5.7 (2012-12-10)\n------------------\n\n- bugfix: didn't shutdown with sleep lower the 1\n\n- improve server setup, use unique log files for each startup\n\n- run tests with pymongo 2.4.1\n\n\n0.5.6 (2012-12-09)\n------------------\n\n- switch to mongodb 2.2.2 and support version property in startMongoServer\n\n\n0.5.5 (2012-11-18)\n------------------\n\n- bugfix: fix start and stop observer methods. Replaced javascript calls with\n  simpler pymongo connectionn calls for startup check and shutdown\n\n\n0.5.4 (2012-11-18)\n------------------\n\n- update to mongodb 2.2.0\n\n- switch to bson import\n\n- force 64 bit download by default\n\n- use \"sleep\" value only for files and directories, use flexible wait for\n  process\n\n- bugfix: mongo results comes back with a line break\n\n- bugfix: string cmd *only* on Windows\n\n- use shell=False to start mongodb, even on posix (safer). This changes the\n  \"options\" argument: it has to be a list now\n\n- to stop mongodb, we are now sending a command through the \"mongo shell\",\n  we do not use a pid file any more, all we need is the port, which we keep\n  in a global\n\n- we are now repeatedly checking till the mongodb server starts up and\n  answers to an admin query\n\n- move flexible sub-version tests to accomodate OpenBSD\n\n- fixed detection of being on a Mac for mongo db download for tests\n\n- added MANIFEST.in file\n\n\n0.5.3 (2011-08-26)\n------------------\n\n- Fix 32bit linux download (Albertas)\n- Remove temp files after download\n- Fix 64bit linux\n\n\n0.5.2 (2011-08-24)\n------------------\n\n- Still fixing on linux\n\n\n0.5.1 (2011-08-24)\n------------------\n\n- fix on linux\n\n\n0.5.0 (2011-08-19)\n------------------\n\n- initial release tested on win 32bit. NOT tested on win 64bit, mac 32/64bit\n  and posix 32/64bit systems. Please report if something doesn't work on this\n  systems.",
    "bugtrack_url": null,
    "license": "ZPL 2.1",
    "summary": "MongoDB server stub setup",
    "version": "3.13.1",
    "project_urls": {
        "Homepage": "http://pypi.python.org/pypi/m01.stub"
    },
    "split_keywords": [
        "zope3",
        "z3c",
        "p01",
        "m01",
        "mongodb",
        "server",
        "stub",
        "setup"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c600d2487acf6be2b2b20c673e89f0315259fbd4c9f007c519391a1818692203",
                "md5": "204d3b7631cefc2d17000d179391d376",
                "sha256": "47e823e65041a38531882d4cfb324bbbaa27fde398e57035214e03435e75d3be"
            },
            "downloads": -1,
            "filename": "m01.stub-3.13.1.tar.gz",
            "has_sig": false,
            "md5_digest": "204d3b7631cefc2d17000d179391d376",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 99151,
            "upload_time": "2025-07-10T13:23:50",
            "upload_time_iso_8601": "2025-07-10T13:23:50.912545Z",
            "url": "https://files.pythonhosted.org/packages/c6/00/d2487acf6be2b2b20c673e89f0315259fbd4c9f007c519391a1818692203/m01.stub-3.13.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-10 13:23:50",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "m01.stub"
}
        
Elapsed time: 0.41547s