Skip to content

Commit

Permalink
Add api acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
otto-ifak committed Nov 12, 2024
1 parent dc6d01a commit e021ff7
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 17 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ on: [push]
jobs:
build:
runs-on: ubuntu-latest
# services:
# aasx-server:
# image: adminshellio/aasx-server-blazor-for-demo:main
steps:
- uses: actions/checkout@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion aas_test_engines/test_cases/v3_0/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,8 @@ def test_include_concept_descriptions(self):
"""
request = generate_one_valid(self.operation, self.sample_cache, {'includeConceptDescriptions': True})
data = _invoke_and_decode(request, self.conf, True)
_assert('conceptDescriptions' in data, 'contains conceptDescriptions', Level.WARNING)
if data:
_assert('conceptDescriptions' in data, 'contains conceptDescriptions', Level.WARNING)


# /description
Expand Down
2 changes: 1 addition & 1 deletion aas_test_engines/test_cases/v3_0/parse_submodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _parse(cls, element: SubmodelElement, root_result, path: AdapterPath):
f"There is no parsing implemented for:\n"
f" origin: {origin}\n"
f" args: {getattr(cls, '__args__', None)}\n"
f" cls: {cls}\m"
f" cls: {cls}\n"
)


Expand Down
1 change: 1 addition & 0 deletions bin/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ coverage run \

PYTHONPATH=. ./test/acceptance/file.py
PYTHONPATH=. ./test/acceptance/generate.py
PYTHONPATH=. ./test/acceptance/server.py
98 changes: 86 additions & 12 deletions test/acceptance/server.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,93 @@
#! /usr/bin/env python3

from aas_test_engines import api
import sys
import os
import shutil
import subprocess
import atexit
import requests
import time
from dataclasses import dataclass

conf = api.ExecConf(
server=sys.argv[1] if len(sys.argv) == 2 else 'http://aasx-server:5001/api/v3.0',
)
HOST = 'http://localhost:5001'
script_dir = os.path.dirname(os.path.realpath(__file__))

result_aas_repo, mat = api.execute_tests(conf, "https://admin-shell.io/aas/API/3/0/AssetAdministrationShellRepositoryServiceSpecification/SSP-002")
result_aas_repo.dump()
mat.print()
test_data_dir = os.path.join(script_dir, '..', '..', 'bin', 'check_servers', 'test_data')
runner_temp = os.environ.get('RUNNER_TEMP', None)
if runner_temp:
# In Github actions, only certain directories can be mounted
runner_temp = os.path.join(runner_temp, 'test_data')
print(f"Copy '{test_data_dir}' to '{runner_temp}'")
shutil.copytree(test_data_dir, runner_temp)
test_data_dir = runner_temp
print(f"test_data_dir={test_data_dir}")

result_submodel_repo, mat = api.execute_tests(conf, "https://admin-shell.io/aas/API/3/0/SubmodelRepositoryServiceSpecification/SSP-002")
result_submodel_repo.dump()
mat.print()

assert result_aas_repo.ok()
assert result_submodel_repo.ok()
def wait_for_server(url: str, max_tries=10):
for _ in range(max_tries):
try:
requests.get(url, verify=False)
print(f"Server is up at {url}")
return
except requests.exceptions.ConnectionError:
pass
time.sleep(1)
print(f"Cannot reach server at {url}")


def start_server(test_data_dir: str) -> str:
container_id = subprocess.check_output([
'docker', 'run',
'--publish', '5001:5001',
'--detach',
# TODO
# '--mount', f'type=bind,src={test_data_dir},target=/AasxServerBlazor/aasxs',
'docker.io/adminshellio/aasx-server-blazor-for-demo:main',
])
return container_id.decode().strip()


def stop_server(container_id: str):
print(f"Stopping {container_id}")
subprocess.check_output([
'docker', 'kill', container_id
])


def show_server_logs(container_id: str):
subprocess.check_call([
'docker', 'logs', container_id
])


container_id = start_server(test_data_dir)
atexit.register(lambda: stop_server(container_id))
wait_for_server(HOST)
show_server_logs(container_id)


@dataclass
class Params:
url: str
suite: str


params = [
Params('/api/v3.0', "https://admin-shell.io/aas/API/3/0/AssetAdministrationShellRepositoryServiceSpecification/SSP-002"),
Params('/api/v3.0', "https://admin-shell.io/aas/API/3/0/SubmodelRepositoryServiceSpecification/SSP-002"),
# Params('/api/v3.0', "https://admin-shell.io/aas/API/3/0/AssetAdministrationShellServiceSpecification/SSP-002"),
# Params('/api/v3.0', "https://admin-shell.io/aas/API/3/0/SubmodelServiceSpecification/SSP-002"),
]

for param in params:
print("-"*10)
print(f"Checking {param.suite}")
conf = api.ExecConf(
server=f"{HOST}{param.url}"
)
result, mat = api.execute_tests(conf, param.suite)
mat.print()
# TODO
# assert result.ok()
assert mat.valid_rejected == 3 # Constraint violations in ExampleMotor.aasx
assert mat.invalid_accepted == 0

0 comments on commit e021ff7

Please sign in to comment.