|
1 | 1 | """
|
2 | 2 | Test module for extauth_hook_ad
|
3 | 3 | """
|
4 |
| -#pylint: disable=invalid-name |
5 |
| -import sys |
| 4 | + |
| 5 | +import logging |
6 | 6 | import os
|
| 7 | +import sys |
7 | 8 | from unittest import TestCase
|
8 |
| -from mock import MagicMock, patch |
9 |
| - |
10 |
| -import pytest |
| 9 | +from unittest.mock import MagicMock, patch |
11 | 10 |
|
12 | 11 | # mock modules to avoid dependencies
|
13 | 12 | sys.modules["XenAPIPlugin"] = MagicMock()
|
14 | 13 | sys.modules["XenAPI"] = MagicMock()
|
15 | 14 | # pylint: disable=wrong-import-position
|
16 | 15 | # Import must after mock modules
|
17 | 16 | from extauth_hook_ad import StaticSSHPam, NssConfig, SshdConfig, UsersList, GroupsList
|
| 17 | +from extauth_hook_ad import run_cmd |
| 18 | + |
| 19 | +def test_run_cmd(caplog): |
| 20 | + """Assert the current buggy behavior of the run_cmd function after py3 migration""" |
| 21 | + cmd = ["echo", " Hello World! "] |
18 | 22 |
|
| 23 | + # Call the function under test, check the return value and capture the log message |
| 24 | + with caplog.at_level(logging.DEBUG): |
| 25 | + assert run_cmd(cmd) is None # The return value is None (not used in the code) |
19 | 26 |
|
20 |
| -if sys.version_info < (3, ): # pragma: no cover |
21 |
| - pytest.skip(allow_module_level=True) |
| 27 | + # Assert the log message |
| 28 | + assert caplog.records[0].message == "%s -> Hello World!" % (cmd) |
22 | 29 |
|
| 30 | + # Test the case where the command fails: |
| 31 | + assert run_cmd(["bad command"]) is None |
| 32 | + assert caplog.records[1].message == "Failed to run command ['bad command']" |
23 | 33 |
|
24 | 34 | def line_exists_in_config(lines, line):
|
25 | 35 | """
|
|
0 commit comments