open-law/tests/test_breadcrumbs.py

24 lines
867 B
Python
Raw Normal View History

2023-05-01 14:01:03 +00:00
from app.controllers import create_breadcrumbs
from app import models as m, db
2023-06-12 13:12:12 +00:00
from tests.utils import create_book, login, create_collection, create_section
2023-05-01 14:01:03 +00:00
2023-06-12 13:12:12 +00:00
def test_breadcrumbs(client, app):
login(client)
book = create_book(client)
collection, _ = create_collection(client, book.id)
section, _ = create_section(client, book.id, collection.id)
2023-05-01 14:01:03 +00:00
with app.app_context(), app.test_request_context():
2023-06-12 13:12:12 +00:00
res = create_breadcrumbs(
book_id=book.id, collection_id=collection.id, section_id=section.id
)
2023-05-01 14:01:03 +00:00
assert len(res) == 4
book: m.Book = db.session.get(m.Book, 1)
assert book
assert book.owner.username in res[0].label
assert res[1].label == book.label
with app.app_context(), app.test_request_context():
2023-05-30 13:45:32 +00:00
res = create_breadcrumbs(book_id=1, section_id=1)
2023-05-01 14:01:03 +00:00
assert res
2023-05-30 13:45:32 +00:00
assert len(res) == 4