Skip to content

Add crud on solution run templates #896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ControllerTestUtils {
tags: MutableList<String> = mutableListOf(),
parameters: MutableList<RunTemplateParameterCreateRequest> = mutableListOf(),
parameterGroups: MutableList<RunTemplateParameterGroupCreateRequest> = mutableListOf(),
runTemplates: MutableList<RunTemplate> = mutableListOf(),
runTemplates: MutableList<RunTemplateCreateRequest> = mutableListOf(),
url: String = "",
security: SolutionSecurity? = null
): SolutionCreateRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import com.cosmotech.run.domain.*
import com.cosmotech.run.workflow.WorkflowService
import com.cosmotech.runner.domain.*
import com.cosmotech.runner.domain.ResourceSizeInfo
import com.cosmotech.solution.domain.RunTemplate
import com.cosmotech.solution.domain.RunTemplateCreateRequest
import com.cosmotech.solution.domain.RunTemplateResourceSizing
import com.ninjasquad.springmockk.SpykBean
import io.mockk.every
Expand Down Expand Up @@ -111,7 +111,7 @@ class RunControllerTests : ControllerTestBase() {

val runTemplates =
mutableListOf(
RunTemplate(
RunTemplateCreateRequest(
RUNNER_RUN_TEMPLATE,
RUN_TEMPLATE_NAME,
PARAMETER_LABELS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import com.cosmotech.api.rbac.ROLE_NONE
import com.cosmotech.api.rbac.ROLE_VIEWER
import com.cosmotech.runner.domain.*
import com.cosmotech.runner.domain.ResourceSizeInfo
import com.cosmotech.solution.domain.RunTemplate
import com.cosmotech.solution.domain.RunTemplateCreateRequest
import com.cosmotech.solution.domain.RunTemplateResourceSizing
import com.ninjasquad.springmockk.SpykBean
import io.mockk.every
Expand Down Expand Up @@ -73,7 +73,7 @@ class RunnerControllerTests : ControllerTestBase() {
com.cosmotech.solution.domain.ResourceSizeInfo("cpu_limits", "memory_limits"))
val runTemplates =
mutableListOf(
RunTemplate(
RunTemplateCreateRequest(
RUNNER_RUN_TEMPLATE,
runTemplateName,
parameterLabels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import com.cosmotech.solution.api.SolutionApiService
import com.cosmotech.solution.domain.*
import io.mockk.every
import io.mockk.mockk
import org.json.JSONArray
import org.json.JSONObject
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -162,7 +161,7 @@ class SolutionControllerTests : ControllerTestBase() {
ResourceSizeInfo("cpu_limits", "memory_limits"))
val runTemplates =
mutableListOf(
RunTemplate(
RunTemplateCreateRequest(
runTemplateId,
runTemplateName,
parameterLabels,
Expand Down Expand Up @@ -300,7 +299,7 @@ class SolutionControllerTests : ControllerTestBase() {
ResourceSizeInfo("cpu_limits", "memory_limits"))
val runTemplates =
mutableListOf(
RunTemplate(
RunTemplateCreateRequest(
runTemplateId,
runTemplateName,
parameterLabels,
Expand Down Expand Up @@ -974,61 +973,57 @@ class SolutionControllerTests : ControllerTestBase() {

@Test
@WithMockOauth2User
fun add_solution_runTemplates() {

val description = "this_is_a_description"
val tags = mutableListOf("tag1", "tag2")
val parameterLabels = mutableMapOf("fr" to "this_is_a_label")
val parameterGroupId = "parameterGroup1"
fun list_solution_runTemplate() {
val runTemplateId = "runtemplate1"

val runTemplateName = "this_is_a_name"
val runTemplateLabels = mutableMapOf("fr" to "this_is_a_label")
val runTemplateDescription = "this_is_a_description"
val runTemplateTags = mutableListOf("tag1", "tag2")
val runTemplateComputeSize = "this_is_a_compute_size"
val runTemplateRunSizing =
RunTemplateResourceSizing(
ResourceSizeInfo("cpu_requests", "memory_requests"),
ResourceSizeInfo("cpu_limits", "memory_limits"))
val runTemplateParameterGroups = mutableListOf("parameterGroup1")
val runTemplates =
mutableListOf(
RunTemplate(
RunTemplateCreateRequest(
runTemplateId,
runTemplateName,
parameterLabels,
description,
tags,
runTemplateLabels,
runTemplateDescription,
runTemplateTags,
runTemplateComputeSize,
runTemplateRunSizing,
mutableListOf(parameterGroupId),
RunTemplateResourceSizing(
ResourceSizeInfo("cpu_requests", "memory_requests"),
ResourceSizeInfo("cpu_limits", "memory_limits")),
runTemplateParameterGroups,
10))

val solutionId =
createSolutionAndReturnId(mvc, organizationId, constructSolutionCreateRequest())
createSolutionAndReturnId(
mvc, organizationId, constructSolutionCreateRequest(runTemplates = runTemplates))

mvc.perform(
patch("/organizations/$organizationId/solutions/$solutionId/runTemplates")
.contentType(MediaType.APPLICATION_JSON)
.content(JSONArray(runTemplates).toString())
.with(csrf()))
get("/organizations/$organizationId/solutions/$solutionId/runTemplates")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$[0].id").value(runTemplateId))
.andExpect(jsonPath("$[0].name").value(runTemplateName))
.andExpect(jsonPath("$[0].labels").value(parameterLabels))
.andExpect(jsonPath("$[0].description").value(description))
.andExpect(jsonPath("$[0].tags").value(tags))
.andExpect(jsonPath("$[0].labels").value(runTemplateLabels))
.andExpect(jsonPath("$[0].description").value(runTemplateDescription))
.andExpect(jsonPath("$[0].tags").value(runTemplateTags))
.andExpect(jsonPath("$[0].computeSize").value(runTemplateComputeSize))
.andExpect(jsonPath("$[0].runSizing.requests.cpu").value("cpu_requests"))
.andExpect(jsonPath("$[0].runSizing.requests.memory").value("memory_requests"))
.andExpect(jsonPath("$[0].runSizing.limits.cpu").value("cpu_limits"))
.andExpect(jsonPath("$[0].runSizing.limits.memory").value("memory_limits"))
.andExpect(jsonPath("$[0].parameterGroups").value(mutableListOf(parameterGroupId)))
.andExpect(jsonPath("$[0].parameterGroups").value(runTemplateParameterGroups))
.andExpect(jsonPath("$[0].executionTimeout").value(10))
.andDo(MockMvcResultHandlers.print())
.andDo(
document("organizations/{organization_id}/solutions/{solution_id}/runTemplates/PATCH"))
.andDo(document("organizations/{organization_id}/solutions/{solution_id}/runTemplates/GET"))
}

@Test
@WithMockOauth2User
fun delete_solution_runTemplates() {
fun create_solution_runTemplate() {

val description = "this_is_a_description"
val tags = mutableListOf("tag1", "tag2")
Expand All @@ -1041,75 +1036,94 @@ class SolutionControllerTests : ControllerTestBase() {
RunTemplateResourceSizing(
ResourceSizeInfo("cpu_requests", "memory_requests"),
ResourceSizeInfo("cpu_limits", "memory_limits"))
val runTemplates =
mutableListOf(
RunTemplate(
runTemplateId,
runTemplateName,
parameterLabels,
description,
tags,
runTemplateComputeSize,
runTemplateRunSizing,
mutableListOf(parameterGroupId),
10))
val runTemplate =
RunTemplateCreateRequest(
runTemplateId,
runTemplateName,
parameterLabels,
description,
tags,
runTemplateComputeSize,
runTemplateRunSizing,
mutableListOf(parameterGroupId),
10)

val solutionId =
createSolutionAndReturnId(
mvc, organizationId, constructSolutionCreateRequest(runTemplates = runTemplates))
createSolutionAndReturnId(mvc, organizationId, constructSolutionCreateRequest())

mvc.perform(
delete("/organizations/$organizationId/solutions/$solutionId/runTemplates")
post("/organizations/$organizationId/solutions/$solutionId/runTemplates")
.contentType(MediaType.APPLICATION_JSON)
.content(JSONObject(runTemplate).toString())
.with(csrf()))
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$.id").value(runTemplateId))
.andExpect(jsonPath("$.name").value(runTemplateName))
.andExpect(jsonPath("$.labels").value(parameterLabels))
.andExpect(jsonPath("$.description").value(description))
.andExpect(jsonPath("$.tags").value(tags))
.andExpect(jsonPath("$.computeSize").value(runTemplateComputeSize))
.andExpect(jsonPath("$.runSizing.requests.cpu").value("cpu_requests"))
.andExpect(jsonPath("$.runSizing.requests.memory").value("memory_requests"))
.andExpect(jsonPath("$.runSizing.limits.cpu").value("cpu_limits"))
.andExpect(jsonPath("$.runSizing.limits.memory").value("memory_limits"))
.andExpect(jsonPath("$.parameterGroups").value(mutableListOf(parameterGroupId)))
.andExpect(jsonPath("$.executionTimeout").value(10))
.andDo(MockMvcResultHandlers.print())
.andDo(
document("organizations/{organization_id}/solutions/{solution_id}/runTemplates/DELETE"))
document("organizations/{organization_id}/solutions/{solution_id}/runTemplates/POST"))
}

@Test
@WithMockOauth2User
fun delete_solution_runTemplate() {

val description = "this_is_a_description"
val tags = mutableListOf("tag1", "tag2")
val parameterLabels = mutableMapOf("fr" to "this_is_a_label")
val parameterGroupId = "parameterGroup1"
fun get_solution_runTemplate() {
val runTemplateId = "runtemplate1"

val runTemplateName = "this_is_a_name"
val runTemplateLabels = mutableMapOf("fr" to "this_is_a_label")
val runTemplateDescription = "this_is_a_description"
val runTemplateTags = mutableListOf("tag1", "tag2")
val runTemplateComputeSize = "this_is_a_compute_size"
val runTemplateRunSizing =
RunTemplateResourceSizing(
ResourceSizeInfo("cpu_requests", "memory_requests"),
ResourceSizeInfo("cpu_limits", "memory_limits"))
val runTemplateParameterGroups = mutableListOf("parameterGroup1")
val runTemplates =
mutableListOf(
RunTemplate(
RunTemplateCreateRequest(
runTemplateId,
runTemplateName,
parameterLabels,
description,
tags,
runTemplateLabels,
runTemplateDescription,
runTemplateTags,
runTemplateComputeSize,
runTemplateRunSizing,
mutableListOf(parameterGroupId),
RunTemplateResourceSizing(
ResourceSizeInfo("cpu_requests", "memory_requests"),
ResourceSizeInfo("cpu_limits", "memory_limits")),
runTemplateParameterGroups,
10))

val solutionId =
createSolutionAndReturnId(
mvc, organizationId, constructSolutionCreateRequest(runTemplates = runTemplates))

mvc.perform(
delete(
"/organizations/$organizationId/solutions/$solutionId/runTemplates/$runTemplateId")
.contentType(MediaType.APPLICATION_JSON)
.with(csrf()))
get("/organizations/$organizationId/solutions/$solutionId/runTemplates/$runTemplateId")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$.id").value(runTemplateId))
.andExpect(jsonPath("$.name").value(runTemplateName))
.andExpect(jsonPath("$.labels").value(runTemplateLabels))
.andExpect(jsonPath("$.description").value(runTemplateDescription))
.andExpect(jsonPath("$.tags").value(runTemplateTags))
.andExpect(jsonPath("$.computeSize").value(runTemplateComputeSize))
.andExpect(jsonPath("$.runSizing.requests.cpu").value("cpu_requests"))
.andExpect(jsonPath("$.runSizing.requests.memory").value("memory_requests"))
.andExpect(jsonPath("$.runSizing.limits.cpu").value("cpu_limits"))
.andExpect(jsonPath("$.runSizing.limits.memory").value("memory_limits"))
.andExpect(jsonPath("$.parameterGroups").value(runTemplateParameterGroups))
.andExpect(jsonPath("$.executionTimeout").value(10))
.andDo(MockMvcResultHandlers.print())
.andDo(
document(
"organizations/{organization_id}/solutions/{solution_id}/runTemplates/{run_template_id}/DELETE"))
"organizations/{organization_id}/solutions/{solution_id}/runTemplates/{run_template_id}/GET"))
}

@Test
Expand All @@ -1119,7 +1133,7 @@ class SolutionControllerTests : ControllerTestBase() {

val runTemplates =
mutableListOf(
RunTemplate(
RunTemplateCreateRequest(
runTemplateId,
"this_is_a_name",
mutableMapOf("fr" to "this_is_a_label"),
Expand Down Expand Up @@ -1147,8 +1161,7 @@ class SolutionControllerTests : ControllerTestBase() {
ResourceSizeInfo("cpu_requests2", "memory_requests2"),
ResourceSizeInfo("cpu_limits2", "memory_limits2"))
val newRunTemplate =
RunTemplate(
runTemplateId,
RunTemplateUpdateRequest(
runTemplateName,
parameterLabels,
description,
Expand All @@ -1165,24 +1178,68 @@ class SolutionControllerTests : ControllerTestBase() {
.contentType(MediaType.APPLICATION_JSON)
.with(csrf()))
.andExpect(status().is2xxSuccessful)
.andExpect(jsonPath("$[0].id").value(runTemplateId))
.andExpect(jsonPath("$[0].name").value(runTemplateName))
.andExpect(jsonPath("$[0].labels").value(parameterLabels))
.andExpect(jsonPath("$[0].description").value(description))
.andExpect(jsonPath("$[0].tags").value(tags))
.andExpect(jsonPath("$[0].computeSize").value(runTemplateComputeSize))
.andExpect(jsonPath("$[0].runSizing.requests.cpu").value("cpu_requests2"))
.andExpect(jsonPath("$[0].runSizing.requests.memory").value("memory_requests2"))
.andExpect(jsonPath("$[0].runSizing.limits.cpu").value("cpu_limits2"))
.andExpect(jsonPath("$[0].runSizing.limits.memory").value("memory_limits2"))
.andExpect(jsonPath("$[0].parameterGroups").value(mutableListOf(parameterGroupId)))
.andExpect(jsonPath("$[0].executionTimeout").value(100))
.andExpect(jsonPath("$.id").value(runTemplateId))
.andExpect(jsonPath("$.name").value(runTemplateName))
.andExpect(jsonPath("$.labels").value(parameterLabels))
.andExpect(jsonPath("$.description").value(description))
.andExpect(jsonPath("$.tags").value(tags))
.andExpect(jsonPath("$.computeSize").value(runTemplateComputeSize))
.andExpect(jsonPath("$.runSizing.requests.cpu").value("cpu_requests2"))
.andExpect(jsonPath("$.runSizing.requests.memory").value("memory_requests2"))
.andExpect(jsonPath("$.runSizing.limits.cpu").value("cpu_limits2"))
.andExpect(jsonPath("$.runSizing.limits.memory").value("memory_limits2"))
.andExpect(jsonPath("$.parameterGroups").value(mutableListOf(parameterGroupId)))
.andExpect(jsonPath("$.executionTimeout").value(100))
.andDo(MockMvcResultHandlers.print())
.andDo(
document(
"organizations/{organization_id}/solutions/{solution_id}/runTemplates/{run_template_id}/PATCH"))
}

@Test
@WithMockOauth2User
fun delete_solution_runTemplate() {

val description = "this_is_a_description"
val tags = mutableListOf("tag1", "tag2")
val parameterLabels = mutableMapOf("fr" to "this_is_a_label")
val parameterGroupId = "parameterGroup1"
val runTemplateId = "runtemplate1"
val runTemplateName = "this_is_a_name"
val runTemplateComputeSize = "this_is_a_compute_size"
val runTemplateRunSizing =
RunTemplateResourceSizing(
ResourceSizeInfo("cpu_requests", "memory_requests"),
ResourceSizeInfo("cpu_limits", "memory_limits"))
val runTemplates =
mutableListOf(
RunTemplateCreateRequest(
runTemplateId,
runTemplateName,
parameterLabels,
description,
tags,
runTemplateComputeSize,
runTemplateRunSizing,
mutableListOf(parameterGroupId),
10))

val solutionId =
createSolutionAndReturnId(
mvc, organizationId, constructSolutionCreateRequest(runTemplates = runTemplates))

mvc.perform(
delete(
"/organizations/$organizationId/solutions/$solutionId/runTemplates/$runTemplateId")
.contentType(MediaType.APPLICATION_JSON)
.with(csrf()))
.andExpect(status().is2xxSuccessful)
.andDo(MockMvcResultHandlers.print())
.andDo(
document(
"organizations/{organization_id}/solutions/{solution_id}/runTemplates/{run_template_id}/DELETE"))
}

@Test
@WithMockOauth2User
fun get_solution_security() {
Expand Down
Loading
Loading