example-of-crud-in-django-w.../tests/library/test_model.py

29 lines
553 B
Python
Raw Normal View History

2021-07-14 16:19:03 +02:00
# tests/Library/test_model.py
import pytest
from app.library.models import Book
@pytest.mark.django_db
def test_book_model():
## Given
book = Book(
title="The foundation",
2021-07-14 16:46:34 +02:00
country="eeuu",
2021-07-14 16:19:03 +02:00
year="1951",
author="Isaac Asimov",
)
book.save()
## When
## Then
assert book.title == "The foundation"
2021-07-14 16:46:34 +02:00
assert book.country == "eeuu"
2021-07-14 16:19:03 +02:00
assert book.year == "1951"
assert book.author == "Isaac Asimov"
assert book.created_at
assert book.updated_at
assert str(book) == book.title