Пример #1
0
async def test_create(session: Session):  # noqa

    yin: FizzSchema = FizzSchema(fizz_id=1, name="Yin", purpose="thing 1")
    await FizzService.create(yin, session)
    results: List[Fizz] = session.query(Fizz).all()

    assert len(results) == 1

    for k in yin.dict().keys():
        assert getattr(results[0], k) == getattr(yin, k)
Пример #2
0
async def test_create(session: Session):  # noqa

    yin: WidgetSchema = WidgetSchema(widget_id=1, name="Yin", purpose="thing 1")
    await WidgetService.create(yin, session)
    results: List[Widget] = session.query(Widget).all()

    assert len(results) == 1

    for k in yin.dict().keys():
        assert getattr(results[0], k) == getattr(yin, k)
Пример #3
0
async def test_update(session: Session):  # noqa
    yin: FizzSchema = FizzSchema(fizz_id=1, name="Yin", purpose="thing 1")
    yin_orm = Fizz(**yin.dict())
    session.add(yin_orm)
    updates: FizzSchema = FizzSchema(fizz_id=1,
                                     name="New Fizz name",
                                     purpose="thing 1")

    await FizzService.update(yin_orm, updates, session)
    result: FizzSchema = session.query(Fizz).get(yin.fizz_id)
    assert result.name == "New Fizz name"
Пример #4
0
async def test_update(session: Session):  # noqa
    yin: WidgetSchema = WidgetSchema(widget_id=1, name="Yin", purpose="thing 1")
    yin_orm = Widget(**yin.dict())
    session.add(yin_orm)
    updates: WidgetSchema = WidgetSchema(
        widget_id=1, name="New Widget name", purpose="thing 1"
    )

    await WidgetService.update(yin_orm, updates, session)
    result: WidgetSchema = session.query(Widget).get(yin.widget_id)
    assert result.name == "New Widget name"
Пример #5
0
async def test_delete_by_id(session: Session):  # noqa
    yin: FizzSchema = FizzSchema(fizz_id=1, name="Yin", purpose="thing 1")
    yang: FizzSchema = FizzSchema(fizz_id=2, name="Yang", purpose="thing 2")

    yin_orm = Fizz(**yin.dict())
    yang_orm = Fizz(**yang.dict())

    session.add(yin_orm)
    session.add(yang_orm)
    session.commit()

    await FizzService.delete_by_id(1, session)
    session.commit()

    results: List[Fizz] = session.query(Fizz).all()

    assert len(results) == 1
    assert yin_orm not in results and yang_orm in results
Пример #6
0
async def test_delete_by_id(session: Session):  # noqa
    yin: WidgetSchema = WidgetSchema(widget_id=1, name="Yin", purpose="thing 1")
    yang: WidgetSchema = WidgetSchema(widget_id=2, name="Yang", purpose="thing 2")

    yin_orm = Widget(**yin.dict())
    yang_orm = Widget(**yang.dict())

    session.add(yin_orm)
    session.add(yang_orm)
    session.commit()

    await WidgetService.delete_by_id(1, session)
    session.commit()

    results: List[Widget] = session.query(Widget).all()

    assert len(results) == 1
    assert yin_orm not in results and yang_orm in results
Пример #7
0
def test_Fizz_retrieve(fizz: Fizz, session: Session):  # noqa
    session.add(fizz)
    session.commit()
    s = session.query(Fizz).first()
    assert s.__dict__ == fizz.__dict__
Пример #8
0
def test_Widget_retrieve(widget: Widget, session: Session):  # noqa
    session.add(widget)
    session.commit()
    s = session.query(Widget).first()
    assert s.__dict__ == widget.__dict__