diff options
author | Alois Mahdal <amahdal@redhat.com> | 2014-06-18 23:39:43 +0200 |
---|---|---|
committer | Alois Mahdal <amahdal@redhat.com> | 2014-07-01 16:13:00 +0200 |
commit | 32bbfe5533e5d625732ba0a68c2c1c8d6083b0b1 (patch) | |
tree | d3117d59fa780059a4d501d4f2cfc3e4a6f47191 | |
parent | e4f0006ad39997b227123731999473eaaff85db9 (diff) | |
download | openlmi-providers-32bbfe5533e5d625732ba0a68c2c1c8d6083b0b1.tar.gz openlmi-providers-32bbfe5533e5d625732ba0a68c2c1c8d6083b0b1.tar.xz openlmi-providers-32bbfe5533e5d625732ba0a68c2c1c8d6083b0b1.zip |
Extend test to groups as well
-rw-r--r-- | src/account/test/TestIndicationEventStream.py | 116 | ||||
-rw-r--r-- | src/account/test/common.py | 70 |
2 files changed, 179 insertions, 7 deletions
diff --git a/src/account/test/TestIndicationEventStream.py b/src/account/test/TestIndicationEventStream.py index 4281995..cc62673 100644 --- a/src/account/test/TestIndicationEventStream.py +++ b/src/account/test/TestIndicationEventStream.py @@ -61,7 +61,7 @@ class TestIndicationEventStream(IndicationStreamTestCase): # ............ # the simplest - def test_create(self): + def test_account_create(self): case = { 'subscriptions': 'ac', 'handlers': 'pr', @@ -71,7 +71,7 @@ class TestIndicationEventStream(IndicationStreamTestCase): } self.check(case) - def test_delete(self): + def test_account_delete(self): case = { 'subscriptions': 'ad', 'handlers': 'pr', @@ -81,7 +81,7 @@ class TestIndicationEventStream(IndicationStreamTestCase): } self.check(case) - def test_round(self): + def test_account_round(self): case = { 'subscriptions': 'ac,ad', 'handlers': '2pr', @@ -91,11 +91,41 @@ class TestIndicationEventStream(IndicationStreamTestCase): } self.check(case) + def test_group_create(self): + case = { + 'subscriptions': 'gc', + 'handlers': 'pr', + 'actions': 'gc', + 'expected_ind_stream': 'ac', + 'expected_si_stream': 'g', + } + self.check(case) + + def test_group_delete(self): + case = { + 'subscriptions': 'gd', + 'handlers': 'pr', + 'actions': 'gc,gd', + 'expected_ind_stream': 'ad', + 'expected_si_stream': 'g', + } + self.check(case) + + def test_group_round(self): + case = { + 'subscriptions': 'gc,gd', + 'handlers': '2pr', + 'actions': 'gc,gd', + 'expected_ind_stream': 'ac,ad', + 'expected_si_stream': '2g', + } + self.check(case) + # ................ # longer sequences @lmi.test.util.mark_tedious - def test_create_50(self): + def test_account_create_50(self): case = { 'subscriptions': 'ac', 'handlers': 'pr', @@ -107,7 +137,7 @@ class TestIndicationEventStream(IndicationStreamTestCase): self.check(case) @lmi.test.util.mark_tedious - def test_delete_50(self): + def test_account_delete_50(self): case = { 'subscriptions': 'ad', 'handlers': 'pr', @@ -119,7 +149,7 @@ class TestIndicationEventStream(IndicationStreamTestCase): self.check(case) @lmi.test.util.mark_tedious - def test_round_50(self): + def test_account_round_50(self): case = { 'subscriptions': 'ac,ad', 'handlers': '2pr', @@ -130,10 +160,46 @@ class TestIndicationEventStream(IndicationStreamTestCase): self.driver_options['delay_chillout'] = 20 self.check(case) + @lmi.test.util.mark_tedious + def test_group_create_50(self): + case = { + 'subscriptions': 'gc', + 'handlers': 'pr', + 'actions': '50gc,50gd', + 'expected_ind_stream': '50ac', + 'expected_si_stream': '50g', + } + self.driver_options['delay_chillout'] = 20 + self.check(case) + + @lmi.test.util.mark_tedious + def test_group_delete_50(self): + case = { + 'subscriptions': 'gd', + 'handlers': 'pr', + 'actions': '50gc,50gd', + 'expected_ind_stream': '50ad', + 'expected_si_stream': '50g', + } + self.driver_options['delay_chillout'] = 20 + self.check(case) + + @lmi.test.util.mark_tedious + def test_group_round_50(self): + case = { + 'subscriptions': 'gc,gd', + 'handlers': '2pr', + 'actions': '50gc,50gd', + 'expected_ind_stream': '50ac,50ad', + 'expected_si_stream': '100g', + } + self.driver_options['delay_chillout'] = 20 + self.check(case) + # ................................. # uneven handlers vs. subscriptions - def test_numbased(self): + def test_account_numbased(self): items = "ac", "ac", "a" # action, indication, source instance variations = [ # (handlers, subs, acts, expect) @@ -168,3 +234,39 @@ class TestIndicationEventStream(IndicationStreamTestCase): (2, 2, 2, 4), ] self.check_numbased(variations, items) + + def test_group_numbased(self): + items = "gc", "ac", "g" # action, indication, source instance + variations = [ + # (handlers, subs, acts, expect) + # ^ count of indications, assumed + # equal to count of source instances + (0, 0, 0, 0), + (0, 0, 1, 0), + (0, 0, 2, 0), + (0, 1, 0, 0), + (0, 1, 1, 0), + (0, 1, 2, 0), + (0, 2, 0, 0), + (0, 2, 1, 0), + (0, 2, 2, 0), + (1, 0, 0, 0), + (1, 0, 1, 0), + (1, 0, 2, 0), + (1, 1, 0, 0), + (1, 1, 1, 1), + (1, 1, 2, 2), + (1, 2, 0, 0), + (1, 2, 1, 1), + (1, 2, 2, 2), + (2, 0, 0, 0), + (2, 0, 1, 0), + (2, 0, 2, 0), + (2, 1, 0, 0), + (2, 1, 1, 1), + (2, 1, 2, 2), + (2, 2, 0, 0), + (2, 2, 1, 2), + (2, 2, 2, 4), + ] + self.check_numbased(variations, items) diff --git a/src/account/test/common.py b/src/account/test/common.py index 01f7ecf..632a159 100644 --- a/src/account/test/common.py +++ b/src/account/test/common.py @@ -257,6 +257,58 @@ class TestUserSet(object): UserOps.clean_account(self._our_users.pop()) +class TestGroupSet(object): + """ + Class to hold list of "testing" groups, able to make up new names + """ + + def __init__(self, prefix="test_group_", strength=8): + self.prefix = prefix + self.strength = strength + self._our_groups = set() + + def _new_name(self): + """ + Make up a name that is not yet on the system + """ + name = None + existing = UserOps.list_groups() + while not name or name in existing: + name = random_string(strength=self.strength, prefix=self.prefix) + return name + + def add(self, name=None): + """ + Create a testing group; return the name + """ + name = name if name else self._new_name() + UserOps.create_account(name) + self._our_groups.add(name) + return name + + def remove(self, name=None): + """ + Remove given group or a random one; return the removed name + """ + try: + name = name if name else next(iter(self._our_groups)) + assert name in self._our_groups + except StopIteration: # from above next() call + raise ValueError("no more testing groups") + except AssertionError: + raise ValueError("not our testing group: %s" % name) + UserOps.clean_account(name) + self._our_groups.remove(name) + return name + + def remove_all(self): + """ + Remove all testing groups + """ + while self._our_groups: + UserOps.clean_account(self._our_groups.pop()) + + class AccountIndicationTestDriver(IndicationTestDriver): """ Test driver for account indications. @@ -273,6 +325,7 @@ class AccountIndicationTestDriver(IndicationTestDriver): 'LMI_AccountInstanceCreationIndication': 'ac', 'LMI_AccountInstanceDeletionIndication': 'ad', 'LMI_Account': 'a', + 'LMI_Group': 'g', } self.tus = TestUserSet( @@ -280,8 +333,15 @@ class AccountIndicationTestDriver(IndicationTestDriver): strength=self.options['gen_strength'] ) + self.tgs = TestGroupSet( + prefix=self.options['gen_prefix'] + '_group_', + strength=self.options['gen_strength'] + ) + self.known_actions['ac'] = self.tus.add self.known_actions['ad'] = self.tus.remove + self.known_actions['gc'] = self.tgs.add + self.known_actions['gd'] = self.tgs.remove self.known_queries['ac'] = ( 'select * from LMI_AccountInstanceCreationIndication' @@ -291,5 +351,15 @@ class AccountIndicationTestDriver(IndicationTestDriver): 'select * from LMI_AccountInstanceDeletionIndication' ' where SourceInstance isa LMI_Account' ) + self.known_queries['gc'] = ( + 'select * from LMI_AccountInstanceCreationIndication' + ' where SourceInstance isa LMI_Group' + ) + self.known_queries['gd'] = ( + 'select * from LMI_AccountInstanceDeletionIndication' + ' where SourceInstance isa LMI_Group' + ) self.cleanup_handlers.append(self.tus.remove_all) + self.cleanup_handlers.append(self.tgs.remove_all) + |