summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit/identity
diff options
context:
space:
mode:
authorNicolas Belouin <nicolas.belouin@gandi.net>2022-01-14 15:44:11 +0100
committerNicolas Belouin <nicolas.belouin@gandi.net>2022-04-12 06:26:18 +0000
commit64e4520b2a79b9046a791f5e3729f5cbfc2d3fa5 (patch)
tree25863212b91ab41998abc6455a495ebe60b01fa1 /openstackclient/tests/unit/identity
parentdabaec5a7b1b9786a8f91eebef738bf755faf059 (diff)
downloadpython-openstackclient-64e4520b2a79b9046a791f5e3729f5cbfc2d3fa5.tar.gz
Add trustor and trustee filtering to trusts list
The keystone API supports filtering trusts by trustor and/or trustee. Also adds a shortcut parameter to get trusts with current user as trustee or trustor. Signed-off-by: Nicolas Belouin <nicolas.belouin@gandi.net> Change-Id: I00ed2b68cf8ada214a59f640f4f0a5c9dbc37063
Diffstat (limited to 'openstackclient/tests/unit/identity')
-rw-r--r--openstackclient/tests/unit/identity/v3/test_trust.py108
1 files changed, 107 insertions, 1 deletions
diff --git a/openstackclient/tests/unit/identity/v3/test_trust.py b/openstackclient/tests/unit/identity/v3/test_trust.py
index d8cfc59f..d530adf5 100644
--- a/openstackclient/tests/unit/identity/v3/test_trust.py
+++ b/openstackclient/tests/unit/identity/v3/test_trust.py
@@ -206,7 +206,113 @@ class TestTrustList(TestTrust):
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
- self.trusts_mock.list.assert_called_with()
+ self.trusts_mock.list.assert_called_with(
+ trustor_user=None,
+ trustee_user=None,
+ )
+
+ collist = ('ID', 'Expires At', 'Impersonation', 'Project ID',
+ 'Trustee User ID', 'Trustor User ID')
+ self.assertEqual(collist, columns)
+ datalist = ((
+ identity_fakes.trust_id,
+ identity_fakes.trust_expires,
+ identity_fakes.trust_impersonation,
+ identity_fakes.project_id,
+ identity_fakes.user_id,
+ identity_fakes.user_id
+ ), )
+ self.assertEqual(datalist, tuple(data))
+
+ def test_trust_list_auth_user(self):
+ auth_ref = self.app.client_manager.auth_ref = mock.Mock()
+ auth_ref.user_id.return_value = identity_fakes.user_id
+
+ arglist = ['--auth-user']
+ verifylist = [
+ ('trustor', None),
+ ('trustee', None),
+ ('authuser', True),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class Lister in cliff, abstract method take_action()
+ # returns a tuple containing the column names and an iterable
+ # containing the data to be listed.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.trusts_mock.list.assert_any_call(
+ trustor_user=self.users_mock.get()
+ )
+ self.trusts_mock.list.assert_any_call(
+ trustee_user=self.users_mock.get()
+ )
+
+ collist = ('ID', 'Expires At', 'Impersonation', 'Project ID',
+ 'Trustee User ID', 'Trustor User ID')
+ self.assertEqual(collist, columns)
+ datalist = ((
+ identity_fakes.trust_id,
+ identity_fakes.trust_expires,
+ identity_fakes.trust_impersonation,
+ identity_fakes.project_id,
+ identity_fakes.user_id,
+ identity_fakes.user_id
+ ), )
+ self.assertEqual(datalist, tuple(data))
+
+ def test_trust_list_trustee(self):
+ arglist = ['--trustee', identity_fakes.user_name]
+ verifylist = [
+ ('trustor', None),
+ ('trustee', identity_fakes.user_name),
+ ('authuser', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class Lister in cliff, abstract method take_action()
+ # returns a tuple containing the column names and an iterable
+ # containing the data to be listed.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ print(self.trusts_mock.list.call_args_list)
+ self.trusts_mock.list.assert_any_call(
+ trustee_user=self.users_mock.get(),
+ trustor_user=None,
+ )
+
+ collist = ('ID', 'Expires At', 'Impersonation', 'Project ID',
+ 'Trustee User ID', 'Trustor User ID')
+ self.assertEqual(collist, columns)
+ datalist = ((
+ identity_fakes.trust_id,
+ identity_fakes.trust_expires,
+ identity_fakes.trust_impersonation,
+ identity_fakes.project_id,
+ identity_fakes.user_id,
+ identity_fakes.user_id
+ ), )
+ self.assertEqual(datalist, tuple(data))
+
+ def test_trust_list_trustor(self):
+ arglist = ['--trustor', identity_fakes.user_name]
+ verifylist = [
+ ('trustee', None),
+ ('trustor', identity_fakes.user_name),
+ ('authuser', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class Lister in cliff, abstract method take_action()
+ # returns a tuple containing the column names and an iterable
+ # containing the data to be listed.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ print(self.trusts_mock.list.call_args_list)
+ self.trusts_mock.list.assert_any_call(
+ trustor_user=self.users_mock.get(),
+ trustee_user=None,
+ )
collist = ('ID', 'Expires At', 'Impersonation', 'Project ID',
'Trustee User ID', 'Trustor User ID')