Skip to content

Commit

Permalink
Merge pull request #32 from EvgeneOskin/feature/fix-listing-groups
Browse files Browse the repository at this point in the history
Fix listing groups
  • Loading branch information
EvgeneOskin authored Dec 9, 2016
2 parents a455f76 + 18d8aa3 commit 11d8506
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
8 changes: 5 additions & 3 deletions termius/handlers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ def take_action(self, parsed_args):

def get_groups(self, group_id):
"""Retrieve all child groups of passed group."""
return self.storage.filter(
Group, **{'parent_group': group_id}
)
if group_id:
filter_operation = {'parent_group.id': group_id}
else:
filter_operation = {'parent_group': None}
return self.storage.filter(Group, **filter_operation)

def get_parent_group_id(self, args):
"""Return parent group id or None from command line arguments."""
Expand Down
27 changes: 25 additions & 2 deletions tests/integration/groups.bats
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,42 @@ setup() {
[ $(get_models_set_length 'group_set') -eq 1 ]
}

@test "List groups in subgroup in table format" {
@test "List subgroups in a group in table format" {
parent=$(termius group -L 'test group' --port 2 --username 'use r name')
child=$(termius group -L 'test group' --parent-group $parent --port 2 --username 'use r name')
run termius groups $parent
[ "$status" -eq 0 ]
[ $(get_models_set_length 'group_set') -eq 2 ]
}

@test "List subgroups in a group" {
parent=$(termius group -L 'test group' --port 2 --username 'use r name')
child=$(termius group -L 'test group' --parent-group $parent --port 2 --username 'use r name')
run termius groups -f csv -c id $parent
[ "$status" -eq 0 ]
[ "${lines[1]}" = "$child" ]
[ "${lines[2]}" = "" ]
[ $(get_models_set_length 'group_set') -eq 2 ]
}

@test "List subgroups in the root group" {
parent=$(termius group -L 'test group' --port 2 --username 'use r name')
termius group -L 'test group' --parent-group $parent --port 2 --username 'use r name'
termius group -L 'test group' --parent-group $parent --port 2 --username 'use r name'
run termius groups -f csv -c id
[ "$status" -eq 0 ]
[ "${lines[1]}" = "$parent" ]
[ "${lines[2]}" = "" ]
[ $(get_models_set_length 'group_set') -eq 3 ]
}

@test "List groups recursivly in subgroup in table format" {
grandparent=$(termius group -L 'test group' --port 2 --username 'use r name')
parent=$(termius group -L 'test group' --parent-group $grandparent --port 2 --username 'use r name')
termius group -L 'test group' --parent-group $parent --port 2 --username 'use r name'
run termius groups $grandparent
run termius groups -f csv -c id $grandparent
[ "$status" -eq 0 ]
[ "${lines[1]}" = "$parent" ]
[ "${lines[2]}" = "" ]
[ $(get_models_set_length 'group_set') -eq 3 ]
}

0 comments on commit 11d8506

Please sign in to comment.