Skip to content

Commit

Permalink
fix(app): serialize cpu and gpu request to number (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
olevski authored Jun 13, 2022
1 parent ad10f71 commit 77aadd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions renku_notebooks/api/schemas/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _serialize(self, value, attr, obj, **kwargs):
raise ValidationError(
"Invalid value during serialization, must be greater than zero."
)
return str(value)
return value

def _deserialize(self, value, attr, data, **kwargs):
"""Always deserialize to fractional cores"""
Expand Down Expand Up @@ -135,7 +135,7 @@ def _serialize(self, value, attr, obj, **kwargs):
"Invalid value during GPU amount serialization, "
f"must be greater than or equal to zero, got {value}."
)
return str(value)
return value

def _deserialize(self, value, attr, data, **kwargs):
"""Always deserialize to whole GPUs as integer."""
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def test_cpu_field_invalid_deserialize(test_input):
@pytest.mark.parametrize(
"test_input,expected_value",
[
({"cpu": 0.1}, "0.1"),
({"cpu": 1}, "1"),
({"cpu": 500}, "500"),
({"cpu": 1000}, "1000"),
({"cpu": 0.1}, 0.1),
({"cpu": 1}, 1),
({"cpu": 500}, 500),
({"cpu": 1000}, 1000),
],
)
def test_cpu_field_valid_serialize(test_input, expected_value):
Expand Down Expand Up @@ -112,8 +112,8 @@ def test_gpu_field_invalid_deserialize(test_input):
@pytest.mark.parametrize(
"test_input,expected_value",
[
({"gpu": 1}, "1"),
({"gpu": 2}, "2"),
({"gpu": 1}, 1),
({"gpu": 2}, 2),
],
)
def test_gpu_field_valid_serialize(test_input, expected_value):
Expand Down

0 comments on commit 77aadd5

Please sign in to comment.