Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

Commit 11d8506

Browse files
authored
Merge pull request #32 from EvgeneOskin/feature/fix-listing-groups
Fix listing groups
2 parents a455f76 + 18d8aa3 commit 11d8506

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

termius/handlers/group.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ def take_action(self, parsed_args):
9292

9393
def get_groups(self, group_id):
9494
"""Retrieve all child groups of passed group."""
95-
return self.storage.filter(
96-
Group, **{'parent_group': group_id}
97-
)
95+
if group_id:
96+
filter_operation = {'parent_group.id': group_id}
97+
else:
98+
filter_operation = {'parent_group': None}
99+
return self.storage.filter(Group, **filter_operation)
98100

99101
def get_parent_group_id(self, args):
100102
"""Return parent group id or None from command line arguments."""

tests/integration/groups.bats

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,42 @@ setup() {
2323
[ $(get_models_set_length 'group_set') -eq 1 ]
2424
}
2525

26-
@test "List groups in subgroup in table format" {
26+
@test "List subgroups in a group in table format" {
27+
parent=$(termius group -L 'test group' --port 2 --username 'use r name')
28+
child=$(termius group -L 'test group' --parent-group $parent --port 2 --username 'use r name')
29+
run termius groups $parent
30+
[ "$status" -eq 0 ]
31+
[ $(get_models_set_length 'group_set') -eq 2 ]
32+
}
33+
34+
@test "List subgroups in a group" {
2735
parent=$(termius group -L 'test group' --port 2 --username 'use r name')
2836
child=$(termius group -L 'test group' --parent-group $parent --port 2 --username 'use r name')
2937
run termius groups -f csv -c id $parent
3038
[ "$status" -eq 0 ]
39+
[ "${lines[1]}" = "$child" ]
40+
[ "${lines[2]}" = "" ]
3141
[ $(get_models_set_length 'group_set') -eq 2 ]
3242
}
3343

44+
@test "List subgroups in the root group" {
45+
parent=$(termius group -L 'test group' --port 2 --username 'use r name')
46+
termius group -L 'test group' --parent-group $parent --port 2 --username 'use r name'
47+
termius group -L 'test group' --parent-group $parent --port 2 --username 'use r name'
48+
run termius groups -f csv -c id
49+
[ "$status" -eq 0 ]
50+
[ "${lines[1]}" = "$parent" ]
51+
[ "${lines[2]}" = "" ]
52+
[ $(get_models_set_length 'group_set') -eq 3 ]
53+
}
54+
3455
@test "List groups recursivly in subgroup in table format" {
3556
grandparent=$(termius group -L 'test group' --port 2 --username 'use r name')
3657
parent=$(termius group -L 'test group' --parent-group $grandparent --port 2 --username 'use r name')
3758
termius group -L 'test group' --parent-group $parent --port 2 --username 'use r name'
38-
run termius groups $grandparent
59+
run termius groups -f csv -c id $grandparent
3960
[ "$status" -eq 0 ]
61+
[ "${lines[1]}" = "$parent" ]
62+
[ "${lines[2]}" = "" ]
4063
[ $(get_models_set_length 'group_set') -eq 3 ]
4164
}

0 commit comments

Comments
 (0)