Search in sources :

Example 26 with TestUser

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

the class Workspace method statusDescribeListReflectUpdate.

@Test
@DisplayName("status, describe, workspace list reflect workspace update")
void statusDescribeListReflectUpdate() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();
    String name = "statusDescribeListReflectUpdate";
    String description = "status list reflect update";
    UFWorkspace createdWorkspace = WorkspaceUtils.createWorkspace(testUser, name, description);
    // check the created workspace name and description are set
    assertNotNull(createdWorkspace.name, "create workspace name is defined");
    assertNotNull(createdWorkspace.description, "create workspace description is defined");
    // `terra workspace update --format=json --new-id=$newId --new-name=$newName
    // --new-description=$newDescription`
    String newId = "newid";
    String newName = "NEW_statusDescribeListReflectUpdate";
    String newDescription = "NEW status describe list reflect update";
    TestCommand.runCommandExpectSuccess("workspace", "update", "--format=json", "--new-id=" + newId, "--new-name=" + newName, "--new-description=" + newDescription);
    // `terra status --format=json`
    UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");
    // check the current status reflects the update
    assertEquals(newId, status.workspace.id, "status matches updated workspace id");
    assertEquals(newName, status.workspace.name, "status matches updated workspace name");
    assertEquals(newDescription, status.workspace.description, "status matches updated workspace description");
    // `terra workspace describe --format=json`
    UFWorkspace describeWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
    // check the workspace describe reflects the update
    assertEquals(newName, describeWorkspace.name, "describe matches updated workspace name");
    assertEquals(newDescription, describeWorkspace.description, "describe matches updated workspace description");
    // check the workspace list reflects the update
    List<UFWorkspaceLight> matchingWorkspaces = listWorkspacesWithId(newId);
    assertEquals(1, matchingWorkspaces.size(), "updated workspace is included exactly once in list");
    assertEquals(newName, matchingWorkspaces.get(0).name, "updated workspace name matches that in list");
    assertEquals(newDescription, matchingWorkspaces.get(0).description, "updated workspace description matches that in list");
    // `terra workspace delete`
    TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
}
Also used : UFWorkspaceLight(bio.terra.cli.serialization.userfacing.UFWorkspaceLight) UFStatus(bio.terra.cli.serialization.userfacing.UFStatus) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 27 with TestUser

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

the class WorkspaceOverride method workspaceUser.

@Test
@DisplayName("workspace user commands respect workspace override")
void workspaceUser() throws IOException {
    // login as the workspace creator and select a test user to share the workspace with
    workspaceCreator.login();
    TestUser testUser = TestUser.chooseTestUserWhoIsNot(workspaceCreator);
    // `terra workspace set --id=$id1`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + workspace1.id);
    // `terra workspace add-user --email=$email --role=READER --workspace=$id2`
    TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + testUser.email, "--role=READER", "--workspace=" + workspace2.id);
    // check that the user exists in the list output for workspace 2, but not workspace 1
    // `terra workspace list-users --email=$email --role=READER --workspace=$id2`
    expectListedUserWithRoles(testUser.email, workspace2.id, WorkspaceUser.Role.READER);
    // `terra workspace list-users --email=$email --role=READER`
    Optional<UFWorkspaceUser> workspaceUser = workspaceListUsersWithEmail(testUser.email);
    assertTrue(workspaceUser.isEmpty(), "test user is not in users list for workspace 1");
    // `terra workspace remove-user --email=$email --role=READER --workspace=$id2`
    TestCommand.runCommandExpectSuccess("workspace", "remove-user", "--email=" + testUser.email, "--role=READER", "--workspace=" + workspace2.id);
    // `terra workspace list-users --email=$email --role=READER --workspace=$id2`
    // check that the user no longer exists in the list output for workspace 2
    workspaceUser = workspaceListUsersWithEmail(testUser.email, workspace2.id);
    assertTrue(workspaceUser.isEmpty(), "test user is no longer in users list for workspace 2");
}
Also used : UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 28 with TestUser

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

the class WorkspaceUser method listReflectAdd.

@Test
@DisplayName("list users reflects adding a user")
void listReflectAdd() throws IOException {
    // login as the workspace creator and select a test user to share the workspace with
    workspaceCreator.login();
    TestUser testUser = TestUser.chooseTestUserWhoIsNot(workspaceCreator);
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getUserFacingId());
    // `terra workspace add-user --email=$email --role=READER --format=json
    UFWorkspaceUser addUserReader = TestCommand.runAndParseCommandExpectSuccess(UFWorkspaceUser.class, "workspace", "add-user", "--email=" + testUser.email, "--role=READER");
    // check that the user has the READER role
    assertTrue(addUserReader.roles.contains(READER), "reader role returned by add-user");
    // check that the user is in the list as a reader
    expectListedUserWithRoles(testUser.email, READER);
    // `terra workspace add-user --email=$email --role=WRITER --format=json
    UFWorkspaceUser addUserWriter = TestCommand.runAndParseCommandExpectSuccess(UFWorkspaceUser.class, "workspace", "add-user", "--email=" + testUser.email, "--role=WRITER");
    // check that the user has both the READER and WRITER roles
    assertTrue(addUserWriter.roles.containsAll(Arrays.asList(READER, WRITER)), "reader and writer roles returned by add-user");
    // check that the user is in the list as a reader + writer
    expectListedUserWithRoles(testUser.email, READER, WRITER);
}
Also used : UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 29 with TestUser

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

