Skip to content

Commit

Permalink
test(restapi): Add content for test manage
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewhand committed Jun 24, 2024
1 parent ad0df5f commit 99eb38a
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
59 changes: 58 additions & 1 deletion src/dioptra/restapi/v1/entrypoints/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,30 @@
from structlog.stdlib import BoundLogger

from dioptra.restapi.db import models
from dioptra.restapi.routes import V1_ENTRYPOINTS_ROUTE
from dioptra.restapi.v1 import utils
from dioptra.restapi.v1.schemas import IdStatusResponseSchema
from dioptra.restapi.v1.shared.drafts.controller import (
generate_resource_drafts_endpoint,
generate_resource_drafts_id_endpoint,
generate_resource_id_draft_endpoint,
)
from dioptra.restapi.v1.shared.snapshots.controller import (
generate_resource_snapshots_endpoint,
generate_resource_snapshots_id_endpoint,
)
from dioptra.restapi.v1.shared.tags.controller import (
generate_resource_tags_endpoint,
generate_resource_tags_id_endpoint,
)

from .schema import (
EntrypointGetQueryParameters,
EntrypointMutableFieldsSchema,
EntrypointPageSchema,
EntrypointSchema,
)
from .service import EntrypointIdService, EntrypointService
from .service import RESOURCE_TYPE, SEARCHABLE_FIELDS, EntrypointIdService, EntrypointService

LOGGER: BoundLogger = structlog.stdlib.get_logger()

Expand Down Expand Up @@ -186,3 +200,46 @@ def put(self, id: int):
),
)
return utils.build_entrypoint(entrypoint)

EntrypointDraftResource = generate_resource_drafts_endpoint(
api,
resource_name=RESOURCE_TYPE,
route_prefix=V1_ENTRYPOINTS_ROUTE,
request_schema=EntrypointSchema,
)
EntrypointDraftIdResource = generate_resource_drafts_id_endpoint(
api,
resource_name=RESOURCE_TYPE,
request_schema=EntrypointMutableFieldsSchema,
)
EntrypointIdDraftResource = generate_resource_id_draft_endpoint(
api,
resource_name=RESOURCE_TYPE,
request_schema=EntrypointMutableFieldsSchema,
)

EntrypointSnapshotsResource = generate_resource_snapshots_endpoint(
api=api,
resource_model=models.EntryPoint,
resource_name=RESOURCE_TYPE,
route_prefix=V1_ENTRYPOINTS_ROUTE,
searchable_fields=SEARCHABLE_FIELDS,
page_schema=EntrypointPageSchema,
build_fn=utils.build_entrypoint,
)
QueueSnapshotsIdResource = generate_resource_snapshots_id_endpoint(
api=api,
resource_model=models.EntryPoint,
resource_name=RESOURCE_TYPE,
response_schema=EntrypointSchema,
build_fn=utils.build_entrypoint,
)

EntrypointTagsResource = generate_resource_tags_endpoint(
api=api,
resource_name=RESOURCE_TYPE,
)
EntrypointTagsIdResource = generate_resource_tags_id_endpoint(
api=api,
resource_name=RESOURCE_TYPE,
)
32 changes: 29 additions & 3 deletions tests/unit/restapi/v1/test_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def test_entrypoint_search_query(
assert_retrieving_entrypoints_works(
client, expected=entrypoint_expected_list, search="description:*entrypoint*"
)
entrypoint_expected_list = list(registered_entrypoints.values())
entrypoint_expected_list = list(registered_entrypoints.values())[:3]
assert_retrieving_entrypoints_works(
client, expected=entrypoint_expected_list, search="*"
)
Expand All @@ -453,7 +453,7 @@ def test_entrypoint_group_query(
default group.
- The returned list of entrypoints matches the expected list owned by the default group.
"""
entrypoint_expected_list = list(registered_entrypoints.values())
entrypoint_expected_list = list(registered_entrypoints.values())[:3]
assert_retrieving_entrypoints_works(
client,
expected=entrypoint_expected_list,
Expand Down Expand Up @@ -602,12 +602,38 @@ def test_manage_existing_entrypoint_draft(
- The request fails with an appropriate error message and response code.
"""
entrypoint = registered_entrypoints["entrypoint1"]
queue = registered_entrypoints["queue"]
name = "draft"
new_name = "draft2"
description = "description"
group_id = entrypoint["group"]["id"]
task_graph = textwrap.dedent(
"""# my entrypoint graph
graph:
message:
my_entrypoint: $name
"""
)
parameters = [
{
"name": "my_entrypoint_param",
"defaultValue": "my_value",
"parameterType": "string",
}
]
plugin_file_ids = [0]
queue_id = queue["id"]

# test creation
payload = {"name": name, "description": description}
payload = {
"name": name,
"description": description,
"group": group_id,
"taskGraph": task_graph,
"parameters": parameters,
"pluginFiles": plugin_file_ids,
"queue": queue_id,
}
expected = {
"user_id": auth_account["id"],
"group_id": entrypoint["group"]["id"],
Expand Down

0 comments on commit 99eb38a

Please sign in to comment.