Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
includeme
support and attach registration directives to confi…
…gurator.
- Loading branch information
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
#a package | ||
from .db import register_mongodb | ||
from .db import register_memcached | ||
|
||
def includeme(config): | ||
""" Function meant to be included via | ||
:meth:`pyramid.config.Configurator.include`, which sets up the | ||
Configurator with a ``register_path`` method.""" | ||
|
||
config.add_directive('register_mongodb', register_mongodb, action_wrap=False) | ||
config.add_directive('register_memcached', register_memcached, action_wrap=False) | ||
config.scan('lumin') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import unittest | ||
import pyramid.testing | ||
|
||
|
||
class ConfigurationTest(unittest.TestCase): | ||
def setUp(self): | ||
self.config = pyramid.testing.setUp() | ||
|
||
def tearDown(self): | ||
pyramid.testing.tearDown() | ||
|
||
def test_register_mongodb_directive(self): | ||
import lumin | ||
self.config.include(lumin) | ||
|
||
from lumin.db import IMongoDBConnection | ||
connection = self.config.registry.queryUtility(IMongoDBConnection) | ||
self.assertTrue(connection is None) | ||
|
||
# Now, let's register a database connection | ||
self.config.register_mongodb('mongodb://localhost/') | ||
connection = self.config.registry.queryUtility(IMongoDBConnection) | ||
self.assertTrue(connection is not None) | ||
|
||
def test_register_memcached_directive(self): | ||
import lumin | ||
self.config.include(lumin) | ||
|
||
from lumin.db import IMemcachedClient | ||
client = self.config.registry.queryUtility(IMemcachedClient) | ||
self.assertTrue(client is None) | ||
|
||
# Now, let's register a memcached client | ||
self.config.register_memcached('http://localhost/') | ||
client = self.config.registry.queryUtility(IMemcachedClient) | ||
self.assertTrue(client is not None) |