Example #1
0
def test_delete_post_with_wrong_id_should_not_be_successful(
        with_factories: None, pg_session: Session) -> None:

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

    assert result.errors
Example #2
0
async def resolve(request):
    body = await request.json()
    try:
        result = schema.execute(str(body['query']))
        return web.json_response(
            {'data': dict(result.data.items()) if result.data else None},
            status=200)
    except Exception as e:
        return web.json_response({'error': e}, status=500)
Example #3
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
Example #4
0
def test_update_post_with_wrong_id_should_not_be_successful(
        with_factories: None, pg_session: Session) -> None:

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

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

    assert result.errors
Example #5
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"]
Example #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
Example #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