From 503b9d93507cd8635b82a5dd40eca00e4a2f18bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Otto?= Date: Mon, 21 Oct 2024 10:12:34 +0200 Subject: [PATCH] Check pagination for GetAllSubmodelReferences (fixes #68) --- aas_test_engines/api.py | 68 ++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 11 deletions(-) diff --git a/aas_test_engines/api.py b/aas_test_engines/api.py index 7bf2d30..146d000 100644 --- a/aas_test_engines/api.py +++ b/aas_test_engines/api.py @@ -566,7 +566,6 @@ def setup(self): request = generate_one_valid(op, self.sample_cache, {'limit': 1}) data = _invoke_and_decode(request, self.conf, True) self.valid_id_short: str = _lookup(data, ['result', 0, 'idShort']) - self.second_id_short: Optional[str] = _lookup(data, ['result', 1, 'idShort'], None) self.cursor = _lookup(data, ['paging_metadata', 'cursor'], None) def test_no_parameters(self): @@ -598,14 +597,12 @@ def test_pagination(self): """ Test pagination """ - if self.cursor is None or self.second_id_short is None: + if self.cursor is None: abort("Cannot check pagination, there must be at least 2 shells", level=Level.WARNING) request = generate_one_valid(self.operation, self.sample_cache, {'cursor': self.cursor, 'limit': 1}) data = _invoke_and_decode(request, self.conf, True) data = _lookup(data, ['result']) _assert(len(data) == 1, 'Exactly one entry') - data = _lookup(data, [0, 'idShort']) - _assert(self.second_id_short == data, 'Returns second') @operation("GetAllAssetAdministrationShells") @@ -668,17 +665,65 @@ def test_simple(self): _assert(data == self.valid_id, 'Returned the correct one') # /shells//submodels -# /shells//submodel-refs -@operation("GetAllSubmodelReferences_AasRepository") @operation("GetAllSubmodels_AasRepository") @operation("GetAllSubmodels_AasRepository Metadata") @operation("GetAllSubmodels_AasRepository-ValueOnly") @operation("GetAllSubmodels_AasRepository-Reference") @operation("GetAllSubmodels_AasRepository-Path") -@operation("GetAssetInformation_AasRepository") -class AasBySuperpathSuite(ApiTestSuite): +class GetAllSubmodelsTestSuite(ApiTestSuite): + def setup(self): + op = self.open_api.operations["GetAllAssetAdministrationShells"] + request = generate_one_valid(op, self.sample_cache, {'limit': 1}) + data = _invoke_and_decode(request, self.conf, True) + self.valid_id = _lookup(data, ['result', 0, 'id']) + + def test_simple(self): + """ + Fetch by id + """ + request = generate_one_valid(self.operation, self.sample_cache, {'aasIdentifier': b64urlsafe(self.valid_id)}) + _invoke_and_decode(request, self.conf, True) + + +# /shells//submodel-refs + + +@operation("GetAllSubmodelReferences_AasRepository") +class GetAllSubmodelRefsTestSuite(ApiTestSuite): + def setup(self): + op = self.open_api.operations["GetAllAssetAdministrationShells"] + request = generate_one_valid(op, self.sample_cache, {'limit': 1}) + data = _invoke_and_decode(request, self.conf, True) + self.valid_id = _lookup(data, ['result', 0, 'id']) + request = generate_one_valid(self.operation, self.sample_cache, {'aasIdentifier': b64urlsafe(self.valid_id), 'limit': 1}) + data = _invoke_and_decode(request, self.conf, True) + self.cursor = _lookup(data, ['paging_metadata', 'cursor'], None) + + def test_simple(self): + """ + Fetch by id + """ + request = generate_one_valid(self.operation, self.sample_cache, {'aasIdentifier': b64urlsafe(self.valid_id)}) + _invoke_and_decode(request, self.conf, True) + + def test_pagination(self): + """ + Check pagination + """ + if self.cursor is None: + abort("Cannot check pagination, there must be at least 2 shells", level=Level.WARNING) + request = generate_one_valid(self.operation, self.sample_cache, {'aasIdentifier': b64urlsafe(self.valid_id), 'cursor': self.cursor, 'limit': 1}) + data = _invoke_and_decode(request, self.conf, True) + data = _lookup(data, ['result']) + _assert(len(data) == 1, 'Exactly one entry') + + +# /shells//asset-information + + +class AssetInfoTestSuiteBase(ApiTestSuite): def setup(self): op = self.open_api.operations["GetAllAssetAdministrationShells"] request = generate_one_valid(op, self.sample_cache, {'limit': 1}) @@ -688,6 +733,9 @@ def setup(self): 'aasIdentifier': [b64urlsafe(self.valid_id)] } + +@operation("GetAssetInformation_AasRepository") +class AssetInfoBySuperPathSuite(AssetInfoTestSuiteBase): def test_simple(self): """ Fetch by id @@ -695,11 +743,9 @@ def test_simple(self): request = generate_one_valid(self.operation, self.sample_cache, {'aasIdentifier': b64urlsafe(self.valid_id)}) _invoke_and_decode(request, self.conf, True) -# /shells//asset-information - @operation('GetThumbnail_AasRepository') -class AasThumbnailBySuperpathSuite(ApiTestSuite): +class AasThumbnailBySuperPathSuite(AssetInfoTestSuiteBase): def setup(self): op = self.open_api.operations["GetAllAssetAdministrationShells"] request = generate_one_valid(op, self.sample_cache, {'limit': 1})