2016-09-18 02:29:00 +03:00
|
|
|
from django.core import management
|
2019-03-31 13:30:29 +03:00
|
|
|
from mock import patch, mock_open
|
2016-09-18 02:29:00 +03:00
|
|
|
from six import StringIO
|
|
|
|
|
|
|
|
|
2018-07-20 02:51:33 +03:00
|
|
|
@patch("graphene_django.management.commands.graphql_schema.Command.save_file")
|
2016-09-18 02:29:00 +03:00
|
|
|
def test_generate_file_on_call_graphql_schema(savefile_mock, settings):
|
|
|
|
out = StringIO()
|
2018-07-20 02:51:33 +03:00
|
|
|
management.call_command("graphql_schema", schema="", stdout=out)
|
2016-09-18 02:29:00 +03:00
|
|
|
assert "Successfully dumped GraphQL schema to schema.json" in out.getvalue()
|
2019-03-31 13:30:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
@patch('json.dump')
|
|
|
|
def test_files_are_canonical(dump_mock):
|
|
|
|
open_mock = mock_open()
|
|
|
|
with patch('graphene_django.management.commands.graphql_schema.open', open_mock):
|
|
|
|
management.call_command('graphql_schema', schema='')
|
|
|
|
|
|
|
|
open_mock.assert_called_once()
|
|
|
|
|
|
|
|
dump_mock.assert_called_once()
|
|
|
|
assert dump_mock.call_args[1]["sort_keys"], "json.mock() should be used to sort the output"
|
|
|
|
assert dump_mock.call_args[1]["indent"] > 0, "output should be pretty-printed by default"
|