2021-07-14 16:19:03 +02:00
|
|
|
# tests/Library/test_serializers.py
|
2021-07-09 19:09:31 +02:00
|
|
|
|
2021-07-14 16:19:03 +02:00
|
|
|
from app.library.serializers import BookSerializer
|
2021-07-09 19:09:31 +02:00
|
|
|
|
2021-07-13 18:30:31 +02:00
|
|
|
|
2021-07-09 19:09:31 +02:00
|
|
|
def test_valid_libro_serializer():
|
|
|
|
valid_serializer_data = {
|
|
|
|
"title": "Raising Arizona",
|
|
|
|
"genre": "comedy",
|
|
|
|
"year": "1987",
|
|
|
|
"author": "Ray Bradbury",
|
|
|
|
}
|
2021-07-14 16:19:03 +02:00
|
|
|
serializer = BookSerializer(data=valid_serializer_data)
|
2021-07-09 19:09:31 +02:00
|
|
|
assert serializer.is_valid()
|
|
|
|
assert serializer.validated_data == valid_serializer_data
|
|
|
|
assert serializer.data == valid_serializer_data
|
|
|
|
assert serializer.errors == {}
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_libro_serializer():
|
|
|
|
invalid_serializer_data = {
|
2021-07-14 16:19:03 +02:00
|
|
|
"title": "I am legend",
|
2021-07-09 19:09:31 +02:00
|
|
|
"author": "Richard Matheson",
|
|
|
|
}
|
2021-07-14 16:19:03 +02:00
|
|
|
serializer = BookSerializer(data=invalid_serializer_data)
|
2021-07-09 19:09:31 +02:00
|
|
|
assert not serializer.is_valid()
|
|
|
|
assert serializer.validated_data == {}
|
|
|
|
assert serializer.data == invalid_serializer_data
|
|
|
|
assert serializer.errors == {
|
|
|
|
"year": ["This field is required."],
|
|
|
|
"genre": ["This field is required."],
|
2021-07-12 23:47:31 +02:00
|
|
|
}
|