the class WorkspaceUser method listReflectRemove.

@Test
@DisplayName("list users reflects removing a user")
void listReflectRemove() throws IOException {
    // login as the workspace creator and select a test user to share the workspace with
    workspaceCreator.login();
    TestUser testUser = TestUser.chooseTestUserWhoIsNot(workspaceCreator);
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getUserFacingId());
    // `terra workspace add-user --email=$email --role=READER --format=json
    TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + testUser.email, "--role=READER", "--format=json");
    // `terra workspace add-user --email=$email --role=OWNER --format=json
    TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + testUser.email, "--role=OWNER", "--format=json");
    // `terra workspace remove-user --email=$email --role=READER --format=json
    TestCommand.runCommandExpectSuccess("workspace", "remove-user", "--email=" + testUser.email, "--role=READER");
    // check that the user is in the list as an OWNER only
    expectListedUserWithRoles(testUser.email, OWNER);
    // `terra workspace remove-user --email=$email --role=READER`
    TestCommand.runCommandExpectSuccess("workspace", "remove-user", "--email=" + testUser.email, "--role=OWNER");
    // check that the user is not in the list
    Optional<UFWorkspaceUser> workspaceUser = workspaceListUsersWithEmail(testUser.email);
    assertTrue(workspaceUser.isEmpty(), "test user is not in users list");
}
Also used : UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 30 with TestUser

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

the class CleanupTestUserWorkspaces method deleteWorkspaces.

/**
 * List all workspaces the test user has access to and try to delete each one that the test user
 * owns. Deletes up to 100 workspaces at a time.
 */
private static void deleteWorkspaces(TestUser testUser, boolean isDryRun) throws IOException {
    System.out.println("Deleting workspaces for testuser " + testUser.email);
    TestContext.clearGlobalContextDir();
    testUser.login();
    // `terra workspace list`
    List<UFWorkspace> listWorkspaces = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
    }, "workspace", "list", "--limit=100");
    List<UFWorkspaceUser> listWorkspaceUsers;
    for (UFWorkspace workspace : listWorkspaces) {
        try {
            // `terra workspace list-users`
            listWorkspaceUsers = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
            }, "workspace", "list-users", "--workspace=" + workspace.id);
            // find the user in the list
            Optional<UFWorkspaceUser> workspaceUser = listWorkspaceUsers.stream().filter(user -> user.email.equalsIgnoreCase(testUser.email)).findAny();
            // skip deleting if the test user is not an owner
            if (workspaceUser.isEmpty() || !workspaceUser.get().roles.contains(WorkspaceUser.Role.OWNER)) {
                System.out.println("Skip deleting workspace because test user is not an owner: id=" + workspace.id + ", testuser=" + testUser.email);
                continue;
            }
            System.out.println("Deleting workspace: id=" + workspace.id + ", testuser=" + testUser.email);
            if (!isDryRun) {
                // `terra workspace delete --workspace=$id`
                TestCommand.runCommandExpectSuccess("workspace", "delete", "--workspace=" + workspace.id, "--quiet");
                System.out.println("Cleaned up workspace: id=" + workspace.id + ", testuser=" + testUser.email);
            }
            deletedWorkspaces.add(workspace.id);
        } catch (Throwable ex) {
            System.out.println("Error deleting workspace: id=" + workspace.id + ", testuser=" + testUser.email);
            ex.printStackTrace();
            failedWorkspaces.add(workspace.id);
            continue;
        }
    }
    // `terra auth revoke`
    TestCommand.runCommandExpectSuccess("auth", "revoke");
}
Also used : List(java.util.List) UserActionableException(bio.terra.cli.exception.UserActionableException) WorkspaceUser(bio.terra.cli.businessobject.WorkspaceUser) UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) TestCommand(harness.TestCommand) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) TestUser(harness.TestUser) Optional(java.util.Optional) TestContext(harness.TestContext) IOException(java.io.IOException) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ArrayList(java.util.ArrayList) UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Aggregations

TestUser (harness.TestUser)30 Test (org.junit.jupiter.api.Test)28 DisplayName (org.junit.jupiter.api.DisplayName)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 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Matchers.emptyString (org.hamcrest.Matchers.emptyString)4 AfterAll (org.junit.jupiter.api.AfterAll)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4