summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Nagy <mnagy@redhat.com>2008-10-17 22:55:03 +0200
committerMartin Nagy <mnagy@redhat.com>2008-10-17 23:11:51 +0200
commit3a80297b04d6fbfd2367ec76c5651d20293adccc (patch)
tree8f10d8b3c490dec9b29077ffaa4052bb03c27fea /tests
parentae8370be44d95b9f6793ded46ef81126aebef3e0 (diff)
downloadfreeipa-3a80297b04d6fbfd2367ec76c5651d20293adccc.tar.gz
freeipa-3a80297b04d6fbfd2367ec76c5651d20293adccc.tar.xz
freeipa-3a80297b04d6fbfd2367ec76c5651d20293adccc.zip
Reworking Environment, moved it to config.py
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ipalib/test_config.py106
-rw-r--r--tests/test_ipalib/test_crud.py2
-rw-r--r--tests/test_ipalib/test_frontend.py4
-rw-r--r--tests/test_ipalib/test_plugable.py79
4 files changed, 97 insertions, 94 deletions
diff --git a/tests/test_ipalib/test_config.py b/tests/test_ipalib/test_config.py
index 3fe44136a..df8302326 100644
--- a/tests/test_ipalib/test_config.py
+++ b/tests/test_ipalib/test_config.py
@@ -23,29 +23,111 @@ Test the `ipalib.config` module.
import types
-from tests.util import raises
+from tests.util import raises, setitem, delitem
+#from tests.util import getitem, setitem, delitem
from ipalib import config
-def test_generate_env():
+def test_Environment():
"""
- Test the `ipalib.config.generate_env` function.
+ Test the `ipalib.config.Environment` class.
+ """
+ # This has to be the same as iter_cnt
+ control_cnt = 0
+ class prop_class:
+ def __init__(self, val):
+ self._val = val
+ def get_value(self):
+ return self._val
+
+ class iter_class(prop_class):
+ # Increment this for each time iter_class yields
+ iter_cnt = 0
+ def get_value(self):
+ for item in self._val:
+ self.__class__.iter_cnt += 1
+ yield item
+
+ # Tests for basic functionality
+ basic_tests = (
+ ('a', 1),
+ ('b', 'basic_foo'),
+ ('c', ('basic_bar', 'basic_baz')),
+ )
+ # Tests with prop classes
+ prop_tests = (
+ ('d', prop_class(2), 2),
+ ('e', prop_class('prop_foo'), 'prop_foo'),
+ ('f', prop_class(('prop_bar', 'prop_baz')), ('prop_bar', 'prop_baz')),
+ )
+ # Tests with iter classes
+ iter_tests = (
+ ('g', iter_class((3, 4, 5)), (3, 4, 5)),
+ ('h', iter_class(('iter_foo', 'iter_bar', 'iter_baz')),
+ ('iter_foo', 'iter_bar', 'iter_baz')
+ ),
+ )
+
+ # Set all the values
+ env = config.Environment()
+ for name, val in basic_tests:
+ env[name] = val
+ for name, val, dummy in prop_tests:
+ env[name] = val
+ for name, val, dummy in iter_tests:
+ env[name] = val
+
+ # Test if the values are correct
+ for name, val in basic_tests:
+ assert env[name] == val
+ for name, dummy, val in prop_tests:
+ assert env[name] == val
+ # Test if the get_value() function is called only when needed
+ for name, dummy, correct_values in iter_tests:
+ values_in_env = []
+ for val in env[name]:
+ control_cnt += 1
+ assert iter_class.iter_cnt == control_cnt
+ values_in_env.append(val)
+ assert tuple(values_in_env) == correct_values
+
+ # Test __setattr__()
+ env.spam = 'ham'
+ assert env.spam == 'ham'
+
+ # Test if we throw AttributeError exception when trying to overwrite
+ # existing value, or delete it
+ raises(AttributeError, setitem, env, 'a', 1)
+ raises(AttributeError, setattr, env, 'a', 1)
+ raises(AttributeError, delitem, env, 'a')
+ raises(AttributeError, delattr, env, 'a')
+ raises(AttributeError, config.Environment.update, env, dict(a=1000))
+ # This should be silently ignored
+ env.update(dict(a=1000), True)
+ assert env.a != 1000
+
+
+def test_set_default_env():
+ """
+ Test the `ipalib.config.set_default_env` function.
"""
# Make sure we don't overwrite any properties
- env = dict(
+ d = dict(
query_dns = False,
server = ('first', 'second'),
realm = 'myrealm',
# test right conversions
server_context = 'off',
)
- d = config.generate_env(env)
- assert d['server_context'] == False
- assert d['query_dns'] == False
+ env = config.Environment()
+ config.set_default_env(env)
+ env.update(d)
+ assert env['server_context'] == False
+ assert env['query_dns'] == False
# Make sure the servers is overwrote properly (that it is still LazyProp)
- iter = d['server'].get_value()
+ iter = env['server']
assert iter.next() == 'first'
assert iter.next() == 'second'
@@ -59,13 +141,13 @@ def test_LazyProp():
return 1
# Basic sanity testing with no initial value
- prop = config.LazyProp(dummy)
+ prop = config.LazyProp(int, dummy)
assert prop.get_value() == 1
prop.set_value(2)
assert prop.get_value() == 2
# Basic sanity testing with initial value
- prop = config.LazyProp(dummy, 3)
+ prop = config.LazyProp(int, dummy, 3)
assert prop.get_value() == 3
prop.set_value(4)
assert prop.get_value() == 4
@@ -81,14 +163,14 @@ def test_LazyIter():
yield 2
# Basic sanity testing with no initial value
- prop = config.LazyIter(dummy)
+ prop = config.LazyIter(int, dummy)
iter = prop.get_value()
assert iter.next() == 1
assert iter.next() == 2
raises(StopIteration, iter.next)
# Basic sanity testing with initial value
- prop = config.LazyIter(dummy, 0)
+ prop = config.LazyIter(int, dummy, 0)
iter = prop.get_value()
assert iter.next() == 0
assert iter.next() == 1
diff --git a/tests/test_ipalib/test_crud.py b/tests/test_ipalib/test_crud.py
index d7e6b51f3..9a207cce9 100644
--- a/tests/test_ipalib/test_crud.py
+++ b/tests/test_ipalib/test_crud.py
@@ -40,7 +40,7 @@ class CrudChecker(ClassChecker):
frontend.Method,
frontend.Property,
)
- api.env.update(config.generate_env())
+ config.set_default_env(api.env)
class user(frontend.Object):
takes_params = (
'givenname',
diff --git a/tests/test_ipalib/test_frontend.py b/tests/test_ipalib/test_frontend.py
index 9ab0504b2..c57428867 100644
--- a/tests/test_ipalib/test_frontend.py
+++ b/tests/test_ipalib/test_frontend.py
@@ -894,7 +894,7 @@ class test_Object(ClassChecker):
frontend.Method,
frontend.Property,
)
- api.env.update(config.generate_env())
+ config.set_default_env(api.env)
api.finalize()
# Test with no primary keys:
@@ -951,7 +951,7 @@ class test_Object(ClassChecker):
frontend.Property,
backend.Backend,
)
- api.env.update(config.generate_env())
+ config.set_default_env(api.env)
class ldap(backend.Backend):
whatever = 'It worked!'
api.register(ldap)
diff --git a/tests/test_ipalib/test_plugable.py b/tests/test_ipalib/test_plugable.py
index dec893a9c..610117971 100644
--- a/tests/test_ipalib/test_plugable.py
+++ b/tests/test_ipalib/test_plugable.py
@@ -659,85 +659,6 @@ class test_NameSpace(ClassChecker):
'NameSpace(<%d members>, sort=%r)' % (cnt, sort)
-def test_Environment():
- """
- Test the `ipalib.plugable.Environment` class.
- """
- # This has to be the same as iter_cnt
- control_cnt = 0
- class prop_class:
- def __init__(self, val):
- self._val = val
- def get_value(self):
- return self._val
-
- class iter_class(prop_class):
- # Increment this for each time iter_class yields
- iter_cnt = 0
- def get_value(self):
- for item in self._val:
- self.__class__.iter_cnt += 1
- yield item
-
- # Tests for basic functionality
- basic_tests = (
- ('a', 1),
- ('b', 'basic_foo'),
- ('c', ('basic_bar', 'basic_baz')),
- )
- # Tests with prop classes
- prop_tests = (
- ('d', prop_class(2), 2),
- ('e', prop_class('prop_foo'), 'prop_foo'),
- ('f', prop_class(('prop_bar', 'prop_baz')), ('prop_bar', 'prop_baz')),
- )
- # Tests with iter classes
- iter_tests = (
- ('g', iter_class((3, 4, 5)), (3, 4, 5)),
- ('h', iter_class(('iter_foo', 'iter_bar', 'iter_baz')),
- ('iter_foo', 'iter_bar', 'iter_baz')
- ),
- )
-
- # Set all the values
- env = plugable.Environment()
- for name, val in basic_tests:
- env[name] = val
- for name, val, dummy in prop_tests:
- env[name] = val
- for name, val, dummy in iter_tests:
- env[name] = val
-
- # Test if the values are correct
- for name, val in basic_tests:
- assert env[name] == val
- for name, dummy, val in prop_tests:
- assert env[name] == val
- # Test if the get_value() function is called only when needed
- for name, dummy, correct_values in iter_tests:
- values_in_env = []
- for val in env[name]:
- control_cnt += 1
- assert iter_class.iter_cnt == control_cnt
- values_in_env.append(val)
- assert tuple(values_in_env) == correct_values
-
- # Test __setattr__()
- env.spam = 'ham'
- assert env.spam == 'ham'
-
- # Test if we throw AttributeError exception when trying to overwrite
- # existing value, or delete it
- raises(AttributeError, setitem, env, 'a', 1)
- raises(AttributeError, setattr, env, 'a', 1)
- raises(AttributeError, delitem, env, 'a')
- raises(AttributeError, delattr, env, 'a')
- raises(AttributeError, plugable.Environment.update, env, dict(a=1000))
- # This should be silently ignored
- env.update(dict(a=1000), True)
- assert env.a != 1000
-
-
def test_Registrar():
"""
Test the `ipalib.plugable.Registrar` class