use of bio.terra.cli.serialization.userfacing.UFGroup in project terra-cli by DataBiosphere.
the class SpendProfileUser method generateSamGroupForEmail.
/**
* Create a SAM group, so we can use its generated email. This is a workaround to our current use
* of hard-coded test users. We don't want to use the CLI test users here because then this test
* could not be run simultaneously with other tests.
*
* @return the generated group's email
*/
private String generateSamGroupForEmail() throws IOException {
String name = SamGroups.randomGroupName();
spendProfileOwner.login();
// `terra group create --name=$name`
UFGroup groupCreated = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "create", "--name=" + name);
// track the group so we can clean it up in case this test method fails
trackedGroups.trackGroup(name, spendProfileOwner);
return groupCreated.email;
}
use of bio.terra.cli.serialization.userfacing.UFGroup 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.UFGroup in project terra-cli by DataBiosphere.
the class Group method listDescribeUsersReflectCreateDelete.
@Test
@DisplayName("list, describe, list-users reflect creating and deleting a group")
void listDescribeUsersReflectCreateDelete() throws IOException {
TestUser testUser = TestUser.chooseTestUser();
testUser.login();
// `terra group create --name=$name`
String name = SamGroups.randomGroupName();
UFGroup groupCreated = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "create", "--name=" + name);
// track the group so we can clean it up in case this test method fails
trackedGroups.trackGroup(name, testUser);
// check that the name and email match
assertEquals(name, groupCreated.name, "group name matches after create");
assertThat("group email contains the name", groupCreated.email, CoreMatchers.containsString(name));
assertThat("group creator is an admin", groupCreated.currentUserPolicies.contains(GroupPolicy.ADMIN));
// `terra group list-users --name=$name`
// check that the group creator is included in the list and is an admin
expectListedMemberWithPolicies(name, testUser.email, GroupPolicy.ADMIN);
// `terra group list`
List<UFGroup> groupList = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
}, "group", "list");
// check that the listed group matches the created one
Optional<UFGroup> matchedGroup = groupList.stream().filter(listedGroup -> listedGroup.name.equals(name)).findAny();
assertTrue(matchedGroup.isPresent(), "group appears in list after create");
assertEquals(name, matchedGroup.get().name, "group name matches list output after create");
assertEquals(groupCreated.email, matchedGroup.get().email, "group email matches list output after create");
assertTrue(matchedGroup.get().currentUserPolicies.contains(GroupPolicy.ADMIN), "group policies for current user matches list output after create");
// `terra group describe --name=$name`
UFGroup groupDescribed = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "describe", "--name=" + name);
// check that the described group matches the created one
assertEquals(name, groupDescribed.name, "group name matches describe output after create");
assertEquals(groupCreated.email, groupDescribed.email, "group email matches describe output after create");
assertTrue(groupDescribed.currentUserPolicies.contains(GroupPolicy.ADMIN), "group policies for current user matches describe output after create");
assertEquals(1, groupDescribed.numMembers, "group # members matches describe output after create");
// `terra group delete --name=$name`
TestCommand.runCommandExpectSuccess("group", "delete", "--name=" + name, "--quiet");
// `terra group list`
groupList = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
}, "group", "list");
// check that the group is not included in the list output
matchedGroup = groupList.stream().filter(listedGroup -> listedGroup.name.equals(name)).findAny();
assertTrue(matchedGroup.isEmpty(), "group does not appear in list after delete");
}
use of bio.terra.cli.serialization.userfacing.UFGroup in project terra-cli by DataBiosphere.
the class Delete method execute.
/**
* Delete an existing Terra group.
*/
@Override
protected void execute() {
Group groupToDelete = Group.get(groupNameOption.name);
// print details about the group before showing the delete prompt
new UFGroup(groupToDelete).print();
deletePromptOption.confirmOrThrow();
groupToDelete.delete();
OUT.println("Terra group successfully deleted.");
}
use of bio.terra.cli.serialization.userfacing.UFGroup in project terra-cli by DataBiosphere.
the class SpendProfileUser method cleanupOnce.
@AfterAll
void cleanupOnce() throws IOException, InterruptedException {
spendProfileOwner.login();
// try to disable spend for each group that was created by a method in this class
for (Map.Entry<String, TestUser> groupNameToCreator : trackedGroups.getTrackedGroups().entrySet()) {
UFGroup groupInfo = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "describe", "--name=" + groupNameToCreator.getKey());
TestCommand.runCommand("spend", "disable", "--email=" + groupInfo.email, "--policy=USER");
TestCommand.runCommand("spend", "disable", "--email=" + groupInfo.email, "--policy=OWNER");
}
// then try to delete the groups
trackedGroups.deleteAllTrackedGroups();
}
Aggregations