Add fake data

This commit is contained in:
Andros Fenollosa
2021-07-14 16:46:34 +02:00
parent d04d21ae5b
commit aeb5199bdc
10 changed files with 658 additions and 24 deletions

View File

@ -10,7 +10,7 @@ def test_book_model():
## Given
book = Book(
title="The foundation",
genre="Science fiction",
country="eeuu",
year="1951",
author="Isaac Asimov",
)
@ -20,7 +20,7 @@ def test_book_model():
## Then
assert book.title == "The foundation"
assert book.genre == "Science fiction"
assert book.country == "eeuu"
assert book.year == "1951"
assert book.author == "Isaac Asimov"
assert book.created_at

View File

@ -6,7 +6,7 @@ from app.library.serializers import BookSerializer
def test_valid_libro_serializer():
valid_serializer_data = {
"title": "Raising Arizona",
"genre": "comedy",
"country": "eeuu",
"year": "1987",
"author": "Ray Bradbury",
}
@ -28,5 +28,5 @@ def test_invalid_libro_serializer():
assert serializer.data == invalid_serializer_data
assert serializer.errors == {
"year": ["This field is required."],
"genre": ["This field is required."],
"country": ["This field is required."],
}

View File

@ -17,7 +17,7 @@ def test_add_book(client):
reverse("book_list"),
{
"title": "The End of Eternity",
"genre": "Sciencie Fiction",
"country": "eeuu",
"author": "Isaac Asimov",
"year": "1955",
},
@ -38,7 +38,7 @@ def test_get_single_book(client):
# Given
book = Book.objects.create(
title="The End of Eternity",
genre="Sciencie Fiction",
country="eeuu",
author="Isaac Asimov",
year="1955",
)
@ -68,7 +68,7 @@ def test_get_all_books(client, faker):
def create_random_book():
return Book.objects.create(
title=faker.name(),
genre=faker.job(),
country=faker.country(),
author=faker.name_nonbinary(),
year=faker.year(),
)
@ -91,7 +91,7 @@ def test_remove_book(client):
# Given
book = Book.objects.create(
title="The End of Eternity",
genre="Sciencie Fiction",
country="eeuu",
author="Isaac Asimov",
year="1955",
)
@ -123,7 +123,7 @@ def test_remove_book_incorrect_id(client):
# Given
book = Book.objects.create(
title="The End of Eternity",
genre="Sciencie Fiction",
country="eeuu",
author="Isaac Asimov",
year="1955",
)
@ -141,7 +141,7 @@ def test_update_book(client):
# Given
book = Book.objects.create(
title="The End of Eternity",
genre="Sciencie Fiction",
country="eeuu",
author="Isaac Asimov",
year="1955",
)
@ -151,7 +151,7 @@ def test_update_book(client):
reverse("book_details", kwargs={"pk": book.id}),
{
"title": "Dune",
"genre": "Sciencie Fiction",
"country": "eeuu",
"author": "Frank Herbert",
"year": "1965",
},
@ -161,14 +161,14 @@ def test_update_book(client):
# Then
assert resp.status_code == 200
assert resp.data["title"] == "Dune"
assert resp.data["genre"] == "Sciencie Fiction"
assert resp.data["country"] == "eeuu"
assert resp.data["author"] == "Frank Herbert"
assert resp.data["year"] == "1965"
resp_detail = client.get(reverse("book_details", kwargs={"pk": book.id}))
assert resp_detail.status_code == 200
assert resp_detail.data["title"] == "Dune"
assert resp_detail.data["genre"] == "Sciencie Fiction"
assert resp_detail.data["country"] == "eeuu"
assert resp_detail.data["author"] == "Frank Herbert"
assert resp_detail.data["year"] == "1965"
@ -184,7 +184,7 @@ def test_update_book_invalid_json(client):
# Given
book = Book.objects.create(
title="The End of Eternity",
genre="Sciencie Fiction",
country="eeuu",
author="Isaac Asimov",
year="1955",
)