Skip to content
Open
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
5 changes: 3 additions & 2 deletions server/app/interfaces/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ def get_all_specific_asset_ids_by_aas_id(
) -> Response:
aas_identifier = str(url_args["aas_id"])
asset_ids = self.persistent_store.get_all_specific_asset_ids_by_aas_id(aas_identifier)
if not asset_ids:
raise werkzeug.exceptions.NotFound(f"AAS {aas_identifier!r} has no asset links!")
return response_t(asset_ids)

def post_all_asset_links_by_id(
Expand All @@ -209,8 +211,7 @@ def post_all_asset_links_by_id(
specific_asset_ids = HTTPApiDecoder.request_body_list(request, model.SpecificAssetId, False)
self.persistent_store.delete_specific_asset_ids_by_aas_id(aas_identifier)
self.persistent_store.add_specific_asset_ids_to_aas(aas_identifier, specific_asset_ids)
updated = {aas_identifier: self.persistent_store.get_all_specific_asset_ids_by_aas_id(aas_identifier)}
return response_t(updated, status=201)
return response_t(self.persistent_store.get_all_specific_asset_ids_by_aas_id(aas_identifier), status=201)

def delete_all_asset_links_by_id(
self, request: Request, url_args: dict, response_t: Type[APIResponse], **_kwargs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def test_asset_link_roundtrip(self):
)
with urllib.request.urlopen(post_request) as response:
self.assertEqual(201, response.status)
self.assertEqual([self.ASSET_LINK], json.loads(response.read()))

with urllib.request.urlopen(aas_asset_links_path) as response:
self.assertEqual(200, response.status)
Expand All @@ -83,6 +84,6 @@ def test_asset_link_roundtrip(self):
with urllib.request.urlopen(delete_request) as response:
self.assertEqual(204, response.status)

with urllib.request.urlopen(aas_asset_links_path) as response:
self.assertEqual(200, response.status)
self.assertEqual([], json.loads(response.read()))
with self.assertRaises(urllib.error.HTTPError) as context:
urllib.request.urlopen(aas_asset_links_path)
self.assertEqual(404, context.exception.code)
31 changes: 12 additions & 19 deletions server/test/interfaces/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
Endpoint tests for :class:`~app.interfaces.discovery.DiscoveryAPI`.

The routes follow the *Discovery Service Specification* (SSP-001, "full" profile) from ``aas-specs-api``.
Where this server deviates from the spec's documented status codes, the test asserts the *implemented*
behavior and the deviation is called out in a comment.

Requests and responses go through the shared :class:`~..format_utils.JsonFormatClient` (as in
``test/interfaces/repository/test_shells.py``). Only ``GET /lookup/shells/{aasIdentifier}`` returns
``test/interfaces/repository/test_shells.py``). ``GET /lookup/shells/{aasIdentifier}`` returns
AAS model objects (``SpecificAssetId``), so it is additionally run against the XML
:class:`~..format_utils.FormatClient`; every other route returns plain strings / JSON objects that the
SDK XML serializer cannot render, so those are JSON only.
:class:`~..format_utils.FormatClient`. ``POST /lookup/shells/{aasIdentifier}`` also returns
``SpecificAssetId`` objects but is tested with JSON only; every other route returns plain strings / JSON
objects that the SDK XML serializer cannot render, so those are JSON only.
"""

import json
Expand Down Expand Up @@ -216,12 +215,8 @@ def test_get_returns_stored_asset_ids(self, format_client: FormatClient) -> None

@with_json_client
@with_xml_client
def test_get_unknown_aas_returns_empty(self, format_client: FormatClient) -> None:
# Spec allows 404 here; this server returns 200 with an empty collection instead.
response = format_client.get(f"/lookup/shells/{base64url_encode(self.UNKNOWN_ID)}")

self.assertEqual(200, response.status_code, msg=response.get_data(as_text=True))
self.assertEqual([], format_client.parse_collection(response))
def test_get_unknown_aas_returns_404(self, format_client: FormatClient) -> None:
self.assert_error(format_client.get(f"/lookup/shells/{base64url_encode(self.UNKNOWN_ID)}"), 404)

# ------------------------------------------------------------------ POST

Expand All @@ -232,8 +227,9 @@ def test_post_creates_asset_links(self) -> None:
)

self.assertEqual(201, response.status_code, msg=response.get_data(as_text=True))
body = self.format_client.parse_object(response)
self.assertEqual([("serial", "123")], [(a["name"], a["value"]) for a in body[self.AAS_ID]])
self.assertEqual(
[("serial", "123")], [(a["name"], a["value"]) for a in self.format_client.parse_collection(response)]
)
self.assertEqual(
[self.AAS_ID],
self.format_client.parse_collection(
Expand All @@ -249,7 +245,7 @@ def test_post_accepts_single_object_body(self) -> None:
self.assertEqual(201, response.status_code, msg=response.get_data(as_text=True))
self.assertEqual(
[("serial", "123")],
[(a["name"], a["value"]) for a in self.format_client.parse_object(response)[self.AAS_ID]],
[(a["name"], a["value"]) for a in self.format_client.parse_collection(response)],
)

def test_post_replaces_existing_asset_links(self) -> None:
Expand All @@ -262,7 +258,7 @@ def test_post_replaces_existing_asset_links(self) -> None:
)

self.assertEqual(201, response.status_code, msg=response.get_data(as_text=True))
stored = {(a["name"], a["value"]) for a in self.format_client.parse_object(response)[self.AAS_ID]}
stored = {(a["name"], a["value"]) for a in self.format_client.parse_collection(response)}
self.assertEqual({("batch", "xyz")}, stored)
self.assertEqual(
[],
Expand All @@ -286,10 +282,7 @@ def test_delete_removes_asset_links(self) -> None:
response = self.format_client.delete(f"/lookup/shells/{base64url_encode(self.AAS_ID)}")

self.assertEqual(204, response.status_code, msg=response.get_data(as_text=True))
self.assertEqual(
[],
self.format_client.parse_object(self.format_client.get(f"/lookup/shells/{base64url_encode(self.AAS_ID)}")),
)
self.assert_error(self.format_client.get(f"/lookup/shells/{base64url_encode(self.AAS_ID)}"), 404)
self.assertEqual(
[],
self.format_client.parse_collection(
Expand Down