def load_services_from_file(cls):
     """
     Loads services from files into the _fixed_service_wrapper
     each time it is called.
     """
     cls._fixed_service_wrapper = ServiceWrapper.from_json_file(
         hub_fixtures_file)
def test_serialization(mocker):
    expected_service_datas = [
        "test/helloworld",
        "hello",
        "microservice/hashes",
        "microservice/not_python",
        "npython",
    ]

    mocker.patch.object(GraphQL, "get_all", return_value=service_data_fixture)

    hub = ServiceWrapper(["hello", "microservice/hashes"])

    hub.update_service(not_python_fixture, hub.services)

    temp_file = tempfile.mktemp(suffix=".json")

    hub.as_json_file(temp_file)

    assert hub.get_all_service_names() == expected_service_datas

    test_hub = ServiceWrapper.from_json_file(path=temp_file)

    assert test_hub.get_all_service_names() == expected_service_datas

    os.remove(temp_file)
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)

    mocker.patch.object(ServiceData, "from_dict")

    assert hub.get_all_service_names() == expected_service_datas

    assert hub.get("python") is not None

    ServiceData.from_dict.assert_called_with(
        data={"service_data": service_data_fixture[0]})

    os.remove(path=temp_file)
Exemplo n.º 4
0
def test_init_hub_path(patch):
    """
    Tests that an SLS App with a Hub Path gets properly initialized.
    """
    patch.object(ServiceWrapper, "from_json_file")
    hub_path = ".hub.path."
    app = App(hub_path=hub_path)
    ServiceWrapper.from_json_file.assert_called_with(hub_path)
    assert app.hub is ServiceWrapper.from_json_file()
Exemplo n.º 5
0
 def read_hub_from_json(self):
     """
     Try loading an existing service JSON blob from storage.
     Returns an initialized ServiceWrapper if successful, None otherwise.
     """
     try:
         return ServiceWrapper.from_json_file(self.hub_path)
     except JSONDecodeError:
         # local JSON blob might be invalid
         # see e.g. https://github.com/storyscript/sls/issues/191
         return None
     except OSError:
         # reading local JSON blob might fail
         # see e.g. https://github.com/storyscript/sls/issues/195
         return None
Exemplo n.º 6
0
def test_init_hub_path(patch):
    """
    Tests that an SLS App with a Hub Path gets properly initialized.
    """
    patch.init(Workspace)
    patch.object(ServiceWrapper,
                 "from_json_file",
                 return_value="ConstServiceHub")
    hub_path = ".hub.path."
    app = App(hub_path=hub_path)
    ServiceWrapper.from_json_file.assert_called_with(hub_path)
    Workspace.__init__.assert_called_with(".root.",
                                          hub=ServiceWrapper.from_json_file())
    assert isinstance(app.ws, Workspace)
    assert app.hub == "ConstServiceHub"
Exemplo n.º 7
0
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)

    mocker.patch.object(ServiceData, 'from_dict')

    assert hub.get_all_service_names() == expected_service_datas

    assert hub.get('python') is not None

    ServiceData.from_dict.assert_called_with(data={"service_data": service_data_fixture[0]})

    os.remove(path=temp_file)
Exemplo n.º 8
0
def test_serialization(mocker):
    expected_service_datas = ['microservice/not_python', 'npython', 'test/helloworld', 'hello', 'microservice/hashes']

    mocker.patch.object(GraphQL, 'get_all', return_value=service_data_fixture)

    hub = ServiceWrapper([not_python_fixture,
        "hello",
        "microservice/hashes"
    ])

    temp_file = tempfile.mktemp(suffix=".json")

    hub.as_json_file(temp_file)

    assert hub.get_all_service_names() == expected_service_datas

    test_hub = ServiceWrapper.from_json_file(path=temp_file)

    assert test_hub.get_all_service_names() == expected_service_datas

    os.remove(temp_file)
Exemplo n.º 9
0
 def __init__(self, hub=None, hub_path=None):
     self.language_server = LanguageServer
     if isinstance(hub_path, str):
         hub = ServiceWrapper.from_json_file(hub_path)
     self.hub = hub
     self.ws = Workspace(".root.", hub=hub)
Exemplo n.º 10
0
from glob import glob
from os import path

from storyhub.sdk.ServiceWrapper import ServiceWrapper

test_dir = path.dirname(path.dirname(path.realpath(__file__)))


def find_test_files(relative=False):
    """
    Returns all available test files.
    """
    files = glob(path.join(test_dir, "**", "*.story"), recursive=True)
    if relative:
        return list(map(lambda e: path.relpath(e, test_dir), files))
    return files


fixture_dir = path.join(test_dir, "..", "fixtures", "hub")
fixture_file = path.join(fixture_dir, "hub.fixed.json")

hub = ServiceWrapper.from_json_file(fixture_file)