Skip to content

Commit

Permalink
add micromongo.models.registered_models, micromongo.VERSION, a test a…
Browse files Browse the repository at this point in the history
…round the version string, version bump to 0.1.2
  • Loading branch information
jmoiron committed Jun 18, 2011
1 parent 37a0cd8 commit 64da2c4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 30 deletions.
9 changes: 8 additions & 1 deletion docs/models.rst
Expand Up @@ -143,5 +143,12 @@ You can also use ``pre_save`` to cache or calculate certain fields based off of
others in the model. A text document meant to be saved in markdown can have
a calculated field ``prerendered`` that is set in this hook.

Registration Access
~~~~~~~~~~~~~~~~~~~

Micromongo keeps track of all models that have been registered. For
applications that might want to use this data, a function providing a mapping
of their database location to the model class is provided:

.. autofunction:: micromongo.models.registered_models


5 changes: 4 additions & 1 deletion micromongo/__init__.py
Expand Up @@ -6,5 +6,8 @@
from models import *
from spec import Field

__all__ = ['connect', 'clean_connection', 'Model', 'Field']
VERSION = (0, 1, 2)

__all__ = ['connect', 'clean_connection', 'Model', 'Field', 'VERSION']


5 changes: 5 additions & 0 deletions micromongo/models.py
Expand Up @@ -44,6 +44,11 @@ def clean_connection():
raise Exception('must call `connect` before `clean_connection`')
return PymongoConnection(*__connection_args[0], **__connection_args[1])

def registered_models():
"""Return the AccountingMeta's model mapping, which is a dictionary of
keys in the form of "db.collection" to model classes."""
return dict(AccountingMeta.collection_map)

def class_router(collection_full_name):
return AccountingMeta.route(collection_full_name)

Expand Down
57 changes: 29 additions & 28 deletions setup.py
Expand Up @@ -5,38 +5,39 @@

from setuptools import setup, find_packages

version = '0.1.1'
version = '0.1.2'

# some trove classifiers:

# License :: OSI Approved :: MIT License
# Intended Audience :: Developers
# Operating System :: POSIX

setup(
name='micromongo',
version=version,
description="small natural object/mongodb driver",
long_description=open('README.rst').read(),
# Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 3 - Alpha',
'Topic :: Database :: Front-Ends',
'License :: OSI Approved :: MIT License',
'Intended Audience :: Developers',
],
keywords='mongodb orm',
author='Jason Moiron',
author_email='jmoiron@jmoiron.net',
url='http://github.com/jmoiron/micromongo',
license='MIT',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
zip_safe=False,
test_suite="tests",
install_requires=[
'pymongo',
],
# -*- Entry points: -*-
entry_points="",
)
if __name__ == '__main__':
setup(
name='micromongo',
version=version,
description="small natural object/mongodb driver",
long_description=open('README.rst').read(),
# Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 3 - Alpha',
'Topic :: Database :: Front-Ends',
'License :: OSI Approved :: MIT License',
'Intended Audience :: Developers',
],
keywords='mongodb orm',
author='Jason Moiron',
author_email='jmoiron@jmoiron.net',
url='http://github.com/jmoiron/micromongo',
license='MIT',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
zip_safe=False,
test_suite="tests",
install_requires=[
'pymongo',
],
# -*- Entry points: -*-
entry_points="",
)
9 changes: 9 additions & 0 deletions tests/test_models.py
Expand Up @@ -135,3 +135,12 @@ class Foo(Model):
self.assertEqual(len(list(foos)), 2)
self.assertEqual(len(list(foos)), 2)

class MiscTest(TestCase):
def test_version(self):
"""Test micromongo.VERSION."""
import setup
import micromongo
self.assertTrue(bool(micromongo.VERSION))
# make sure that it's the same as the version in setup.py
self.assertEqual('.'.join(map(str, micromongo.VERSION)), setup.version)

0 comments on commit 64da2c4

Please sign in to comment.