|
| 1 | +# Copyright (c) 2026 the Eclipse BaSyx Authors |
| 2 | +# |
| 3 | +# This program and the accompanying materials are made available under the terms of the MIT License, available in |
| 4 | +# the LICENSE file of this project. |
| 5 | +# |
| 6 | +# SPDX-License-Identifier: MIT |
| 7 | + |
| 8 | +import base64 |
| 9 | +import json |
| 10 | +import unittest |
| 11 | + |
| 12 | +from basyx.aas import model |
| 13 | +from basyx.aas.adapter.aasx import DictSupplementaryFileContainer |
| 14 | +from basyx.aas.examples.data.example_aas import create_full_example |
| 15 | +from werkzeug.test import Client |
| 16 | + |
| 17 | +from app.interfaces.repository import WSGIApp |
| 18 | + |
| 19 | +BASE_PATH = "/api/v3.1" |
| 20 | + |
| 21 | + |
| 22 | +def _encode_asset_id(name: str, value: str) -> str: |
| 23 | + payload = json.dumps({"name": name, "value": value}) |
| 24 | + return base64.urlsafe_b64encode(payload.encode()).decode() |
| 25 | + |
| 26 | + |
| 27 | +class ShellsAssetIdsTest(unittest.TestCase): |
| 28 | + def setUp(self) -> None: |
| 29 | + self.example_data = create_full_example() |
| 30 | + app = WSGIApp(self.example_data, DictSupplementaryFileContainer()) |
| 31 | + self.client = Client(app) |
| 32 | + |
| 33 | + def test_multiple_global_asset_ids_returns_matching_results(self) -> None: |
| 34 | + aas_list = [obj for obj in self.example_data if isinstance(obj, model.AssetAdministrationShell)] |
| 35 | + known_id = aas_list[0].asset_information.global_asset_id |
| 36 | + unknown_id = "http://example.org/nonexistent_asset" |
| 37 | + id1 = _encode_asset_id("globalAssetId", known_id) |
| 38 | + id2 = _encode_asset_id("globalAssetId", unknown_id) |
| 39 | + response = self.client.get(f"{BASE_PATH}/shells?assetIds={id1}&assetIds={id2}") |
| 40 | + self.assertEqual(200, response.status_code) |
| 41 | + result = json.loads(response.data) |
| 42 | + returned_ids = [r["id"] for r in result] |
| 43 | + self.assertIn(aas_list[0].id, returned_ids) |
0 commit comments