-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
187 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,88 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# Licensed under the Apache V2, see LICENCE file for details. | ||
from __future__ import annotations | ||
|
||
import json | ||
import pytest | ||
from typing import Dict, List | ||
from typing import reveal_type as reveal_type | ||
|
||
from juju.application import Application | ||
from juju.client.facade import _convert_response | ||
from juju.client._definitions import FullStatus | ||
from juju.model import Model | ||
from juju.unit import Unit | ||
|
||
|
||
@pytest.fixture | ||
def full_status_response(pytestconfig: pytest.Config) -> dict: | ||
return json.loads(((pytestconfig.rootpath / "fullstatus.json")).read_text()) | ||
|
||
|
||
def test_foo(full_status_response): | ||
def test_foo(full_status_response: dict): | ||
# tweak the response here | ||
fs = _convert_response(full_status_response, cls=FullStatus) | ||
reveal_type(fs) | ||
|
||
assert fs.applications | ||
assert fs.applications["hexanator"] | ||
|
||
hexanator = fs.applications["hexanator"] | ||
assert hexanator.status # DetailedStatus | ||
assert hexanator.status.status == "active" | ||
assert hexanator.status.info == "" | ||
|
||
assert fs.applications["grafana-agent-k8s"] | ||
grafana = fs.applications["grafana-agent-k8s"] # ApplicationStatus | ||
|
||
assert grafana.units["grafana-agent-k8s/0"] | ||
grafana0 = grafana.units["grafana-agent-k8s/0"] | ||
|
||
assert grafana0.workload_status # DetailedStatus | ||
assert isinstance(grafana0.workload_status.info, str) | ||
|
||
assert grafana0.workload_status.info.startswith("Missing") | ||
|
||
|
||
class ModelFake(Model): | ||
_applications: Dict[str, Application] | ||
|
||
@property | ||
def applications(self) -> Dict[str, Application]: | ||
return self._applications | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self._applications = {} | ||
|
||
|
||
class ApplicationFake(Application): | ||
_status: str = "" | ||
_status_message: str = "" | ||
_units: List[Unit] | ||
|
||
@property | ||
def status(self) -> str: | ||
return self._status | ||
|
||
@property | ||
def status_message(self) -> str: | ||
return self._status_message | ||
|
||
@property | ||
def units(self) -> List[Unit]: | ||
return self._units | ||
|
||
async def test_something(full_status_response): | ||
m = Model() | ||
rv = await m._legacy_check_idle( | ||
apps=[], | ||
raise_on_error=False, | ||
raise_on_blocked=False, | ||
status=None, | ||
wait_for_at_least_units=None, | ||
wait_for_exact_units=None, | ||
timeout=100, | ||
idle_period=100, | ||
_wait_for_units=1, | ||
) | ||
assert rv == 42 |