Skip to content

Commit

Permalink
feat: add authenticate_response model
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdaemon committed May 13, 2024
1 parent 0efdc56 commit e0ea838
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/gvm_sync_targets/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
from gvm.transforms import EtreeCheckCommandTransform

from gvm_sync_targets.models.assets_response import GetAssetsResponse
from gvm_sync_targets.models.auth_response import AuthenticateResponse
from gvm_sync_targets.models.model import Model
from gvm_sync_targets.util import Element

_MODEL_MAP: Mapping[str, type[Model]] = {
"get_assets_response": GetAssetsResponse,
"authenticate_response": AuthenticateResponse,
}


Expand Down
15 changes: 15 additions & 0 deletions src/gvm_sync_targets/models/auth_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SPDX-FileCopyrightText: 2024-present linuxdaemon <linuxdaemon.irc@gmail.com>
#
# SPDX-License-Identifier: MIT

from pydantic_xml import attr, element

from gvm_sync_targets.models.model import Model


class AuthenticateResponse(Model, tag="authenticate_response"):
status: int = attr("status")
status_text: str = attr("status_text")

role: str = element()
timezone: str = element()
18 changes: 18 additions & 0 deletions tests/gvm_sync_targets/models/auth_response_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2024-present linuxdaemon <linuxdaemon.irc@gmail.com>
#
# SPDX-License-Identifier: MIT

from gvm_sync_targets.models import AuthenticateResponse

data = """
<authenticate_response status="200" status_text="OK">
<role>Admin</role>
<timezone>UTC</timezone>
</authenticate_response>
"""


def test_auth_response():
model = AuthenticateResponse.from_xml(data)
assert model.role == "Admin"
assert model.timezone == "UTC"

0 comments on commit e0ea838

Please sign in to comment.