Exemplo n.º 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
Exemplo n.º 2
0
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"]
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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