Skip to content

Commit

Permalink
tests/dsp2043 - update using 2024.3
Browse files Browse the repository at this point in the history
  • Loading branch information
commonism committed Dec 31, 2024
1 parent 7b1a5d1 commit 7c63875
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 30 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ jobs:
name: Get description documents
run: |
mkdir ~/www-data
wget --directory-prefix=$HOME/www-data https://www.dmtf.org/sites/default/files/standards/documents/DSP2043_2024.1.zip
wget --directory-prefix=$HOME/www-data https://www.dmtf.org/sites/default/files/standards/documents/DSP8010_2024.1.zip
wget --directory-prefix=$HOME/www-data https://www.snia.org/sites/default/files/technical-work/swordfish/release/v1.2.6/zip/Swordfish_v1.2.6.zip
unzip $HOME/www-data/Swordfish_v1.2.6.zip '*_Schema.zip' -d $HOME/www-data/
wget --directory-prefix=$HOME/www-data https://www.dmtf.org/sites/default/files/standards/documents/DSP2043_2024.3.zip
wget --directory-prefix=$HOME/www-data https://www.dmtf.org/sites/default/files/standards/documents/DSP8010_2024.3.zip
wget --directory-prefix=$HOME/www-data https://www.snia.org/sites/default/files/technical-work/swordfish/release/v1.2.7/zip/Swordfish_v1.2.7.zip
unzip $HOME/www-data/Swordfish_v1.2.7.zip '*_Schema.zip' -d $HOME/www-data/
- name: service::mock - unzip DSP8010 public-rackmount1
run: |
ls -al ${{ github.workspace }}/tmp/DSP8010/public-rackmount1/
mkdir -p ${{ github.workspace }}/tmp/DSP8010/public-rackmount1
ls -al ${{ github.workspace }}/tmp/DSP8010/public-rackmount1
sudo touch ${{ github.workspace }}/tmp/DSP8010/public-rackmount1/test
sudo unzip $HOME/www-data/DSP2043_2024.1.zip "public-rackmount1/*" -d ${{ github.workspace }}/tmp/DSP8010/
sudo unzip $HOME/www-data/DSP2043_2024.3.zip "public-rackmount1/*" -d ${{ github.workspace }}/tmp/DSP8010/
- name: service::mock - copy service files
uses: docker://docker
Expand All @@ -78,9 +78,9 @@ jobs:
working-directory: ./code
run: |
mkdir -p src/aiopenapi3_redfish/description_documents/DSP8010/2024.1/
unzip -j ~/www-data/DSP8010_2024.1.zip 'openapi/*.yaml' -d src/aiopenapi3_redfish/description_documents/DSP8010/2024.1/
mkdir -p src/aiopenapi3_redfish/description_documents/Swordfish/v1.2.6/
unzip -j ~/www-data/Swordfish_v1.2.6_Schema.zip 'yaml/*.yaml' -d src/aiopenapi3_redfish/description_documents/Swordfish/v1.2.6/
unzip -j ~/www-data/DSP8010_2024.3.zip 'openapi/*.yaml' -d src/aiopenapi3_redfish/description_documents/DSP8010/2024.3/
mkdir -p src/aiopenapi3_redfish/description_documents/Swordfish/v1.2.7/
unzip -j ~/www-data/Swordfish_v1.2.7_Schema.zip 'yaml/*.yaml' -d src/aiopenapi3_redfish/description_documents/Swordfish/v1.2.7/
pdm run pytest --cov=tests/test_description_documents --cov-report=xml:../coverage/reports/coverage-description_documents-tests.xml tests/description_documents_test.py
- name: Generate coverage report (DSP 2043)
working-directory: ./code
Expand All @@ -92,6 +92,11 @@ jobs:
run: |
pdm run pytest --cov=src/aiopenapi3_redfish/ --cov-report=xml:../coverage/reports/coverage-mock.xml tests/mock_test.py::test_iter
pdm run pytest --cov=tests/ --cov-report=xml:../coverage/reports/coverage-mock-tests.xml tests/mock_test.py::test_iter
- name: Generate coverage report (taskset)
working-directory: ./code
run: |
pdm run pytest --cov=src/aiopenapi3_redfish/ --cov-report=xml:../coverage/reports/coverage-mock.xml tests/mock_test.py::test_iter
pdm run pytest --cov=tests/ --cov-report=xml:../coverage/reports/coverage-mock-tests.xml tests/mock_test.py::test_iter
- name: Upload coverage to Codecov (core)
uses: codecov/codecov-action@v4
with:
Expand Down
93 changes: 72 additions & 21 deletions tests/dsp2043_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import dataclasses
import zipfile
from pathlib import Path
import textwrap

import yarl
import httpx
import json
from pydantic import ValidationError

import pytest
import pytest_asyncio
Expand Down Expand Up @@ -65,8 +68,8 @@ def config(description_documents, target):
# MockMessage(),
],
locations=[
RedirectLoader(description_documents / "DSP8010" / "2024.1"),
RedirectLoader(description_documents / "Swordfish" / "v1.2.6"),
RedirectLoader(description_documents / "DSP8010" / "2024.3"),
RedirectLoader(description_documents / "Swordfish" / "v1.2.7"),
],
cache=Path("/tmp/test_new.pickle"),
)
Expand Down Expand Up @@ -95,9 +98,26 @@ async def _request_send(self, req, parameters, data, context=None, **kwargs):
data = json.loads(p.read_text())
r = aiopenapi3.request.RequestBase.Response(headers={}, data=data, result=None)
try:
return req.operation.responses["200"].content["application/json"].schema_.model(r.data)
except Exception as e:
raise e
expectation = req.operation.responses["200"].content["application/json"].schema_
return expectation.model(r.data)
except ValidationError as e:
request = httpx.Request("GET", str(url), params=parameters)

