-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from simonsobs/dev
Add GraphQL mutation `loadExampleScript`
- Loading branch information
Showing
4 changed files
with
62 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
nextlinegraphql/plugins/ctrl/graphql/mutations/LoadExampleScript.gql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mutation LoadExampleScript { | ||
loadExampleScript | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/plugins/ctrl/schema/mutations/test_load_example_script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from pathlib import Path | ||
|
||
from nextline import Nextline | ||
from strawberry import Schema | ||
|
||
from nextlinegraphql.plugins.ctrl import example_script as example_script_module | ||
from nextlinegraphql.plugins.ctrl.graphql import MUTATE_LOAD_EXAMPLE_SCRIPT | ||
from nextlinegraphql.plugins.ctrl.schema import Mutation, Query, Subscription | ||
|
||
EXAMPLE_SCRIPT_PATH = Path(example_script_module.__file__).parent / 'script.py' | ||
example_script = EXAMPLE_SCRIPT_PATH.read_text() | ||
|
||
INITIAL_SCRIPT = ''' | ||
import time | ||
time.sleep(0.001) | ||
'''.strip() | ||
|
||
|
||
async def test_query() -> None: | ||
nextline = Nextline(INITIAL_SCRIPT) | ||
async with nextline: | ||
context = {'nextline': nextline} | ||
schema = Schema(query=Query, mutation=Mutation, subscription=Subscription) | ||
result = await schema.execute(MUTATE_LOAD_EXAMPLE_SCRIPT, context_value=context) | ||
assert not result.errors | ||
assert result.data | ||
assert result.data['loadExampleScript'] is True | ||
assert nextline.statement == example_script |