|
13 | 13 | # under the License. |
14 | 14 | # |
15 | 15 |
|
| 16 | +import contextlib |
16 | 17 | import copy |
| 18 | + |
17 | 19 | import mock |
18 | 20 |
|
19 | 21 | from openstackclient.identity.v3 import user |
@@ -944,6 +946,52 @@ def test_user_set_disable(self): |
944 | 946 | ) |
945 | 947 |
|
946 | 948 |
|
| 949 | +class TestUserSetPassword(TestUser): |
| 950 | + |
| 951 | + def setUp(self): |
| 952 | + super(TestUserSetPassword, self).setUp() |
| 953 | + self.cmd = user.SetPasswordUser(self.app, None) |
| 954 | + |
| 955 | + @staticmethod |
| 956 | + @contextlib.contextmanager |
| 957 | + def _mock_get_password(*passwords): |
| 958 | + mocker = mock.Mock(side_effect=passwords) |
| 959 | + with mock.patch("openstackclient.common.utils.get_password", mocker): |
| 960 | + yield |
| 961 | + |
| 962 | + def test_user_password_change(self): |
| 963 | + current_pass = 'old_pass' |
| 964 | + new_pass = 'new_pass' |
| 965 | + arglist = [ |
| 966 | + '--password', new_pass, |
| 967 | + ] |
| 968 | + verifylist = [ |
| 969 | + ('password', new_pass), |
| 970 | + ] |
| 971 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 972 | + |
| 973 | + # Mock getting user current password. |
| 974 | + with self._mock_get_password(current_pass): |
| 975 | + self.cmd.take_action(parsed_args) |
| 976 | + |
| 977 | + self.users_mock.update_password.assert_called_with( |
| 978 | + current_pass, new_pass |
| 979 | + ) |
| 980 | + |
| 981 | + def test_user_create_password_prompt(self): |
| 982 | + current_pass = 'old_pass' |
| 983 | + new_pass = 'new_pass' |
| 984 | + parsed_args = self.check_parser(self.cmd, [], []) |
| 985 | + |
| 986 | + # Mock getting user current and new password. |
| 987 | + with self._mock_get_password(current_pass, new_pass): |
| 988 | + self.cmd.take_action(parsed_args) |
| 989 | + |
| 990 | + self.users_mock.update_password.assert_called_with( |
| 991 | + current_pass, new_pass |
| 992 | + ) |
| 993 | + |
| 994 | + |
947 | 995 | class TestUserShow(TestUser): |
948 | 996 |
|
949 | 997 | def setUp(self): |
|
0 commit comments