Tests: Add system tests for groupadd in test_groupadd.py - #1693
Conversation
cbb8850 to
d010ea7
Compare
8b0a946 to
0c8cf07
Compare
| shadow.groupadd() | ||
| assert exc_info.value.rc == 2, f"Expected return code 2(invalid usage), got {exc_info.value.rc}" |
There was a problem hiding this comment.
Add an empty line between these two
| args_list = shlex.split(args[0][0] if args[0] else "") | ||
| name = args_list[-1] if args_list else "" |
There was a problem hiding this comment.
args[0][0] takes the first character of the argument, not the whole argument string.
I think a good approach would be to have the defensive programming first and then handle the parsing:
if not args or not args[0]:
return {"name": ""}
args_list = shlex.split(args[0])
name = args_list[-1] if args_list else ""
There was a problem hiding this comment.
Hi @ikerexxe with this change, test fails with error:
FAILED tests/test_groupadd_working.py::test_groupadd__no_group (shadow) - IndexError: tuple index out of range
I think an additional change would be required here:
shadow/tests/system/framework/roles/shadow.py
Line 233 in 5e7ae07
| @pytest.mark.topology(KnownTopology.Shadow) | ||
| def test_groupadd__usage(shadow: Shadow): | ||
| """ | ||
| :title: Groupadd command displays usage with -h option and exits successfully |
There was a problem hiding this comment.
Let's avoid using -h option and only state what the test does display usage
| :setup: | ||
| 1. None required | ||
| :steps: | ||
| 1. Run groupadd command with -h option |
There was a problem hiding this comment.
No need to mention with -h option, as that's the how
| 1. None required | ||
| :steps: | ||
| 1. Run groupadd command with -h option | ||
| 2. Verify that groupadd command exits successfully |
There was a problem hiding this comment.
You are missing an additional step here: Check usage information
| 1. Run groupadd command with -h option | ||
| 2. Verify that groupadd command exits successfully | ||
| :expectedresults: | ||
| 1. Command shows usage help |
There was a problem hiding this comment.
I'd say this should be Command runs successfully
| 2. Verify that groupadd command exits successfully | ||
| :expectedresults: | ||
| 1. Command shows usage help | ||
| 2. groupadd command completes successfully and displays usage information |
There was a problem hiding this comment.
In this step you are checking that the command run successfully, thus update the message accordingly
| :expectedresults: | ||
| 1. Command shows usage help | ||
| 2. groupadd command completes successfully and displays usage information | ||
| :customerscenario: False |
There was a problem hiding this comment.
Missing another step here to Check usage information
| ) | ||
| def test_groupadd__invalid_usage(shadow: Shadow, args: str): | ||
| """ | ||
| :title: Groupadd command fails with invalid usage |
| 1. Run groupadd command with invalid arguments | ||
| 2. Verify that groupadd command fails | ||
| :expectedresults: | ||
| 1. Command with invalid argument fails |
There was a problem hiding this comment.
I'd say this should be Attempt to create groups or something similar
This is Python transformation of the test located in `tests/grouptools/groupadd/22_groupadd_usage/groupadd.test` which checks that `groupadd` command shows usage with -h option. Signed-off-by: Akshay Sakure <asakure@redhat.com>
This patch fixes the issue in shadow.py file to handle empty or missing arguments in _parse_args and groupadd so shadow.groupadd() does not raise TypeError or IndexError. Signed-off-by: Akshay Sakure <asakure@redhat.com>
This is Python transformation of the test located in `tests/grouptools/groupadd/23_groupadd_no_groups/groupadd.test` which checks that `groupadd` fails when no groupname is mentioned. Signed-off-by: Akshay Sakure <asakure@redhat.com>
This is Python transformation of the test located in `tests/grouptools/groupadd/24_groupadd_2_groups/groupadd.test` which checks that `groupadd` command fails when two groupnames are mentioned. It also parametrize python tests 23 and 24 into single test. Signed-off-by: Akshay Sakure <asakure@redhat.com>
0c8cf07 to
e632b96
Compare
Add system tests for groupadd in test_groupadd.py for
existing bash tests with numbering 22, 23, 24.