Skip to content

Commit 654673f

Browse files
committed
Make test keys constants
Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
1 parent 12a18d5 commit 654673f

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/frequenz/client/dispatch/test/_service.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
from .._internal_types import DispatchCreateRequest
3636
from ..types import Dispatch
3737

38+
ALL_KEY = "all"
39+
"""Key that has access to all resources."""
40+
41+
NONE_KEY = "none"
42+
"""Key that has no access to any resources."""
43+
3844

3945
@dataclass
4046
class FakeService:
@@ -75,13 +81,13 @@ def _check_access(self, metadata: grpc.aio.Metadata) -> None:
7581
"No access key provided",
7682
)
7783

78-
if key == "none":
84+
if key == NONE_KEY:
7985
raise grpc.RpcError(
8086
grpc.StatusCode.PERMISSION_DENIED,
8187
"Permission denied",
8288
)
8389

84-
if key != "all":
90+
if key != ALL_KEY:
8591
raise grpc.RpcError(
8692
grpc.StatusCode.UNAUTHENTICATED,
8793
"Invalid access key",

src/frequenz/client/dispatch/test/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
from .. import Client
1010
from ..types import Dispatch
11-
from ._service import FakeService
11+
from ._service import ALL_KEY, NONE_KEY, FakeService
12+
13+
__all__ = ["FakeClient", "to_create_params", "ALL_KEY", "NONE_KEY"]
1214

1315

1416
class FakeClient(Client):
@@ -26,7 +28,7 @@ def __init__(
2628
Args:
2729
shuffle_after_create: Whether to shuffle the dispatches after creating them.
2830
"""
29-
super().__init__(grpc_channel=MagicMock(), svc_addr="mock", key="all")
31+
super().__init__(grpc_channel=MagicMock(), svc_addr="mock", key=ALL_KEY)
3032
self._stub = FakeService() # type: ignore
3133
self._service._shuffle_after_create = shuffle_after_create
3234

tests/test_dispatch_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from frequenz.client.common.microgrid.components import ComponentCategory
1616
from frequenz.client.dispatch.__main__ import cli
17-
from frequenz.client.dispatch.test.client import FakeClient
17+
from frequenz.client.dispatch.test.client import ALL_KEY, FakeClient
1818
from frequenz.client.dispatch.types import (
1919
Dispatch,
2020
EndCriteria,
@@ -26,7 +26,7 @@
2626
TEST_NOW = datetime(2023, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
2727
"""Arbitrary time used as NOW for testing."""
2828

29-
ENVIRONMENT_VARIABLES = {"DISPATCH_API_KEY": "all"}
29+
ENVIRONMENT_VARIABLES = {"DISPATCH_API_KEY": ALL_KEY}
3030

3131

3232
@pytest.fixture

0 commit comments

Comments
 (0)