コード例 #1
0
def test_list_posts_should_be_successful(
    with_factories: None, pg_session: Session
) -> None:
    PostFactory.create_batch(5)

    query = "{posts {id title}}"
    context = {"session": pg_session}
    result = schema.execute(query, context=context)

    assert not result.errors
    assert len(result.data["posts"]) == 5
コード例 #2
0
ファイル: test_post.py プロジェクト: drac94/pygql-boilerplate
def test_create_post_should_be_successful(with_factories: None,
                                          pg_session: Session) -> None:
    PostFactory.create_batch(5)

    query = get_create_mutation("title", "content")
    context = {"session": pg_session}
    result = schema.execute(query, context=context)

    assert not result.errors
    assert result.data
    assert result.data["createPost"]["post"]
コード例 #3
0
ファイル: test_post.py プロジェクト: drac94/pygql-boilerplate
def test_get_post_by_id(pg_session: Session, with_factories: None) -> None:
    post = PostFactory()
    result = PostService(pg_session).get(post.id)

    assert result
    assert post.id == result.id
    assert post.title == result.title
    assert post.content == result.content
コード例 #4
0
ファイル: test_post.py プロジェクト: drac94/pygql-boilerplate
def test_delete_post_by_id(pg_session: Session, with_factories: None) -> None:

    post = PostFactory()
    posts = PostService(pg_session).get_list()

    assert len(posts) == 1

    PostService(pg_session).delete(post.id)

    posts = PostService(pg_session).get_list()

    assert len(posts) == 0
コード例 #5
0
ファイル: test_post.py プロジェクト: drac94/pygql-boilerplate
def test_update_post(pg_session: Session, with_factories: None) -> None:

    updated_title = "title updated"
    updated_contnet = "content updated"

    post = PostFactory()
    updated_post = PostService(pg_session).update(post.id, updated_title,
                                                  updated_contnet)

    assert updated_post
    assert updated_post.id == post.id
    assert updated_post.title == updated_title
    assert updated_post.content == updated_contnet
コード例 #6
0
ファイル: test_post.py プロジェクト: drac94/pygql-boilerplate
def test_delete_post_should_be_successful(with_factories: None,
                                          pg_session: Session) -> None:
    post = PostFactory()

    post_id = str(post.id)

    query = get_delete_mutation(post_id)
    context = {"session": pg_session}
    result = schema.execute(query, context=context)

    assert not result.errors
    assert result.data
    assert result.data["deletePost"]["post"]
    assert result.data["deletePost"]["post"]["id"] == post_id
コード例 #7
0
ファイル: test_post.py プロジェクト: drac94/pygql-boilerplate
def test_update_post_should_be_successful(with_factories: None,
                                          pg_session: Session) -> None:
    post = PostFactory()

    updated_title = "title updated"
    updated_contnet = "content updated"

    query = get_update_mutation(post.id, updated_title, updated_contnet)
    context = {"session": pg_session}
    result = schema.execute(query, context=context)

    assert not result.errors
    assert result.data
    assert result.data["updatePost"]["post"]
    assert result.data["updatePost"]["post"]["title"] == updated_title
    assert result.data["updatePost"]["post"]["content"] == updated_contnet
コード例 #8
0
ファイル: test_post.py プロジェクト: drac94/pygql-boilerplate
def test_get_post_list(pg_session: Session, with_factories: None) -> None:

    PostFactory.create_batch(BATCH_CREATE)
    posts = PostService(pg_session).get_list()

    assert len(posts) == BATCH_CREATE