Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests #125

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/schema/mutations/auto_mode/test_change_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ async def test_schema(mode: str, schema: Schema) -> None:
expected = {'schedule': {'autoMode': {'changeMode': valid}}}
assert DeepDiff(data, expected) == {}
if valid:
auto_mode.change_mode.assert_called_once_with(mode)
auto_mode.change_mode.assert_awaited_once_with(mode)
16 changes: 16 additions & 0 deletions tests/schema/mutations/auto_mode/test_turn_off.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from unittest.mock import Mock

from nextline_schedule.auto import AutoMode
from nextline_schedule.graphql import MUTATE_AUTO_MODE_TURN_OFF
from tests.schema.conftest import Schema


async def test_schema(schema: Schema) -> None:
auto_mode = Mock(spec=AutoMode)
context_auto_mode = {'auto_mode': auto_mode}
context_value = {'schedule': context_auto_mode}
resp = await schema.execute(MUTATE_AUTO_MODE_TURN_OFF, context_value=context_value)
assert (data := resp.data)
expected = {'schedule': {'autoMode': {'turnOff': True}}}
assert data == expected
auto_mode.turn_off.assert_awaited_once()
16 changes: 16 additions & 0 deletions tests/schema/mutations/auto_mode/test_turn_on.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from unittest.mock import Mock

from nextline_schedule.auto import AutoMode
from nextline_schedule.graphql import MUTATE_AUTO_MODE_TURN_ON
from tests.schema.conftest import Schema


async def test_schema(schema: Schema) -> None:
auto_mode = Mock(spec=AutoMode)
context_auto_mode = {'auto_mode': auto_mode}
context_value = {'schedule': context_auto_mode}
resp = await schema.execute(MUTATE_AUTO_MODE_TURN_ON, context_value=context_value)
assert (data := resp.data)
expected = {'schedule': {'autoMode': {'turnOn': True}}}
assert data == expected
auto_mode.turn_on.assert_awaited_once()
2 changes: 1 addition & 1 deletion tests/schema/mutations/queue/move/test_one_backward.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ async def test_schema(d: st.DataObject, schema: Schema) -> None:
expected_data = {'schedule': {'queue': {'move': {'oneBackward': return_value}}}}
assert DeepDiff(data, expected_data) == {}

queue.move_one_backward.assert_called_once_with(id)
queue.move_one_backward.assert_awaited_once_with(id)
2 changes: 1 addition & 1 deletion tests/schema/mutations/queue/move/test_one_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ async def test_schema(d: st.DataObject, schema: Schema) -> None:
expected_data = {'schedule': {'queue': {'move': {'oneForward': return_value}}}}
assert DeepDiff(data, expected_data) == {}

queue.move_one_forward.assert_called_once_with(id)
queue.move_one_forward.assert_awaited_once_with(id)
2 changes: 1 addition & 1 deletion tests/schema/mutations/queue/move/test_to_first.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ async def test_schema(d: st.DataObject, schema: Schema) -> None:
expected_data = {'schedule': {'queue': {'move': {'toFirst': return_value}}}}
assert DeepDiff(data, expected_data) == {}

queue.move_to_first.assert_called_once_with(id)
queue.move_to_first.assert_awaited_once_with(id)
2 changes: 1 addition & 1 deletion tests/schema/mutations/queue/move/test_to_last.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ async def test_schema(d: st.DataObject, schema: Schema) -> None:
expected_data = {'schedule': {'queue': {'move': {'toLast': return_value}}}}
assert DeepDiff(data, expected_data) == {}

queue.move_to_last.assert_called_once_with(id)
queue.move_to_last.assert_awaited_once_with(id)
2 changes: 1 addition & 1 deletion tests/schema/mutations/queue/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ async def test_schema(d: st.DataObject, schema: Schema) -> None:
}
assert DeepDiff(data, expected_data) == {}

queue.push.assert_called_once_with(PushArg(**input))
queue.push.assert_awaited_once_with(PushArg(**input))
2 changes: 1 addition & 1 deletion tests/schema/mutations/queue/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ async def test_schema(d: st.DataObject, schema: Schema) -> None:
expected_data = {'schedule': {'queue': {'remove': return_value}}}
assert DeepDiff(data, expected_data) == {}

queue.remove.assert_called_once_with(id)
queue.remove.assert_awaited_once_with(id)
5 changes: 3 additions & 2 deletions tests/schema/queries/auto_mode/test_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ async def test_schema(schema: Schema) -> None:
context_auto_mode = {'auto_mode': auto_mode}
context = {'schedule': context_auto_mode}
resp = await schema.execute(QUERY_AUTO_MODE_MODE, context_value=context)
assert resp.data
assert resp.data['schedule']['autoMode']['mode'] == mode
assert (data := resp.data)
expected = {'schedule': {'autoMode': {'mode': mode}}}
assert data == expected
5 changes: 3 additions & 2 deletions tests/schema/queries/auto_mode/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ async def test_schema(schema: Schema) -> None:
context_auto_mode = {'auto_mode': auto_mode}
context = {'schedule': context_auto_mode}
resp = await schema.execute(QUERY_AUTO_MODE_STATE, context_value=context)
assert resp.data
assert resp.data['schedule']['autoMode']['state'] == state
assert (data := resp.data)
expected = {'schedule': {'autoMode': {'state': state}}}
assert data == expected
Empty file.
37 changes: 37 additions & 0 deletions tests/schema/queries/scheduler/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from string import ascii_letters
from unittest.mock import Mock

from hypothesis import given, provisional
from hypothesis import strategies as st

from nextline_schedule.graphql import QUERY_SCHEDULER
from nextline_schedule.scheduler import Scheduler
from nextline_test_utils.strategies import st_graphql_ints
from tests.schema.conftest import Schema


@given(d=st.data())
async def test_schema(d: st.DataObject, schema: Schema) -> None:
api_url = d.draw(provisional.urls())
length_minutes = d.draw(st_graphql_ints(min_value=1))
policy = d.draw(st.text(ascii_letters, min_size=1))

scheduler = Mock(spec=Scheduler)
scheduler._api_url = api_url
scheduler._length_minutes = length_minutes
scheduler._policy = policy

context = {'schedule': {'scheduler': scheduler}}
resp = await schema.execute(QUERY_SCHEDULER, context_value=context)
assert (data := resp.data)

expected = {
'schedule': {
'scheduler': {
'apiUrl': api_url,
'lengthMinutes': length_minutes,
'policy': policy,
}
}
}
assert data == expected