From fdd309f383401550b425fef148ebcd74f7cfd323 Mon Sep 17 00:00:00 2001 From: Jiri Podivin Date: Mon, 8 Mar 2021 17:22:06 +0100 Subject: [PATCH] New utils.py tests Unit tests covering get_nested and geth_auth_session functions. Further tests will be submitted as a follow up dependent review. Closes-Bug: #1922726 Signed-off-by: Jiri Podivin Change-Id: I0ed44d1014d10e632beea44f2665a256453c2499 --- tripleo_validations/tests/test_utils.py | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tripleo_validations/tests/test_utils.py b/tripleo_validations/tests/test_utils.py index 928d0a700..e8598a37a 100644 --- a/tripleo_validations/tests/test_utils.py +++ b/tripleo_validations/tests/test_utils.py @@ -14,6 +14,11 @@ import collections +try: + from unittest import mock +except ImportError: + import mock + from tripleo_validations.tests import base from tripleo_validations import utils @@ -118,3 +123,40 @@ class TestGetNested(base.TestCase): self.assertEqual( utils.get_nested(resources, 'foo', PATH[:])[0], 'old') + + +class TestGetAuthSession(base.TestCase): + """Tests for tripleo_validations.utils.get_auth_session function. + """ + + @mock.patch('keystoneauth1.session.Session') + @mock.patch('keystoneauth1.identity.generic.Token') + def test_get_auth_session_token(self, mock_token, mock_session): + + fake_auth_vars = { + 'auth_url': 'http://www.fizz.bar/auth', + 'username': 'buzz', + 'project_name': 'project_foo', + 'os_auth_token': 'token', + 'password': 'password', + 'cacert': 'fizz_buzz_cert', + 'timeout': '999' + } + + utils.get_auth_session(fake_auth_vars) + + @mock.patch('keystoneauth1.session.Session') + @mock.patch('keystoneauth1.identity.generic.Password') + def test_get_auth_session_password(self, mock_pass, mock_session): + + fake_auth_vars = {} + + utils.get_auth_session(fake_auth_vars) + + @mock.patch('keystoneauth1.session.Session') + @mock.patch('keystoneauth1.identity.generic.Password') + def test_get_auth_session_empty_vars(self, mock_pass, mock_session): + + fake_auth_vars = {} + + utils.get_auth_session(fake_auth_vars)