import json from storyhub.sdk.service.Argument import Argument from storyhub.sdk.service.output import OutputString from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper argument_fixture = JsonFixtureHelper.load_fixture("argument_fixture") argument_fixture_json = json.dumps(argument_fixture) def test_deserialization(mocker): mocker.patch.object(json, "loads", return_value=argument_fixture) assert Argument.from_json(jsonstr=argument_fixture_json) is not None json.loads.assert_called_with(argument_fixture_json) def test_serialization(mocker): mocker.patch.object(json, "dumps", return_value=argument_fixture_json) service_command = Argument.from_dict(data=argument_fixture) assert service_command.as_json(compact=True) is not None json.dumps.assert_called_with(argument_fixture, sort_keys=True) assert service_command.as_json() is not None json.dumps.assert_called_with(argument_fixture, indent=4, sort_keys=True)
import json from storyhub.sdk.service.EnvironmentVariable import EnvironmentVariable from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper env_fixture = JsonFixtureHelper.load_fixture("env_fixture") env_fixture_json = json.dumps(env_fixture) def test_deserialization(mocker): mocker.patch.object(json, 'loads', return_value=env_fixture) assert EnvironmentVariable.from_json(jsonstr=env_fixture_json) is not None json.loads.assert_called_with(env_fixture_json) def test_serialization(mocker): mocker.patch.object(json, 'dumps', return_value=env_fixture_json) service_command = EnvironmentVariable.from_dict(data=env_fixture) assert service_command.as_json(compact=True) is not None json.dumps.assert_called_with(env_fixture, sort_keys=True) assert service_command.as_json() is not None json.dumps.assert_called_with(env_fixture, indent=4, sort_keys=True)
import json from storyhub.sdk.service.Action import Action from storyhub.sdk.service.Command import Command from storyhub.sdk.service.Configuration import Configuration from storyhub.sdk.service.Entrypoint import Entrypoint from storyhub.sdk.service.EnvironmentVariable import EnvironmentVariable from storyhub.sdk.service.Lifecycle import Lifecycle from storyhub.sdk.service.ServiceInfo import ServiceInfo from storyhub.sdk.service.Volume import Volume from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper configuration_fixture = JsonFixtureHelper.load_fixture("configuration_fixture") configuration_fixture_json = json.dumps(configuration_fixture) def test_deserialization(mocker): mocker.patch.object(json, 'loads', return_value=configuration_fixture) mocker.patch.object(Entrypoint, 'from_dict') mocker.patch.object(Action, 'from_dict') mocker.patch.object(Command, 'from_dict') mocker.patch.object(Volume, 'from_dict') mocker.patch.object(EnvironmentVariable, 'from_dict') mocker.patch.object(Lifecycle, 'from_dict') mocker.patch.object(ServiceInfo, 'from_dict') configuration = Configuration.from_json(configuration_fixture_json) assert configuration is not None
import json from storyhub.sdk.service.LifecycleOption import LifecycleOption from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper lifecycle_option_fixture = JsonFixtureHelper.load_fixture( "lifecycle_option_fixture") lifecycle_option_fixture_json = json.dumps(lifecycle_option_fixture) def test_deserialization(mocker): mocker.patch.object(json, "loads", return_value=lifecycle_option_fixture) assert (LifecycleOption.from_json(jsonstr=lifecycle_option_fixture_json) is not None) json.loads.assert_called_with(lifecycle_option_fixture_json) def test_serialization(mocker): mocker.patch.object(json, "dumps", return_value=lifecycle_option_fixture_json) service_command = LifecycleOption.from_dict(data=lifecycle_option_fixture) assert service_command.as_json(compact=True) is not None json.dumps.assert_called_with(lifecycle_option_fixture, sort_keys=True)
import json from storyhub.sdk.service.Action import Action from storyhub.sdk.service.Argument import Argument from storyhub.sdk.service.Event import Event from storyhub.sdk.service.HttpOptions import HttpOptions from storyhub.sdk.service.Output import Output from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper event_fixture = JsonFixtureHelper.load_fixture("event_fixture") event_fixture_json = json.dumps(event_fixture) def test_deserialization(mocker): mocker.patch.object(json, 'loads', return_value=event_fixture) mocker.patch.object(Argument, 'from_dict') mocker.patch.object(Action, 'from_dict') mocker.patch.object(Output, 'from_dict') mocker.patch.object(HttpOptions, 'from_dict') assert Event.from_json(jsonstr=event_fixture_json) is not None json.loads.assert_called_with(event_fixture_json) Argument.from_dict.assert_any_call( data={ "name": "path", "argument": event_fixture["event"]["arguments"]["path"] })
import json from storyhub.sdk.service.License import License from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper license_fixture = JsonFixtureHelper.load_fixture("license_fixture") license_fixture_json = json.dumps(license_fixture) def test_deserialization(mocker): mocker.patch.object(json, 'loads', return_value=license_fixture) assert License.from_json(jsonstr=license_fixture_json) is not None json.loads.assert_called_with(license_fixture_json) def test_serialization(mocker): mocker.patch.object(json, 'dumps', return_value=license_fixture_json) service_command = License.from_dict(data=license_fixture) assert service_command.as_json(compact=True) is not None json.dumps.assert_called_with(license_fixture, sort_keys=True) assert service_command.as_json() is not None json.dumps.assert_called_with(license_fixture, indent=4, sort_keys=True)
import json from storyhub.sdk.service.Argument import Argument from storyhub.sdk.service.Entrypoint import Entrypoint from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper entry_point_fixture = JsonFixtureHelper.load_fixture("entrypoint_fixture") entry_point_fixture_json = json.dumps(entry_point_fixture) def test_deserialization(mocker): mocker.patch.object(json, "loads", return_value=entry_point_fixture) mocker.patch.object(Argument, "from_dict") assert Entrypoint.from_json(jsonstr=entry_point_fixture_json) is not None json.loads.assert_called_with(entry_point_fixture_json) Argument.from_dict.assert_called_with( data={ "name": "path", "argument": entry_point_fixture["entrypoint"]["arguments"]["path"], }) def test_serialization(mocker): mocker.patch.object(json, "dumps", return_value=entry_point_fixture_json)
actual_service = hub.get(alias="second_service") assert actual_service is not None def test_get_with_name(mocker): hub = StoryscriptHub(db_path=tempfile.mkdtemp()) mocker.patch.object(Service, "select") assert hub.get("microservice/redis") is not None Service.select().where.assert_called_with( (Service.username == "microservice") & (Service.name == "redis")) not_python_fixture = JsonFixtureHelper.load_fixture("not_python_fixture") def test_service_wrapper(mocker): hub = StoryscriptHub(db_path=tempfile.mkdtemp()) mocker.patch.object(GraphQL, "get_all", return_value=[not_python_fixture]) mocker.patch.object(ServiceData, "from_dict") assert hub.get("microservice/not_python") is not None ServiceData.from_dict.assert_called_with( data={"service_data": not_python_fixture})
import tempfile import os import json from storyhub.sdk.ServiceWrapper import ServiceWrapper from storyhub.sdk.GraphQL import GraphQL from storyhub.sdk.service.ServiceData import ServiceData # note: needs updates/cleanup from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper service_data_fixture = JsonFixtureHelper.load_fixture("wrapper_service_data_fixture") not_python_fixture = JsonFixtureHelper.load_fixture("not_python_fixture") def test_deserialization(): service_datas = JsonFixtureHelper.load_fixture("hello_services") hub = ServiceWrapper.from_dict(service_datas) assert hub.get_all_service_names() == ["test/helloworld", "hello"] def test_deserialization_from_file(mocker): expected_service_datas = ['microservice/python', 'python', 'microservice/hashes', 'storyscript/http', 'http', 'test/helloworld', 'hello'] temp_file = tempfile.mktemp(suffix=".json") with open(temp_file, 'w') as outfile: json.dump(service_data_fixture, outfile) hub = ServiceWrapper.from_json_file(path=temp_file)
def test_deserialization(): service_datas = JsonFixtureHelper.load_fixture("hello_services") hub = ServiceWrapper.from_dict(service_datas) assert hub.get_all_service_names() == ["test/helloworld", "hello"]
import json from storyhub.sdk.service.Contact import Contact from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper contact_fixture = JsonFixtureHelper.load_fixture("contact_fixture") contact_fixture_json = json.dumps(contact_fixture) def test_deserialization(mocker): mocker.patch.object(json, 'loads', return_value=contact_fixture) assert Contact.from_json(jsonstr=contact_fixture_json) is not None json.loads.assert_called_with(contact_fixture_json) def test_serialization(mocker): mocker.patch.object(json, 'dumps', return_value=contact_fixture_json) service_command = Contact.from_dict(data=contact_fixture) assert service_command.as_json(compact=True) is not None json.dumps.assert_called_with(contact_fixture, sort_keys=True) assert service_command.as_json() is not None json.dumps.assert_called_with(contact_fixture, indent=4, sort_keys=True)
import json from storyhub.sdk.service.Contact import Contact from storyhub.sdk.service.License import License from storyhub.sdk.service.ServiceInfo import ServiceInfo from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper service_info_fixture = JsonFixtureHelper.load_fixture("service_info_fixture") service_info_fixture_json = json.dumps(service_info_fixture) def test_deserialization(mocker): mocker.patch.object(json, 'loads', return_value=service_info_fixture) mocker.patch.object(License, 'from_dict') mocker.patch.object(Contact, 'from_dict') service_info = ServiceInfo.from_json(jsonstr=service_info_fixture_json) assert service_info is not None json.loads.assert_called_with(service_info_fixture_json) assert service_info.title( ) == service_info_fixture["service_info"]["title"] assert service_info.description( ) == service_info_fixture["service_info"]["description"] Contact.from_dict.assert_called_with( data={"contact": service_info_fixture["service_info"]["contact"]})
import json from storyhub.sdk.service.Volume import Volume from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper volume_fixture = JsonFixtureHelper.load_fixture("volume_fixture") volume_fixture_json = json.dumps(volume_fixture) def test_deserialization(mocker): mocker.patch.object(json, "loads", return_value=volume_fixture) assert Volume.from_json(jsonstr=volume_fixture_json) is not None json.loads.assert_called_with(volume_fixture_json) def test_serialization(mocker): mocker.patch.object(json, "dumps", return_value=volume_fixture_json) service_entry_point = Volume.from_dict(data=volume_fixture) assert service_entry_point.as_json(compact=True) is not None json.dumps.assert_called_with(volume_fixture, sort_keys=True) assert service_entry_point.as_json() is not None json.dumps.assert_called_with(volume_fixture, indent=4, sort_keys=True)
import json from storyhub.sdk.service.Configuration import Configuration from storyhub.sdk.service.Service import Service from storyhub.sdk.service.ServiceData import ServiceData from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper service_data_fixture = JsonFixtureHelper.load_fixture("service_data_fixture") service_data_fixture_json = json.dumps(service_data_fixture) def test_deserialization(mocker): mocker.patch.object(json, "loads", return_value=service_data_fixture) mocker.patch.object(Configuration, "from_dict") mocker.patch.object(Service, "from_dict") service_data = ServiceData.from_json(service_data_fixture_json) assert service_data is not None json.loads.assert_called_with(service_data_fixture_json) Configuration.from_dict.assert_called_once_with(data={ "configuration": service_data_fixture["service_data"]["configuration"] }) Service.from_dict.assert_called_once_with( data={"service": service_data_fixture["service_data"]["service"]})
import json from storyhub.sdk.service.HttpOptions import HttpOptions from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper http_options_fixture = JsonFixtureHelper.load_fixture("http_option_fixture") http_options_fixture_json = json.dumps(http_options_fixture) def test_deserialization(mocker): mocker.patch.object(json, 'loads', return_value=http_options_fixture) http_options = HttpOptions.from_json(jsonstr=http_options_fixture_json) assert http_options is not None json.loads.assert_called_with(http_options_fixture_json) subscribe = HttpOptions.from_dict(data={ "http_options": http_options_fixture["http_options"]["subscribe"] }) unsubscribe= HttpOptions.from_dict(data={ "http_options": http_options_fixture["http_options"]["unsubscribe"] }) assert http_options.subscribe().path() == subscribe.path() assert http_options.subscribe().method() == subscribe.method() assert http_options.subscribe().content_type() == subscribe.content_type() assert http_options.unsubscribe().path() == unsubscribe.path()
import json from storyhub.sdk.service.Output import Output from storyhub.sdk.service.OutputAction import OutputAction from storyhub.sdk.service.OutputProperty import OutputProperty from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper output_fixture = JsonFixtureHelper.load_fixture("output_fixture") output_fixture_json = json.dumps(output_fixture) def test_deserialization(mocker): mocker.patch.object(json, 'loads', return_value=output_fixture) mocker.patch.object(OutputAction, 'from_dict') mocker.patch.object(OutputProperty, 'from_dict') output = Output.from_json(jsonstr=output_fixture_json) assert output is not None json.loads.assert_called_with(output_fixture_json) assert output.type() == output_fixture["output"]["type"] assert output.content_type() == output_fixture["output"]["contentType"] OutputAction.from_dict.assert_any_call( data={ "name": "write", "output_action": output_fixture["output"]["actions"]["write"]
import json from storyhub.sdk.service.Argument import Argument from storyhub.sdk.service.Command import Command from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper command_fixture = JsonFixtureHelper.load_fixture("command_fixture") command_fixture_json = json.dumps(command_fixture) def test_deserialization(mocker): mocker.patch.object(json, 'loads', return_value=command_fixture) mocker.patch.object(Argument, 'from_dict') assert Command.from_json(jsonstr=command_fixture_json) is not None json.loads.assert_called_with(command_fixture_json) Argument.from_dict.assert_called_with( data={ "name": "path", "argument": command_fixture["command"]["arguments"]["path"] }) def test_serialization(mocker): mocker.patch.object(json, 'dumps', return_value=command_fixture_json)
import json from storyhub.sdk.service.Action import Action from storyhub.sdk.service.Argument import Argument from storyhub.sdk.service.Event import Event from storyhub.sdk.service.HttpOptions import HttpOptions from storyhub.sdk.service.output import OutputObject from storyhub.sdk.service.ServiceOutput import ServiceOutput from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper action_fixture = JsonFixtureHelper.load_fixture("action_fixture") action_fixture_json = json.dumps(action_fixture) def test_deserialization(mocker): mocker.patch.object(json, "loads", return_value=action_fixture) mocker.patch.object(Argument, "from_dict") mocker.patch.object(Event, "from_dict") mocker.patch.object(HttpOptions, "from_dict") mocker.patch.object(ServiceOutput, "from_dict") assert Action.from_json(jsonstr=action_fixture_json) is not None json.loads.assert_called_with(action_fixture_json) Argument.from_dict.assert_any_call( data={ "name": "flush",
import json from storyhub.sdk.service.OutputProperty import OutputProperty from tests.storyhub.sdk.JsonFixtureHelper import JsonFixtureHelper output_property_fixture = JsonFixtureHelper.load_fixture( "output_property_fixture") output_property_fixture_json = json.dumps(output_property_fixture) def test_deserialization(mocker): mocker.patch.object(json, 'loads', return_value=output_property_fixture) assert OutputProperty.from_json( jsonstr=output_property_fixture_json) is not None json.loads.assert_called_with(output_property_fixture_json) def test_serialization(mocker): mocker.patch.object(json, 'dumps', return_value=output_property_fixture_json) service_event = OutputProperty.from_dict(data=output_property_fixture) assert service_event.as_json(compact=True) is not None json.dumps.assert_called_with(output_property_fixture, sort_keys=True) assert service_event.as_json() is not None