diff options
author | Ray Strode <rstrode@redhat.com> | 2023-03-27 11:45:51 -0400 |
---|---|---|
committer | Ray Strode <rstrode@redhat.com> | 2023-03-27 15:13:47 -0400 |
commit | 24645afea0da48496914614b4c0f0ab1d3d743d5 (patch) | |
tree | 5d03b31b2b6b6e2b3b9f9908fe67eef0153c7897 | |
parent | c7554931bbb673316a2c5541e0de4ddf25495a2f (diff) |
tests: Add test for multiple in-flight get_user calls
AccountsService doesn't currently handle act_user_manager_get_user
getting called multiple times in quick succession for the same
user.
This commit adds a test to test that.
-rw-r--r-- | tests/test-libaccountsservice.py | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/tests/test-libaccountsservice.py b/tests/test-libaccountsservice.py index 76096fa..723ab51 100644 --- a/tests/test-libaccountsservice.py +++ b/tests/test-libaccountsservice.py @@ -25,11 +25,8 @@ try: except (ImportError, ValueError): have_accounts_service = False - -@unittest.skipUnless(have_accounts_service, - 'AccountsService gi introspection not available') -class TestAccountsService(dbusmock.DBusTestCase): - '''Test mocking AccountsService''' +class AccountsServiceTestBase(dbusmock.DBusTestCase): + '''Base class for accountsservice test cases''' @classmethod def setUpClass(cls): @@ -40,10 +37,11 @@ class TestAccountsService(dbusmock.DBusTestCase): def setUp(self): super().setUp() - template = os.path.join( - os.path.dirname(__file__), 'dbusmock/accounts_service.py') - (self._mock, self._mock_obj) = self.spawn_server_template( - template, {}, stdout=subprocess.PIPE) + if not hasattr(self, '_mock'): + template = os.path.join( + os.path.dirname(__file__), 'dbusmock/accounts_service.py') + (self._mock, self._mock_obj) = self.spawn_server_template( + template, {}, stdout=subprocess.PIPE) self._manager = AccountsService.UserManager.get_default() while not self._manager.props.is_loaded: self.ctx.iteration(True) @@ -84,6 +82,47 @@ class TestAccountsService(dbusmock.DBusTestCase): self.ctx.iteration(True) user.disconnect(conn_id) +@unittest.skipUnless(have_accounts_service, + 'AccountsService gi introspection not available') +class TestAccountsServicePreExistingUser(AccountsServiceTestBase): + '''Test mocking AccountsService with pre-existing user''' + def setUp(self): + template = os.path.join( + os.path.dirname(__file__), 'dbusmock/accounts_service.py') + (self._mock, self._mock_obj) = self.spawn_server_template( + template, {'users': { 2001: 'pizza' }}, stdout=subprocess.PIPE) + super().setUp() + + def test_multiple_inflight_get_user_by_id_calls(self): + user_objects = [] + + for double_instances in range(5): + user_objects.append(self._manager.get_user_by_id(2001)) + user_objects.append(self._manager.get_user('pizza')) + + for second in range(10): + done = True + for user in user_objects: + if not user.is_loaded(): + self.ctx.iteration(True) + done = False + if done: + break + else: + time.sleep(1) + + for instance in range(len(user_objects)): + self.assertTrue(user_objects[instance].is_loaded()) + + for user in user_objects: + self.assertEquals(user.get_user_name(), 'pizza') + self.assertEquals(user.get_uid(), 2001) + +@unittest.skipUnless(have_accounts_service, + 'AccountsService gi introspection not available') +class TestAccountsService(AccountsServiceTestBase): + '''Test mocking AccountsService''' + def test_empty(self): self.assertTrue(self._manager.props.is_loaded) self.assertFalse(self._manager.list_users()) |