コード例 #1
0
def test_update(db):
    schema = build_graphql_schema()
    result = execute_query(schema, create_actors_query)
    result = execute_query(schema,
                           update_actors_query,
                           variables={
                               'id1': result.data['firstActor']['id'],
                               'id2': result.data['secondActor']['id']
                           })
    assert result.errors is None
    assert result.data['firstActor']['age'] == 60
    assert result.data['secondActor']['age'] == 80
コード例 #2
0
def test_update_or_create(db):
    schema = build_graphql_schema()
    result = execute_query(schema,
                           update_or_create_actor_query,
                           variables={'firstName': 'a'})
    assert result.errors is None
    assert result.data['updateOrCreateActor']['id'] is not None
    assert result.data['updateOrCreateActor']['firstName'] == 'a'
    result = execute_query(schema,
                           update_or_create_actor_query,
                           variables={
                               'id': result.data['updateOrCreateActor']['id'],
                               'firstName': 'b'
                           })
    assert result.errors is None
    assert result.data['updateOrCreateActor']['firstName'] == 'b'
コード例 #3
0
def test_get_query(db, factory):
    schema = build_graphql_schema()
    movie_id = factory.Movie.create().id
    result = execute_query(schema, get_movie_query, variables={'id': movie_id})
    assert result.errors is None
    movie = result.data['getMovie']
    assert movie.get('id') is not None
コード例 #4
0
def test_set_role(db):
    # TOOD: Really need to check the kind of error returned.
    schema = build_graphql_schema()
    result = execute_query(
        schema,
        all_addresses_query,
        context={'session': Session(DefaultRole.Meta.dbrole)})
    assert len(result.errors) > 0
    result = execute_query(schema,
                           all_addresses_query,
                           context={'session': Session(UserRole.Meta.dbrole)})
    assert result.errors is None
    result = execute_query(
        schema,
        get_address_query,
        context={'session': Session(DefaultRole.Meta.dbrole)})
    assert len(result.errors) > 0
コード例 #5
0
def test_custom_resolver(db):
    schema = build_graphql_schema()
    result = execute_query(schema,
                           update_or_create_store_query,
                           variables={'name': 'a'})
    assert result.errors is None
    assert result.data['updateOrCreateStore']['id'] is not None
    assert result.data['updateOrCreateStore']['name'] == 'override'
コード例 #6
0
def test_reverse_query(db, factory):
    schema = build_graphql_schema()
    movies = factory.Movie.create_batch(5)
    factory.Movie.create(star=movies[0].star)
    result = execute_query(schema, all_actors_query)
    assert result.errors is None
    assert len(result.data['allActors']) == 5
    for actor in result.data['allActors']:
        assert actor.get('moviesByStar') is not None
コード例 #7
0
def test_query(db, factory):
    schema = build_graphql_schema()
    factory.Movie.create_batch(5)
    result = execute_query(schema, all_movies_query)
    assert result.errors is None
    assert len(result.data['allMovies']) == 5
    for movie in result.data['allMovies']:
        assert movie.get('star') is not None
        assert movie['star'].get('address') is not None
コード例 #8
0
def test_create_reverse(db):
    schema = build_graphql_schema()
    result = execute_query(schema, create_actor_and_movies_query)
    assert result.errors is None
    data = result.data['createActor']
    assert data['id'] is not None
    assert data['moviesByStar'] is not None
    assert len(data['moviesByStar']) == 2
    for movie in data['moviesByStar']:
        assert movie['id'] is not None
コード例 #9
0
def test_mutation(db, factory):
    schema = build_graphql_schema()
    factory.User.create(email='test', password='******')
    result = execute_query(schema,
                           authenticate_query, {
                               'email': 'test',
                               'password': '******'
                           },
                           reraise=True)
    assert result.errors is None
    assert len(result.data['authenticate']['token']) > 0
コード例 #10
0
def test_delete(db, factory):
    schema = build_graphql_schema()
    movie = factory.Movie.create()
    result = execute_query(schema,
                           delete_movie_query,
                           variables={'id': movie.id})
    assert result.errors is None
    data = result.data['deleteMovie']
    assert data['id'] == movie.id
    result = Q(movie).filter(id=movie.id).get()
    assert result is None
コード例 #11
0
def test_create(db):
    schema = build_graphql_schema()
    result = execute_query(schema, create_actors_query)
    assert result.errors is None
    assert result.data['firstActor'] is not None
    assert result.data['secondActor'] is not None