Exemplo n.º 1
0
def init_db(session):
    book1 = model.Book("Some Book", "Some Author", "Some Publisher", 1000)
    book2 = model.Book(
        "A Different Book", "A Different Author", "A Different Publisher", 1000
    )
    session.add(book1)
    session.add(book2)
    session.commit()
Exemplo n.º 2
0
def test_book():
    book = model.Book(title="A Book",
                      author="An Author",
                      publisher="A Publisher",
                      pages=1000)

    assert book.title == "A Book"
    assert book.author == "An Author"
    assert book.publisher == "A Publisher"
    assert book.pages == 1000
Exemplo n.º 3
0
def test_book_to_dict():
    book_dict = model.Book(title="A Book",
                           author="An Author",
                           publisher="A Publisher",
                           pages=1000).to_dict()

    assert book_dict["title"] == "A Book"
    assert book_dict["author"] == "An Author"
    assert book_dict["publisher"] == "A Publisher"
    assert book_dict["pages"] == 1000
Exemplo n.º 4
0
def update():
    validate(request.json, "BookSchema", "specs/book_put.yml")
    data = request.json
    book = model.Book(
        title=data["title"],
        author=data["author"],
        publisher=data["publisher"],
        pages=data["pages"],
    )
    command = commands.UpdateBook(book=book)
    result = context.messagebus.handle(command)
    return dict(success=result), 201
Exemplo n.º 5
0
def add():
    validate(request.json, "BookSchema", "specs/book_add.yml")
    data = request.json
    book = model.Book(
        title=data["title"],
        author=data["author"],
        publisher=data["publisher"],
        pages=data["pages"],
    )
    command = commands.AddBook(book=book)
    context.messagebus.handle(command)
    return dict(success=True), 200
Exemplo n.º 6
0
def test_update_book(sqlite_session_factory):
    session = sqlite_session_factory()
    repo = book_repository.SqlAlchemyBookRepository(session)
    book = model.Book("A Book", "An Author", "A Publisher", 1000)
    repo.update(book)