Exemple #1
0
def test_backend_is_cached_by_default():
    """Sample pytest test function with the pytest fixture as an argument."""
    # from bs4 import BeautifulSoup
    # assert 'GitHub' in BeautifulSoup(response.content).title.string
    graphql_env = GraphQLEnv(schema=schema, backend=GraphQLCoreBackend())
    document1 = graphql_env.document_from_string('{ hello }')
    document2 = graphql_env.document_from_string('{ hello }')
    assert document1 == document2
Exemple #2
0
def test_backend_can_execute_custom_executor():
    executor = BaseExecutor()
    graphql_env = GraphQLEnv(
        schema=schema, backend=GraphQLCoreBackend(executor=executor))
    document1 = graphql_env.document_from_string('{ hello }')
    result = document1.execute()
    assert not result.errors
    assert result.data == {'hello': 'World'}
    assert executor.executed
Exemple #3
0
def test_backend_will_compute_if_cache_non_existing():
    """Sample pytest test function with the pytest fixture as an argument."""
    # from bs4 import BeautifulSoup
    # assert 'GitHub' in BeautifulSoup(response.content).title.string
    graphql_env = GraphQLEnv(
        schema=schema, backend=GraphQLCoreBackend(use_cache=False))
    document1 = graphql_env.document_from_string('{ hello }')
    document2 = graphql_env.document_from_string('{ hello }')
    assert document1 != document2
Exemple #4
0
def test_core_backend():
    """Sample pytest test function with the pytest fixture as an argument."""
    # from bs4 import BeautifulSoup
    # assert 'GitHub' in BeautifulSoup(response.content).title.string
    graphql_env = GraphQLEnv(schema=schema, backend=GraphQLCoreBackend())
    document = graphql_env.document_from_string('{ hello }')
    assert isinstance(document, GraphQLDocument)
    result = document.execute()
    assert not result == {'data': {'hello': 'World'}}
Exemple #5
0
def test_decider_backend_unhealthy_backend():
    backend1 = FakeBackend(raises=True)
    backend2 = FakeBackend()
    graphql_env = GraphQLEnv(
        schema=schema, backend=GraphQLDeciderBackend([
            backend1,
            backend2,
        ]))

    graphql_env.document_from_string('{ hello }')
    assert backend1.reached
    assert backend2.reached
Exemple #6
0
def test_decider_backend_dont_use_cache():
    backend1 = FakeBackend()
    backend2 = FakeBackend()
    graphql_env = GraphQLEnv(
        schema=schema, backend=GraphQLDeciderBackend([
            backend1,
            backend2,
        ]))

    graphql_env.document_from_string('{ hello }')
    assert backend1.reached
    assert not backend2.reached

    backend1.reset()
    graphql_env.document_from_string('{ hello }')
    assert backend1.reached
Exemple #7
0
def test_backend_can_execute():
    graphql_env = GraphQLEnv(schema=schema, backend=GraphQLCoreBackend())
    document1 = graphql_env.document_from_string('{ hello }')
    result = document1.execute()
    assert not result.errors
    assert result.data == {'hello': 'World'}