@dataclasses.dataclass
class MockResponse:
request: httpx.Request
data: "JSON"

def json(self):
return self.data

raise aiopenapi3.errors.ResponseSchemaError(
operation=req.operation,
expectation=expectation,
schema=None,
response=MockResponse(request=request, data=data),
exception=e,
)


class MockDocument(aiopenapi3.plugin.Document):
Expand All @@ -112,16 +132,22 @@ def parsed(self, ctx: aiopenapi3.plugin.Document.Context) -> aiopenapi3.plugin.D


def dsp2043zip():
url = yarl.URL("https://www.dmtf.org/sites/default/files/standards/documents/DSP2043_2024.1.zip")
url = yarl.URL("https://www.dmtf.org/sites/default/files/standards/documents/DSP2043_2024.3.zip")

for i in ["~/www-data", "/tmp/"]:
if (p := Path(i).expanduser() / Path(url.path).name).exists():
return zipfile.Path(p)
f = zipfile.Path(p)
if (v := (f / p.stem)).exists() and v.is_dir():
return v
return f

with httpx.Client() as f:
r = f.get(str(url))
(p := (Path("/tmp/") / url.name)).write_bytes(r.content)
return zipfile.Path(p)
f = zipfile.Path(p)
if (v := (f / p.stem)).exists() and v.is_dir():
return v
return f


def pytest_generate_tests(metafunc):
Expand All @@ -135,7 +161,8 @@ def pytest_generate_tests(metafunc):
for info in zipfile.root.infolist():
if info.is_dir():
continue
rfile = (file := Path(info.filename)).relative_to(dsp2043 := file.parts[0])
file = Path(info.filename)
rfile = file.relative_to(dsp2043 := file.parts[0])
if not dsp2043.startswith("public-"):
continue
if rfile.parts[0] in {"$metadata", "explorer_config.json"}:
Expand Down Expand Up @@ -191,7 +218,11 @@ async def test_single_fail(client):
mock = "public-liquid-cooled-server"
file = "ComponentIntegrity/SS-SPDM-0/index.json"
client.dsp2043 = dsp2043zip() / mock
await _test_single_file(client, Path(file))
try:
await _test_single_file(client, Path(file))
except Exception as e:
client.log.exception(e)
raise


@pytest.mark.asyncio
Expand All @@ -203,10 +234,18 @@ async def test_single_pass(client):


@pytest.mark.asyncio
async def test_iter(client):
async def test_iter(caplog, client, dsp2043):
import logging

caplog.set_level(logging.WARNING, logger="asyncio")

print(f"## {dsp2043.name}")
pages: set[yarl.URL] = set()
todo = set()

indent = " "
wrapper = textwrap.TextWrapper(initial_indent=indent, width=250, subsequent_indent=" " * len(indent))

from typing import Any
import pydantic

Expand Down Expand Up @@ -239,9 +278,6 @@ def _find_links(data: pydantic.BaseModel | list[Any] | dict[str, Any]) -> set[st
pass
return links

# import collections
# Page = collections.namedtuple("Page", field_names=["routepath", "parameters", "data", "response"])

class RoutingError(Exception):
pass

Expand All @@ -258,16 +294,31 @@ async def visit(t: yarl.URL) -> pydantic.BaseModel | list[Any] | dict[str, Any]:
r = await get(t)
return r
except aiopenapi3.errors.ResponseSchemaError as rse:
print(f"{rse.__class__.__name__} {t} {rse}")
print(f"### {rse.__class__.__name__} {t}")
print("```")
print(textwrap.indent(str(rse.exception), "\t"))
print("```")
print("")
return rse.response.json()
except aiopenapi3.errors.ResponseError as rer:
print(f"{rer.__class__.__name__} {t} {rer}")
print(f"### {rer.__class__.__name__} {t}")
print("```")
print(textwrap.indent(str(rer), "\t"))
print("```")
print("")
except RoutingError as ror:
print(f"{ror.__class__.__name__} {t} {ror}")
except KeyError as ke:
print(f"{ke.__class__.__name__} {t} {ke}")
except pydantic.ValidationError as ve:
print(f"{ve.__class__.__name__} {t} {ve}")
print(f"### {ror.__class__.__name__} {t}")
print("```")
print(textwrap.indent(str(ror), "\t"))
print("```")
print("")

client.dsp2043 = dsp2043

try:
await client.asyncInit()
except Exception:
return

todo |= _find_links(client._serviceroot._v) - pages

Expand Down
4 changes: 3 additions & 1 deletion tests/mock_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import string
from pathlib import Path
import random

from pathlib import Path


Expand Down Expand Up @@ -240,7 +241,8 @@ async def visit(t) -> pydantic.BaseModel | list[Any] | dict[str, Any]:
r = await get(t)
return r.data
except aiopenapi3.errors.ResponseSchemaError as rse:
print(f"{rse.__class__.__name__} {t} {rse}")
print(f"{rse.__class__.__name__} {t}")
print()
return rse.response.json()
except aiopenapi3.errors.ResponseError as rer:
print(f"{rer.__class__.__name__} {t} {rer}")
Expand Down

0 comments on commit 7c63875

Please sign in to comment.