Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
nix010 committed Jul 5, 2024
1 parent e49d8f9 commit cc80ddf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/serializers/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def computed_field_x(self) -> int:
return self.x + 200

def ser_func(self, v: Any, info: core_schema.FieldSerializationInfo) -> str:
return str(v * 2)
return info.field_name + '_' + str(v * 2)

field_str_with_field_serializer = core_schema.str_schema(
serialization=core_schema.plain_serializer_function_ser_schema(
Expand All @@ -597,8 +597,8 @@ def ser_func(self, v: Any, info: core_schema.FieldSerializationInfo) -> str:
),
)
)
assert json.loads(s.to_json(Model(x=1000))) == {'x': '2000', 'computed_field_x': '2400'}
assert s.to_python(Model(x=2000)) == {'x': '4000', 'computed_field_x': '4400'}
assert json.loads(s.to_json(Model(x=1000))) == {'x': 'x_2000', 'computed_field_x': 'computed_field_x_2400'}
assert s.to_python(Model(x=2000)) == {'x': 'x_4000', 'computed_field_x': 'computed_field_x_4400'}


def test_function_wrap_field_serializer_to_json():
Expand Down

0 comments on commit cc80ddf

Please sign in to comment.