Skip to content

Commit

Permalink
chore: more hookup
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaqq committed Oct 3, 2024
1 parent 20da616 commit 22922d4
Showing 1 changed file with 48 additions and 16 deletions.
64 changes: 48 additions & 16 deletions tests/unit/test_wait_for_idle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import json
import pytest
from typing import Dict, List
from typing import Any, Dict, List
from typing import reveal_type as reveal_type
from unittest.mock import Mock

from juju.application import Application
from juju.client.facade import _convert_response
Expand Down Expand Up @@ -45,15 +46,25 @@ def test_foo(full_status_response: dict):

class ModelFake(Model):
_applications: Dict[str, Application]
_response: Dict

@property
def applications(self) -> Dict[str, Application]:
return self._applications

def __init__(self):
super().__init__()
self._applications = {}

def connection(self):
rv = Mock()
rv.facades = {"Client": 6} # Must match juju.client.connection.client_facades
rv.rpc = self.rpc
return rv

async def rpc(self, msg, encoder=None):
return self._response


class ApplicationFake(Application):
_status: str = ""
Expand All @@ -70,19 +81,40 @@ def status_message(self) -> str:

@property
def units(self) -> List[Unit]:
1/0
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

@pytest.fixture
def kwargs() -> Dict[str, Any]:
return dict(
apps=["hexanator", "grafana-agent-k8s"],
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,
)


async def test_something(full_status_response, kwargs: Dict[str, Any]):
m = ModelFake()
m._response = full_status_response
m._applications["hexanator"] = ApplicationFake("hexanator", m)
m._applications["grafana-agent-k8s"] = ApplicationFake("grafana-agent-k8s", m)

try:
idle = await m._check_idle(**kwargs)
except Exception as e:
idle = e

try:
legacy = await m._legacy_check_idle(**kwargs)
except Exception as e:
raise
legacy = e

assert idle == legacy

0 comments on commit 22922d4

Please sign in to comment.