Esempio n. 1
0
def step_impl(context, app_name: str):
    from bookshop import app, db
    client = context.client = app.test_client()
    with app.app_context():
        db.drop_all()
        db.create_all()
    assert_that(client.get('/').status_code, equal_to(200))
Esempio n. 2
0
def _get_sqlalchemy_model(context, entity_type, entity):
    from bookshop import app
    context.app_context = app.app_context()
    context.app_context.push()
    if entity_type == 'author':
        model = Author
        filter_ = Author.author_id == entity['id']
    elif entity_type == 'book':
        model = Book
        filter_ = Book.book_id == entity['id']
    else:
        raise Exception('Only supports books and authors')

    setattr(context, f'sql_{entity_type}',
            getattr(model, 'query').filter(filter_).one())
Esempio n. 3
0
    genre_id=GENRE_UUID,
    title='genre title',
)
book_genre_model = BookGenre(
    id=1, book_genre_id=uuid.uuid4(),
    book_id=1, genre_id=1,
)

review_model = Review(id=1, review_id=REVIEW_UUID, text='scathing review - pigs cant talk', book_id=1)

review_dict = {
    'id': REVIEW_UUID,
    'text': 'scathing review - pigs cant talk'
}

with app.app_context():
    db.drop_all()
    db.create_all()
    db.session.add(author_model)
    db.session.add(book_model)
    db.session.add(review_model)
    db.session.commit()

with description('model_to_dict') as self:
    with it('converts a flat model into a dict'):
        with app.app_context():
            retrieved_book = Book.query.filter_by(book_id=BOOK_UUID).first()
        result = model_to_dict(
            sqlalchemy_model=retrieved_book,
        )
        expect(result).to(have_keys(**book_dict))