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
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"]
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
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
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
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
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
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