diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-01 03:12:17 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-01 03:12:17 +0000 |
commit | 31fc955355ac8d873b82d129021f599f820c2694 (patch) | |
tree | 85e686aefaffeddd6307e4e0eeff4447c85727e3 /ipalib/tests/unit_common.py | |
parent | f53dec2600f95246a72fa3c847a485d2a94edfa7 (diff) | |
download | freeipa.git-31fc955355ac8d873b82d129021f599f820c2694.tar.gz freeipa.git-31fc955355ac8d873b82d129021f599f820c2694.tar.xz freeipa.git-31fc955355ac8d873b82d129021f599f820c2694.zip |
34: Added tests.unit_common with frequently used utility functions; split ro __setattr__, __delattr__ methods out of Proxy and into new ReadOnly base class; added corresponding unit tests
Diffstat (limited to 'ipalib/tests/unit_common.py')
-rw-r--r-- | ipalib/tests/unit_common.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/ipalib/tests/unit_common.py b/ipalib/tests/unit_common.py new file mode 100644 index 00000000..f5c7f0f9 --- /dev/null +++ b/ipalib/tests/unit_common.py @@ -0,0 +1,63 @@ +# Authors: +# Jason Gerard DeRose <jderose@redhat.com> +# +# Copyright (C) 2008 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; version 2 only +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +""" +Utility functions for unit tests. +""" + + +def no_set(obj, name): + """ + Tests that attribute cannot be set. + """ + raised = False + try: + setattr(obj, name, 'some_new_obj') + except AttributeError: + raised = True + assert raised + + +def no_del(obj, name): + """ + Tests that attribute cannot be deleted. + """ + raised = False + try: + delattr(obj, name) + except AttributeError: + raised = True + assert raised + + +def read_only(obj, name): + """ + Tests that attribute is read-only. Returns attribute. + """ + assert isinstance(obj, object) + assert hasattr(obj, name) + + # Test that it cannot be set: + no_set(obj, name) + + # Test that it cannot be deleted: + no_del(obj, name) + + # Return the attribute + return getattr(obj, name) |