use of bio.terra.cli.serialization.userfacing.UFGroupMember in project terra-cli by DataBiosphere.
the class Group method listUsersReflectsAddRemove.
@Test
@DisplayName("list-users reflects adding and removing a user")
void listUsersReflectsAddRemove() throws IOException {
TestUser groupCreator = TestUser.chooseTestUser();
groupCreator.login();
// `terra group create --name=$name`
String name = SamGroups.randomGroupName();
TestCommand.runCommandExpectSuccess("group", "create", "--name=" + name);
// track the group so we can clean it up in case this test method fails
trackedGroups.trackGroup(name, groupCreator);
// `terra group add-user --name=$name --email=$email --policy=MEMBER`
TestUser groupMember = TestUser.chooseTestUserWhoIsNot(groupCreator);
TestCommand.runCommandExpectSuccess("group", "add-user", "--name=" + name, "--email=" + groupMember.email, "--policy=MEMBER");
// check that group member is included in the list-users output with one policy
expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.MEMBER);
// `terra group add-user --name=$name --email=$email --policy=ADMIN`
TestCommand.runCommandExpectSuccess("group", "add-user", "--name=" + name, "--email=" + groupMember.email, "--policy=ADMIN");
// check that group member is included in the list-users output with two policies
expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.MEMBER, GroupPolicy.ADMIN);
// `terra group describe --name=$name`
UFGroup groupDescribed = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "describe", "--name=" + name);
assertEquals(2, groupDescribed.numMembers, "group describe shows two members");
// `terra group remove-user --name=$name --email=$email --policy=MEMBER`
TestCommand.runCommandExpectSuccess("group", "remove-user", "--name=" + name, "--email=" + groupMember.email, "--policy=MEMBER");
// check that group member is included in the list-users output with one policy
expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.ADMIN);
// `terra group remove-user --name=$name --email=$email --policy=ADMIN`
TestCommand.runCommandExpectSuccess("group", "remove-user", "--name=" + name, "--email=" + groupMember.email, "--policy=ADMIN");
// check that group member is no longer included in the list-users output
Optional<UFGroupMember> listedGroupMember = listMembersWithEmail(name, groupMember.email);
assertTrue(listedGroupMember.isEmpty(), "test user is no longer included in members list");
// check that the group creator is included in the list-users output
expectListedMemberWithPolicies(name, groupCreator.email, GroupPolicy.ADMIN);
// `terra group delete --name=$name`
TestCommand.runCommandExpectSuccess("group", "delete", "--name=" + name, "--quiet");
}
use of bio.terra.cli.serialization.userfacing.UFGroupMember in project terra-cli by DataBiosphere.
the class AddUser method execute.
/**
* Add a user to a Terra group.
*/
@Override
protected void execute() {
Group.Member groupMember = Group.get(groupMemberOption.groupNameOption.name).addPolicyToMember(groupMemberOption.email, groupMemberOption.policy);
formatOption.printReturnValue(new UFGroupMember(groupMember), AddUser::printText);
}
Aggregations