Codebase list python-graphene-sqlalchemy / upstream/2.0.0 graphene_sqlalchemy / tests / test_utils.py
upstream/2.0.0

Tree @upstream/2.0.0 (Download .tar.gz)

test_utils.py @upstream/2.0.0raw · history · blame

from graphene import ObjectType, Schema, String

from ..utils import get_session


def test_get_session():
    session = 'My SQLAlchemy session'

    class Query(ObjectType):
        x = String()

        def resolve_x(self, info):
            return get_session(info.context)

    query = '''
        query ReporterQuery {
            x
        }
    '''

    schema = Schema(query=Query)
    result = schema.execute(query, context_value={'session': session})
    assert not result.errors
    assert result.data['x'] == session