Search in sources :

Example 1 with TestUser

use of harness.TestUser in project terra-cli by DataBiosphere.

the class SpendProfileUser method listUsersReflectsEnableDisable.

@Test
@DisplayName("list-users reflects enabling and disabling users")
void listUsersReflectsEnableDisable() throws IOException {
    // get an email to try and add
    String testEmail = generateSamGroupForEmail();
    // use a test user that is an owner to grant spend access to the test email
    TestUser spendProfileOwner = TestUser.chooseTestUserWithOwnerAccess();
    spendProfileOwner.login();
    // `terra spend enable --email=$testEmail --policy=USER`
    TestCommand.runCommandExpectSuccess("spend", "enable", "--email=" + testEmail, "--policy=USER");
    // check that the test email is included in the list-users output
    expectListedUserWithPolicies(testEmail, SpendProfilePolicy.USER);
    // `terra spend disable --email=$testEmail --policy=USER`
    TestCommand.runCommandExpectSuccess("spend", "disable", "--email=" + testEmail, "--policy=USER");
    // check that the test email is not included in the list-users output
    Optional<UFSpendProfileUser> listUsersOutput = listUsersWithEmail(testEmail);
    assertTrue(listUsersOutput.isEmpty(), "user is not included in the test-users output after having their spend access disabled");
}
Also used : UFSpendProfileUser(bio.terra.cli.serialization.userfacing.UFSpendProfileUser) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with TestUser

use of harness.TestUser in project terra-cli by DataBiosphere.

the class Workspace method statusDescribeReflectsSet.

@Test
@DisplayName("status, describe reflect workspace set")
void statusDescribeReflectsSet() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();
    // `terra workspace create --format=json` (workspace 1)
    UFWorkspace createWorkspace1 = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "create");
    // `terra workspace create --format=json` (workspace 2)
    UFWorkspace createWorkspace2 = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "create");
    // set current workspace = workspace 1
    UFWorkspace setWorkspace1 = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "set", "--id=" + createWorkspace1.id);
    assertEquals(createWorkspace1.id, setWorkspace1.id, "set returned the expected workspace (1)");
    // `terra status --format=json`
    UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");
    // check the current status reflects the workspace set
    assertEquals(createWorkspace1.id, status.workspace.id, "status matches set workspace id (1)");
    // `terra workspace describe --format=json`
    UFWorkspace describeWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
    // check the workspace describe reflects the workspace set
    assertEquals(createWorkspace1.id, describeWorkspace.id, "describe matches set workspace id (1)");
    // set current workspace = workspace 2
    UFWorkspace setWorkspace2 = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "set", "--id=" + createWorkspace2.id);
    assertEquals(createWorkspace2.id, setWorkspace2.id, "set returned the expected workspace (2)");
    // `terra status --format=json`
    status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");
    // check the current status reflects the workspace set
    assertEquals(createWorkspace2.id, status.workspace.id, "status matches set workspace id (2)");
    // `terra workspace describe --format=json`
    describeWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
    // check the workspace describe reflects the workspace set
    assertEquals(createWorkspace2.id, describeWorkspace.id, "describe matches set workspace id (2)");
    // `terra workspace delete` (workspace 2)
    TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
    // `terra workspace set` (workspace 1)
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + createWorkspace1.id);
    // `terra workspace delete` (workspace 1)
    TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
}
Also used : UFStatus(bio.terra.cli.serialization.userfacing.UFStatus) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with TestUser

use of harness.TestUser in project terra-cli by DataBiosphere.

the class ClientExceptionHandling method samDuplicateGroup.

@Test
@DisplayName("try to create a group twice, check that the output includes the CLI and SAM error messages")
void samDuplicateGroup() throws IOException {
    TestUser testUser = TestUser.chooseTestUser();
    testUser.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, testUser);
    // try to create another group with the same name
    String stdErr = TestCommand.runCommandExpectExitCode(2, "group", "create", "--name=" + name);
    assertThat("stderr includes the CLI error message", stdErr, CoreMatchers.containsString("Error creating SAM group"));
    assertThat("stderr includes the SAM error message", stdErr, CoreMatchers.containsString("A resource of this type and name already exists"));
}
Also used : TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with TestUser

use of harness.TestUser 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");
}
Also used : UFGroupMember(bio.terra.cli.serialization.userfacing.UFGroupMember) UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with TestUser

use of harness.TestUser 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");
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) UFGroupMember(bio.terra.cli.serialization.userfacing.UFGroupMember) Arrays(java.util.Arrays) UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) TestCommand(harness.TestCommand) SamGroups(harness.utils.SamGroups) TestUser(harness.TestUser) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) DisplayName(org.junit.jupiter.api.DisplayName) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) GroupPolicy(bio.terra.cli.service.SamService.GroupPolicy) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ClearContextUnit(harness.baseclasses.ClearContextUnit) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Tag(org.junit.jupiter.api.Tag) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TypeReference(com.fasterxml.jackson.core.type.TypeReference) UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TestUser (harness.TestUser)29 DisplayName (org.junit.jupiter.api.DisplayName)27 Test (org.junit.jupiter.api.Test)27 UFWorkspace (bio.terra.cli.serialization.userfacing.UFWorkspace)7 UFGroup (bio.terra.cli.serialization.userfacing.UFGroup)5 UFStatus (bio.terra.cli.serialization.userfacing.UFStatus)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 TestCommand (harness.TestCommand)5 IOException (java.io.IOException)5 List (java.util.List)5 UFWorkspaceLight (bio.terra.cli.serialization.userfacing.UFWorkspaceLight)4 UFWorkspaceUser (bio.terra.cli.serialization.userfacing.UFWorkspaceUser)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ClearContextUnit (harness.baseclasses.ClearContextUnit)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 AfterAll (org.junit.jupiter.api.AfterAll)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Tag (org.junit.jupiter.api.Tag)4 UFGroupMember (bio.terra.cli.serialization.userfacing.UFGroupMember)3