Search in sources :

Example 21 with TestUser

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

the class BqDatasetNumTables method numTablesForReferencedWithNoAccess.

@Test
@DisplayName("referenced dataset with no access does not fail the describe command")
void numTablesForReferencedWithNoAccess() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getUserFacingId());
    // `terra resource add-ref bq-dataset --name=$name --project-id=$projectId
    // --dataset-id=$datasetId`
    String name = "numTablesForReferencedWithNoAccess";
    TestCommand.runCommandExpectSuccess("resource", "add-ref", "bq-dataset", "--name=" + name, "--project-id=" + externalDataset.getProjectId(), "--dataset-id=" + externalDataset.getDatasetId());
    // `terra workspace add-user --email=$email --role=READER`
    TestUser shareeUser = TestUser.chooseTestUserWhoIsNot(workspaceCreator);
    TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + shareeUser.email, "--role=READER");
    shareeUser.login();
    // `terra resource describe --name=$name`
    UFBqDataset describeDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "describe", "--name=" + name);
    // the external dataset created in the beforeall method should have 1 table in it, but the
    // sharee user doesn't have read access to the dataset so they can't know that
    assertNull(describeDataset.numTables, "referenced dataset with no access contains NULL tables");
}
Also used : UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 22 with TestUser

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

the class Workspace method describeReflectsNumResources.

@Test
@DisplayName("workspace describe reflects the number of resources")
void describeReflectsNumResources() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();
    UFWorkspace createdWorkspace = WorkspaceUtils.createWorkspace(testUser);
    assertEquals(0, createdWorkspace.numResources, "new workspace has 0 resources");
    // `terra resource create gcs-bucket --name=$name --bucket-name=$bucketName`
    String bucketResourceName = "describeReflectsNumResourcesGCS";
    String bucketName = UUID.randomUUID().toString();
    TestCommand.runCommandExpectSuccess("resource", "create", "gcs-bucket", "--name=" + bucketResourceName, "--bucket-name=" + bucketName);
    // `terra workspace describe`
    UFWorkspace describeWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
    assertEquals(1, describeWorkspace.numResources, "worksapce has 1 resource after creating bucket");
    // `terra resource create bq-dataset --name=$name --dataset-id=$datasetId`
    String datasetResourceName = "describeReflectsNumResourcesBQ";
    String datasetId = "bq1";
    TestCommand.runCommandExpectSuccess("resource", "create", "bq-dataset", "--name=" + datasetResourceName, "--dataset-id=" + datasetId);
    // `terra workspace describe`
    Result describeResult2 = TestCommand.runCommand("workspace", "describe");
    assertEquals(0, describeResult2.exitCode, "Describe was successful.");
    assertThat("workspace has 2 resources after creating dataset", describeResult2.stdOut, containsString("# Resources:       2"));
    assertThat("No error message is displayed on second describe.", describeResult2.stdErr, is(emptyString()));
    UFWorkspace describeWorkspace3 = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
    assertEquals(2, describeWorkspace3.numResources, "worksapce has 2 resources after creating dataset");
    // `terra workspace delete`
    TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
}
Also used : UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Matchers.containsString(org.hamcrest.Matchers.containsString) TestUser(harness.TestUser) Result(harness.TestCommand.Result) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 23 with TestUser

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

the class Workspace method createFailsWithoutSpendAccess.

@Test
@DisplayName("workspace create fails without spend profile access")
void createFailsWithoutSpendAccess() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithoutSpendAccess();
    testUser.login();
    final String workspaceName = "bad-profile-6789";
    // `terra workspace create --id=<user-facing-id>`
    String stdErr = TestCommand.runCommandExpectExitCode(1, "workspace", "create", "--id=" + WorkspaceUtils.createUserFacingId());
    assertThat("error message includes spend profile unauthorized", stdErr, CoreMatchers.containsString("Accessing the spend profile failed. Ask an administrator to grant you access."));
    // workspace was deleted
    List<UFWorkspace> listWorkspaces = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
    }, "workspace", "list", "--limit=100");
    assertFalse(listWorkspaces.stream().anyMatch(w -> workspaceName.equals(w.name)));
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) CoreMatchers(org.hamcrest.CoreMatchers) Matchers.emptyString(org.hamcrest.Matchers.emptyString) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TestCommand(harness.TestCommand) Result(harness.TestCommand.Result) TestUser(harness.TestUser) IsEqualIgnoringCase.equalToIgnoringCase(org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) 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) UFStatus(bio.terra.cli.serialization.userfacing.UFStatus) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) WorkspaceUtils(harness.utils.WorkspaceUtils) List(java.util.List) ClearContextUnit(harness.baseclasses.ClearContextUnit) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) UFWorkspaceLight(bio.terra.cli.serialization.userfacing.UFWorkspaceLight) 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 24 with TestUser

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

the class Workspace method statusDescribeListReflectCreate.

@Test
@DisplayName("status, describe, workspace list reflect workspace create")
void statusDescribeListReflectCreate() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();
    UFWorkspace createdWorkspace = WorkspaceUtils.createWorkspace(testUser);
    // check the created workspace has an id and a google project
    assertNotNull(createdWorkspace.id, "create workspace returned a workspace id");
    assertNotNull(createdWorkspace.googleProjectId, "create workspace created a gcp project");
    assertThat("workspace email matches test user", createdWorkspace.userEmail, equalToIgnoringCase(testUser.email));
    // `terra status --format=json`
    UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");
    // check the current status reflects the new workspace
    assertThat("workspace server matches current server", createdWorkspace.serverName, equalToIgnoringCase(status.server.name));
    assertEquals(createdWorkspace.id, status.workspace.id, "workspace id matches current status");
    assertEquals(createdWorkspace.googleProjectId, status.workspace.googleProjectId, "workspace gcp project matches current status");
    // `terra workspace describe --format=json`
    UFWorkspace describeWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
    // check the new workspace is returned by describe
    assertEquals(createdWorkspace.id, describeWorkspace.id, "workspace id matches that in describe");
    assertEquals(createdWorkspace.googleProjectId, describeWorkspace.googleProjectId, "workspace gcp project matches that in describe");
    // check the new workspace is included in the list
    List<UFWorkspaceLight> matchingWorkspaces = listWorkspacesWithId(createdWorkspace.id);
    assertEquals(1, matchingWorkspaces.size(), "new workspace is included exactly once in list");
    assertEquals(createdWorkspace.id, matchingWorkspaces.get(0).id, "workspace id matches that in list");
    assertEquals(createdWorkspace.googleProjectId, matchingWorkspaces.get(0).googleProjectId, "workspace gcp project 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) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 25 with TestUser

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

the class Workspace method statusDescribeListReflectDelete.

@Test
@DisplayName("status, describe, workspace list reflect workspace delete")
void statusDescribeListReflectDelete() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();
    UFWorkspace createdWorkspace = WorkspaceUtils.createWorkspace(testUser);
    // `terra workspace delete --format=json`
    TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
    // `terra status --format=json`
    UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");
    // check the current status reflects the deleted workspace
    assertNull(status.workspace, "status has no workspace after delete");
    // `terra workspace describe --format=json`
    TestCommand.runCommandExpectExitCode(1, "workspace", "describe");
    // check the deleted workspace is not included in the list
    List<UFWorkspaceLight> matchingWorkspaces = listWorkspacesWithId(createdWorkspace.id);
    assertEquals(0, matchingWorkspaces.size(), "deleted workspace is not included in list");
}
Also used : UFWorkspaceLight(bio.terra.cli.serialization.userfacing.UFWorkspaceLight) 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)

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