forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ allows frontend to check if a project is inactive (ITISFoundation#4895
) Co-authored-by: Andrei Neagu <[email protected]>
- Loading branch information
Showing
32 changed files
with
862 additions
and
69 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
Empty file.
9 changes: 9 additions & 0 deletions
9
packages/models-library/src/models_library/api_schemas_dynamic_sidecar/containers.py
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from pydantic import BaseModel, NonNegativeFloat | ||
|
||
|
||
class InactivityResponse(BaseModel): | ||
seconds_inactive: NonNegativeFloat | None = None | ||
|
||
@property | ||
def is_inactive(self) -> bool: | ||
return self.seconds_inactive is not None |
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
16 changes: 16 additions & 0 deletions
16
packages/models-library/tests/test_api_schemas_dynamic_sidecar_containers.py
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from typing import Any | ||
|
||
import pytest | ||
from models_library.api_schemas_dynamic_sidecar.containers import InactivityResponse | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"data, is_inactive", | ||
[ | ||
pytest.param({"seconds_inactive": None}, False), | ||
pytest.param({"seconds_inactive": 0}, True), | ||
pytest.param({"seconds_inactive": 100}, True), | ||
], | ||
) | ||
def test_expected(data: dict[str, Any], is_inactive: bool): | ||
assert InactivityResponse.parse_obj(data).is_inactive == is_inactive |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Any | ||
|
||
import pytest | ||
from models_library.callbacks_mapping import ( | ||
INACTIVITY_TIMEOUT_CAP, | ||
TIMEOUT_MIN, | ||
CallbacksMapping, | ||
) | ||
from pydantic import ValidationError, parse_obj_as | ||
|
||
|
||
def _format_with_timeout(timeout: float) -> dict[str, Any]: | ||
return {"inactivity": {"service": "a-service", "command": "", "timeout": timeout}} | ||
|
||
|
||
def test_inactivity_time_out_is_max_capped(): | ||
for in_bounds in [ | ||
TIMEOUT_MIN, | ||
TIMEOUT_MIN + 1, | ||
INACTIVITY_TIMEOUT_CAP - 1, | ||
INACTIVITY_TIMEOUT_CAP, | ||
]: | ||
parse_obj_as(CallbacksMapping, _format_with_timeout(in_bounds)) | ||
|
||
for out_of_bounds in [INACTIVITY_TIMEOUT_CAP + 1, TIMEOUT_MIN - 1]: | ||
with pytest.raises(ValidationError): | ||
parse_obj_as(CallbacksMapping, _format_with_timeout(out_of_bounds)) |
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
Oops, something went wrong.