{ "info": { "author": "Christo Buschek", "author_email": "crito@30loops.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Topic :: Software Development :: Testing" ], "description": "========\nfakeldap\n========\n\nThe goal of this module is to provide a simple way to mock ldap backend servers\nfor your unittests. It makes it possible to define upfront a set of directory\nentries that can be queried or set fixed return values to ldap queries. It acts\nas a drop in replacement for the ``LDAPObject`` class of the python-ldap\nmodule. It implements a subset of the allowed methods of this class.\n\nThis module implements the ``MockLDAP`` class that functions both as the\n``LDAPObject`` as well as the ldap module. Most of the code and design has been\ntaken from Peter Sagerson's excellent django-auth-ldap_ module.\n\n.. _django-auth-ldap: https://bitbucket.org/psagers/django-auth-ldap/wiki/Home\n\nInstallation\n============\n\nGet and install the code::\n\n $ git clone git://github.com/30loops/fakeldap.git\n $ cd fakeldap\n $ python setup.py install\n\nIf you want, you can run the tests::\n\n $ python setup.py nosetests\n\nUsage\n=====\n\n.. note::\n\n This code is still experimental and not very tested as of yet. So is the\n documentation\n\nThe ``MockLDAP`` class replaces the ``LDAPObject`` of the python-ldap module.\nThe easiest way to use it, is to overwrite ``ldap.initialize`` to return\n``MockLDAP`` instead of ``LDAPObject``. The example below uses Michael Foord's\nMock_ library to achieve that::\n\n import unittest\n from mock import patch\n from fakeldap import MockLDAP\n\n\n _mock_ldap = MockLDAP()\n\n class YourTestCase(unittest.TestCase):\n def setUp(self):\n # Patch where the ldap library is used:\n self.ldap_patcher = patch('app.module.ldap.initialize')\n self.mock_ldap = self.ldap_patcher.start()\n self.mock_ldap.return_value = _mock_ldap\n\n def tearDown(self):\n _mock_ldap.reset()\n self.mock_ldap.stop()\n\nThe mock ldap object implements the following ldap operations:\n\n- simple_bind_s\n- search_s\n- compare_s\n- modify_s\n- delete_s\n- add_s\n- rename_s\n\nThis is an example how to use ``MockLDAP`` with fixed return values::\n\n def test_some_ldap_group_stuff(self):\n # Define the expected return value for the ldap operation\n return_value = (\"cn=testgroup,ou=group,dc=30loops,dc=net\", {\n 'objectClass': ['posixGroup'],\n 'cn': 'testgroup',\n 'gidNumber': '2030',\n })\n\n # Register a return value with the MockLDAP object\n _mock_ldap.set_return_value('add_s',\n (\"cn=testgroup,ou=groups,dc=30loops,dc=net\", (\n ('objectClass', ('posixGroup')),\n ('cn', 'testgroup'),\n ('gidNumber', '2030'))),\n (105,[], 10, []))\n\n # Run your actual code, this is just an example\n group_manager = GroupManager()\n result = group_manager.add(\"testgroup\")\n\n # assert that the return value of your method and of the MockLDAP\n # are as expected, here using python-nose's eq() test tool:\n eq_(return_value, result)\n\n # Each actual ldap call your software makes gets recorded. You could\n # prepare a list of calls that you expect to be issued and compare it:\n called_records = []\n\n called_records.append(('simple_bind_s',\n {'who': 'cn=admin,dc=30loops,dc=net', 'cred': 'ldaptest'}))\n\n called_records.append(('add_s', {\n 'dn': 'cn=testgroup,ou=groups,dc=30loops,dc=net\",\n 'record': [\n ('objectClass', ['posixGroup']),\n ('gidNumber', '2030'),\n ('cn', 'testgroup'),\n ]}))\n\n # And again test the expected behaviour\n eq_(called_records, _mock_ldap.ldap_methods_called_with_arguments())\n\nBesides of fixing return values for specific calls, you can also imitate a full\nldap server with a directory of entries::\n\n # Create an instance of MockLDAP with a preset directory\n tree = {\n \"cn=admin,dc=30loops,dc=net\": {\n \"userPassword\": \"ldaptest\"\n }\n }\n mock_ldap = MockLDAP(tree) \n\n record = [\n ('uid', 'crito'),\n ('userPassword', 'secret'),\n ]\n # The return value I expect when I add another record to the directory\n eq_(\n (105,[],1,[]),\n mock_ldap.add_s(\"uid=crito,ou=people,dc=30loops,dc=net\", record)\n )\n\n # The expected directory\n directory = {\n \"cn=admin,dc=30loops,dc=net\": {\"userPassword\": \"ldaptest\"},\n \"uid=crito,ou=people,dc=30loops,dc=net\": {\n \"uid\": \"crito\", \"userPassword\": \"secret\"}\n }\n # Compare the expected directory with the MockLDAP directory\n eq_(directory, mock_ldap.directory)\n\n.. _Mock: http://www.voidspace.org.uk/python/mock/\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/zulip/fakeldap", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "fakeldap", "package_url": "https://pypi.org/project/fakeldap/", "platform": "", "project_url": "https://pypi.org/project/fakeldap/", "project_urls": { "Homepage": "https://github.com/zulip/fakeldap" }, "release_url": "https://pypi.org/project/fakeldap/0.6.1/", "requires_dist": [ "pyldap", "nose; extra == 'test'", "Mock; extra == 'test'", "coverage; extra == 'test'", "unittest2; extra == 'test'", "pyldap; extra == 'test'" ], "requires_python": "", "summary": "An implementation of a LDAPObject to fake a ldap server in unittests.", "version": "0.6.1" }, "last_serial": 3333593, "releases": { "0.5.1": [ { "comment_text": "", "digests": { "md5": "3e28a5b5cf8d6215e5b16cc23c44c9f2", "sha256": "b36e4ff9be06c662ee52164514889f6352cf0eb811925a68bace1d142a2e8ed5" }, "downloads": -1, "filename": "fakeldap-0.5.1.tar.gz", "has_sig": false, "md5_digest": "3e28a5b5cf8d6215e5b16cc23c44c9f2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8184, "upload_time": "2011-11-01T02:49:09", "url": "https://files.pythonhosted.org/packages/22/19/57e51a0ccfd4152e3a3cf0ed18a614a304c28dc13310c1b056cff77fec0c/fakeldap-0.5.1.tar.gz" } ], "0.6": [ { "comment_text": "", "digests": { "md5": "081ca2e37aafd7b608b1b82d616a04ea", "sha256": "a091485ce038b6816296671891ae0af5d91c8c0a69edc1c43c47f1d852f0035b" }, "downloads": -1, "filename": "fakeldap-0.6-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "081ca2e37aafd7b608b1b82d616a04ea", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9906, "upload_time": "2017-11-10T22:27:16", "url": "https://files.pythonhosted.org/packages/86/82/85a7b8650a3ee01da568b2031cd9f2d11f9c4d01cc40f3d7b03c089429a9/fakeldap-0.6-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7f3e5b1775a5411620393c6756f37896", "sha256": "deaa7a48c315316cb2e17bf4df6812fa0587c48fa3509e816b14dbbf9ca0e0a9" }, "downloads": -1, "filename": "fakeldap-0.6.tar.gz", "has_sig": false, "md5_digest": "7f3e5b1775a5411620393c6756f37896", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7590, "upload_time": "2017-11-10T22:27:18", "url": "https://files.pythonhosted.org/packages/46/f1/544dc488155ab3fec5703ed55fb801c1b7c7dcb12f01864efbfa68529e08/fakeldap-0.6.tar.gz" } ], "0.6.1": [ { "comment_text": "", "digests": { "md5": "17fabc04b3b7429c8dcdccc6083b6d9d", "sha256": "43000061ca8e6d56fe0ce89256a1a2afc46e6443762bb96631542a1af8e70354" }, "downloads": -1, "filename": "fakeldap-0.6.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "17fabc04b3b7429c8dcdccc6083b6d9d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9937, "upload_time": "2017-11-15T02:19:59", "url": "https://files.pythonhosted.org/packages/36/c9/f4c9d3751daa2b116a7ab1d943fac79980e334b9f59b412b598824f83fef/fakeldap-0.6.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "61387868b430ce2bbf42e5f3ab0a9c04", "sha256": "3f7262b41def43b85be886ca6d64d1c310d2db48a434fddae86efc34a09a7a81" }, "downloads": -1, "filename": "fakeldap-0.6.1.tar.gz", "has_sig": false, "md5_digest": "61387868b430ce2bbf42e5f3ab0a9c04", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7550, "upload_time": "2017-11-15T02:20:00", "url": "https://files.pythonhosted.org/packages/2f/d9/61e6190c8b60839fa3d09a4453600a66be776f22c0983d9faf526e4e8caf/fakeldap-0.6.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "17fabc04b3b7429c8dcdccc6083b6d9d", "sha256": "43000061ca8e6d56fe0ce89256a1a2afc46e6443762bb96631542a1af8e70354" }, "downloads": -1, "filename": "fakeldap-0.6.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "17fabc04b3b7429c8dcdccc6083b6d9d", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9937, "upload_time": "2017-11-15T02:19:59", "url": "https://files.pythonhosted.org/packages/36/c9/f4c9d3751daa2b116a7ab1d943fac79980e334b9f59b412b598824f83fef/fakeldap-0.6.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "61387868b430ce2bbf42e5f3ab0a9c04", "sha256": "3f7262b41def43b85be886ca6d64d1c310d2db48a434fddae86efc34a09a7a81" }, "downloads": -1, "filename": "fakeldap-0.6.1.tar.gz", "has_sig": false, "md5_digest": "61387868b430ce2bbf42e5f3ab0a9c04", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7550, "upload_time": "2017-11-15T02:20:00", "url": "https://files.pythonhosted.org/packages/2f/d9/61e6190c8b60839fa3d09a4453600a66be776f22c0983d9faf526e4e8caf/fakeldap-0.6.1.tar.gz" } ] }