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"))
def test_get_with_wrap_service(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})
def test_caching(mocker): config = {"actions": {"foo": "bar"}} owner = "default_username" actual_service = VerifiableService( owner_name=owner, name="sample_name", alias="sample_alias", topics=["the", "topics", "are", "here"], desc="service_description", certified=False, public=True, uuid="A86742FD-55B4-4AEC-92B9-9989B3AF2F7E", state="BETA", config=config, readme="readme_here", ) registered_services = [actual_service.service] mocker.patch.object(GraphQL, "get_all", return_value=registered_services) hub = StoryscriptHub(db_path=tempfile.mkdtemp()) # No need to call update_cache explicitly, since the background thread will # call it. Just sleep for a split second. # hub.update_cache() sleep(0.2) assert hub.get_all_service_names() == [ "sample_alias", "default_username/sample_name", ] service = hub.get(alias="sample_alias") actual_service.verify(service) service = hub.get(owner="default_username", name="sample_name") actual_service.verify(service) second_service = VerifiableService( owner_name="second_username", name="second_service", alias="second_service", topics=["second_", "the", "topics", "are", "here"], desc="second_service_description", certified=True, public=False, uuid="7D5D5A94-F45D-4F44-9B65-BAE13C49AAF4", state="BETA", config=config, readme="second_readme_here", ) registered_services.append(second_service.service) actual_service = hub.get(alias="second_service") assert actual_service is not None
def test_caching(mocker): config = {'config_bucket': True} owner = 'default_username' actual_service = VerifiableService( owner_name=owner, name='sample_name', alias='sample_alias', topics=['the', 'topics', 'are', 'here'], desc='service_description', certified=False, public=True, uuid='A86742FD-55B4-4AEC-92B9-9989B3AF2F7E', state='BETA', config=config, readme='readme_here') registered_services = [actual_service.service] mocker.patch.object(GraphQL, 'get_all', return_value=registered_services) hub = StoryscriptHub(db_path=tempfile.mkdtemp()) # No need to call update_cache explicitly, since the background thread will # call it. Just sleep for a split second. # hub.update_cache() sleep(0.2) assert hub.get_all_service_names() == [ 'sample_alias', 'default_username/sample_name' ] service = hub.get(alias='sample_alias') actual_service.verify(service) service = hub.get(owner='default_username', name='sample_name') actual_service.verify(service) second_service = VerifiableService( owner_name='second_username', name='second_service', alias='second_service', topics=['second_', 'the', 'topics', 'are', 'here'], desc='second_service_description', certified=True, public=False, uuid='7D5D5A94-F45D-4F44-9B65-BAE13C49AAF4', state='BETA', config=config, readme='second_readme_here') registered_services.append(second_service.service) actual_service = hub.get(alias='second_service') assert actual_service is not None
def update_hub_fixture(): fixture_dir = path.dirname(path.realpath(__file__)) out_file = path.join(fixture_dir, "hub.fixed.json") services = StoryscriptHub().get_all_service_names() ServiceWrapper(services).as_json_file(out_file)
def story_hub(): """ Returns a cached instance of StoryscriptHub() from the hub sdk. """ return StoryscriptHub()
def _story_hub(): """ Cached instance of the hub sdk """ return StoryscriptHub()