This commit is contained in:
Andros Fenollosa
2021-07-13 18:30:31 +02:00
parent 7fd71eca7f
commit 204556f495
13 changed files with 59 additions and 60 deletions

View File

@ -4,6 +4,7 @@ import pytest
from app.libros.models import Libros
@pytest.mark.django_db
def test_libros_model():
@ -26,4 +27,4 @@ def test_libros_model():
assert libro.author == "Isaac Asimov"
assert libro.created_at
assert libro.updated_at
assert str(libro) == libro.title
assert str(libro) == libro.title

View File

@ -2,6 +2,7 @@
from app.libros.serializers import LibroSerializer
def test_valid_libro_serializer():
valid_serializer_data = {
"title": "Raising Arizona",

View File

@ -20,7 +20,7 @@ def test_add_book(client):
"author": "Isaac Asimov",
"year": "1955",
},
content_type="application/json"
content_type="application/json",
)
# Then
@ -40,7 +40,7 @@ def test_get_single_book(client):
genre="Ciencia Ficción",
author="Isaac Asimov",
year="1955",
)
)
# When
resp = client.get(f"/api/libros/{libro.id}/")
@ -154,7 +154,7 @@ def test_update_book(client):
"author": "Frank Herbert",
"year": "1965",
},
content_type="application/json"
content_type="application/json",
)
# Then
@ -195,8 +195,8 @@ def test_update_book_invalid_json(client):
"foo": "Dune",
"boo": "Ciencia Ficción",
},
content_type="application/json"
content_type="application/json",
)
# Then
assert resp.status_code == 400
assert resp.status_code == 400

View File

@ -1,3 +1,3 @@
# Las funciones deben empezar por "test_"
def test_titulo():
assert "canción de hielo y fuego" != "juego de tronos"
assert "canción de hielo y fuego" != "juego de tronos"

View File

@ -1,9 +1,10 @@
import json
from django.urls import reverse
def test_ping(client):
url = reverse("ping")
response = client.get(url)
content = json.loads(response.content)
assert response.status_code == 200
assert content["ping"] == "pong!"
assert content["ping"] == "pong!"