diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-07-19 07:43:48 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-07-19 07:43:48 +0000 |
commit | 91adc9c2d060b65d96a8515d08fc7192be79da83 (patch) | |
tree | b6490f3c526e04c63c73c1a21fa0a79b2fd6ffcf /ipalib/tests/test_base.py | |
parent | e8257ad5311a4011625ed28bf6b308b1a9b43776 (diff) | |
download | freeipa.git-91adc9c2d060b65d96a8515d08fc7192be79da83.tar.gz freeipa.git-91adc9c2d060b65d96a8515d08fc7192be79da83.tar.xz freeipa.git-91adc9c2d060b65d96a8515d08fc7192be79da83.zip |
6: Fleshed out API.register_command, made correpsonding unit tests much more rigorous
Diffstat (limited to 'ipalib/tests/test_base.py')
-rw-r--r-- | ipalib/tests/test_base.py | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/ipalib/tests/test_base.py b/ipalib/tests/test_base.py index e0e2d8e8..bf727ed6 100644 --- a/ipalib/tests/test_base.py +++ b/ipalib/tests/test_base.py @@ -184,7 +184,7 @@ class test_NameSpace: raised = False try: setattr(ns, key, value) - except exceptions.SetAttributeError: + except exceptions.SetError: raised = True assert raised assert getattr(ns, key, None) != value @@ -238,13 +238,17 @@ class test_NameSpace: assert len(kw) == len(ns) == 3 -class test_Command: - def new(self): - return base.Command() +class test_Command(ClassChecker): + class cmd_some_command(base.Command): + pass + cls = cmd_some_command def test_fresh(self): c = self.new() - + assert isinstance(c, base.Named) + assert c.name == 'some_command' + assert c.name_cli == 'some-command' + assert callable(c) class test_API: @@ -267,19 +271,46 @@ class test_API: assert read_only(api, 'objects') is None def test_register_command(self): - class my_command(base.Command): + api = self.new() + + class cmd_my_command(base.Command): pass - class another_command(base.Command): + class cmd_another_command(base.Command): pass - api = self.new() - api.register_command(my_command) + # Check that RegistrationError is raised when registering anything + # other than a subclass of Command: + for obj in [object, cmd_my_command()]: + raised = False + try: + api.register_command(obj) + except exceptions.RegistrationError: + raised = True + assert raised - # Check that RegistrationError is raised passing something not - # sub-classed from Command: + # Check that command registration works: + api.register_command(cmd_my_command) + api.register_command(cmd_another_command) + + # Check that DuplicateError is raised when registering the same class + # twice: + raised = False + try: + api.register_command(cmd_my_command) + except exceptions.DuplicateError: + raised = True + assert raised + + # Check that OverrideError is raised when registering same name + # without override = True: + class cmd_my_command(base.Command): + pass raised = False try: - api.register_command(object) - except exceptions.RegistrationError: + api.register_command(cmd_my_command) + except exceptions.OverrideError: raised = True assert raised + + # Check that override=True works: + api.register_command(cmd_my_command, override=True) |