openlp/tests/functional/openlp_core_lib/test_registry.py

41 lines
1.2 KiB
Python
Raw Normal View History

2013-01-22 21:59:45 +00:00
"""
Package to test the openlp.core.lib package.
"""
import os
from unittest import TestCase
from mock import MagicMock
2013-01-23 21:51:45 +00:00
from openlp.core.lib import Registry
2013-01-22 21:59:45 +00:00
TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources'))
class TestServiceItem(TestCase):
def registry_basic_test(self):
"""
Test the Service Item basic test
"""
# GIVEN: A new registry
registry = Registry.create()
2013-01-24 06:00:51 +00:00
# WHEN: I add a service it should save it
2013-01-22 21:59:45 +00:00
mock_1 = MagicMock()
Registry().register(u'test1', mock_1)
# THEN: we should be able retrieve the saved object
2013-01-24 06:00:51 +00:00
assert Registry().get(u'test1') == mock_1, u'The saved service can be retrieved and matches'
2013-01-22 21:59:45 +00:00
2013-01-24 06:00:51 +00:00
# WHEN: I add a service it should save it a second time
# THEN I will get an exception
try:
Registry().register(u'test1', mock_1)
except Exception, e:
pass
# WHEN I try to get back a non existent service
# THEN I will get an exception
2013-01-22 21:59:45 +00:00
try:
assert Registry().get(u'test2') == mock_1, u'This should not be fired'
except Exception, e:
pass