def setUp(self): self.wps_path = "/ows/wps" settings = { "weaver.url": "", "weaver.wps": True, "weaver.wps_path": self.wps_path, "weaver.wps_metadata_identification_title": "Weaver WPS Test Server", "weaver.wps_metadata_provider_name": WpsAppTest.__name__ } config = get_test_weaver_config(settings=settings) config = setup_config_with_mongodb(config) config = setup_config_with_pywps(config) config = setup_config_with_celery(config) self.process_store = setup_mongodb_processstore(config) self.app = get_test_weaver_app(config=config, settings=settings) # add processes by database Process type self.process_public = WpsTestProcess(identifier="process_public") self.process_private = WpsTestProcess(identifier="process_private") self.process_store.save_process(self.process_public) self.process_store.save_process(self.process_private) self.process_store.set_visibility(self.process_public.identifier, VISIBILITY_PUBLIC) self.process_store.set_visibility(self.process_private.identifier, VISIBILITY_PRIVATE) # add processes by pywps Process type self.process_store.save_process(HelloWPS()) self.process_store.set_visibility(HelloWPS.identifier, VISIBILITY_PUBLIC)
def test_deploy_opensearch(): store = setup_mongodb_processstore() class MockDB(object): def __init__(self, *args): pass def get_store(self, *_): # noqa: E811 return store def _get_mocked(req): return req.registry.settings # mock db functions called by add_local_process with contextlib.ExitStack() as stack: stack.enter_context( mock.patch("weaver.wps_restapi.processes.processes.get_db", side_effect=MockDB)) stack.enter_context( mock.patch("weaver.wps_restapi.processes.utils.get_db", side_effect=MockDB)) stack.enter_context( mock.patch("weaver.wps_restapi.processes.utils.get_settings", side_effect=_get_mocked)) stack.enter_context( mock.patch("weaver.database.get_settings", side_effect=_get_mocked)) stack.enter_context( mock.patch("weaver.database.mongodb.get_settings", side_effect=_get_mocked)) stack.enter_context( mock.patch("weaver.datatype.get_settings", side_effect=_get_mocked)) stack.enter_context( mock.patch("weaver.processes.utils.get_db", side_effect=MockDB)) stack.enter_context( mock.patch("weaver.processes.utils.get_settings", side_effect=_get_mocked)) # given opensearch_payload = get_opensearch_payload() initial_payload = deepcopy(opensearch_payload) request = make_request(json=opensearch_payload, method="POST") process_id = get_any_id( opensearch_payload["processDescription"]["process"]) # when response = processes.add_local_process(request) # then assert response.code == 201 assert response.json["deploymentDone"] process = store.fetch_by_id(process_id) assert process assert process.package assert process.payload assert_json_equals(process.payload, initial_payload)
def setUpClass(cls): config = setup_config_with_mongodb(settings=cls.settings) config = setup_config_with_pywps(config) config = setup_config_with_celery(config) config = get_test_weaver_config(config) cls.process_store = setup_mongodb_processstore(config) # force reset cls.job_store = setup_mongodb_jobstore(config) cls.app = get_test_weaver_app(config=config, settings=cls.settings) cls.db = get_db(config) cls.config = config cls.settings.update(cls.config.registry.settings) # back propagate changes
def setUp(self): # rebuild clean db on each test self.job_store = setup_mongodb_jobstore(self.config) self.process_store = setup_mongodb_processstore(self.config) self.service_store = setup_mongodb_servicestore(self.config) self.user_admin_id = 100 self.user_editor1_id = 1 self.user_editor2_id = 2 self.process_public = WpsTestProcess(identifier="process-public") self.process_store.save_process(self.process_public) self.process_store.set_visibility(self.process_public.identifier, VISIBILITY_PUBLIC) self.process_private = WpsTestProcess(identifier="process-private") self.process_store.save_process(self.process_private) self.process_store.set_visibility(self.process_private.identifier, VISIBILITY_PRIVATE) self.process_unknown = "process-unknown" self.service_public = Service(name="service-public", url="http://localhost/wps/service-public", public=True) self.service_store.save_service(self.service_public) self.service_private = Service(name="service-private", url="http://localhost/wps/service-private", public=False) self.service_store.save_service(self.service_private) # create jobs accessible by index self.job_info = [] # type: List[Job] self.make_job(task_id="0000-0000-0000-0000", process=self.process_public.identifier, service=None, user_id=self.user_editor1_id, status=STATUS_SUCCEEDED, progress=100, access=VISIBILITY_PUBLIC) self.make_job(task_id="1111-1111-1111-1111", process=self.process_unknown, service=self.service_public.name, user_id=self.user_editor1_id, status=STATUS_FAILED, progress=99, access=VISIBILITY_PUBLIC) self.make_job(task_id="2222-2222-2222-2222", process=self.process_private.identifier, service=None, user_id=self.user_editor1_id, status=STATUS_FAILED, progress=55, access=VISIBILITY_PUBLIC) # same process as job 0, but private (ex: job ran with private process, then process made public afterwards) self.make_job(task_id="3333-3333-3333-3333", process=self.process_public.identifier, service=None, user_id=self.user_editor1_id, status=STATUS_FAILED, progress=55, access=VISIBILITY_PRIVATE) # job ran by admin self.make_job(task_id="4444-4444-4444-4444", process=self.process_public.identifier, service=None, user_id=self.user_admin_id, status=STATUS_FAILED, progress=55, access=VISIBILITY_PRIVATE) # job public/private service/process combinations self.make_job(task_id="5555-5555-5555-5555", process=self.process_public.identifier, service=self.service_public.name, user_id=self.user_editor1_id, status=STATUS_FAILED, progress=99, access=VISIBILITY_PUBLIC) self.make_job(task_id="6666-6666-6666-6666", process=self.process_private.identifier, service=self.service_public.name, user_id=self.user_editor1_id, status=STATUS_FAILED, progress=99, access=VISIBILITY_PUBLIC) self.make_job(task_id="7777-7777-7777-7777", process=self.process_public.identifier, service=self.service_private.name, user_id=self.user_editor1_id, status=STATUS_FAILED, progress=99, access=VISIBILITY_PUBLIC) self.make_job(task_id="8888-8888-8888-8888", process=self.process_private.identifier, service=self.service_private.name, user_id=self.user_editor1_id, status=STATUS_FAILED, progress=99, access=VISIBILITY_PUBLIC)
def setUp(self): # rebuild clean db on each test self.process_store = setup_mongodb_processstore(self.config) self.job_store = setup_mongodb_jobstore(self.config) self.remote_server = "local" self.process_remote_WPS1 = "process_remote_wps1" self.process_remote_WPS3 = "process_remote_wps3" self.process_public = WpsTestProcess(identifier="process_public") self.process_private = WpsTestProcess(identifier="process_private") self.process_store.save_process(self.process_public) self.process_store.save_process(self.process_private) self.process_store.set_visibility(self.process_public.identifier, VISIBILITY_PUBLIC) self.process_store.set_visibility(self.process_private.identifier, VISIBILITY_PRIVATE)
def setUp(self): # rebuild clean db on each test self.service_store = setup_mongodb_servicestore(self.config) self.process_store = setup_mongodb_processstore(self.config) self.job_store = setup_mongodb_jobstore(self.config) self.app_url = self.settings["weaver.url"]
def test_register_wps_processes_from_config_valid(): """ Validate the different combinations of supported remote WPS-1 processes and providers specifications. """ settings = { "weaver.url": "https://localhost", "weaver.wps_path": "/ows/wps", # define some options to avoid useless retry/timeout # everything is mocked and should return immediately "weaver.request_options": { "requests": [{ "url": WPS1_URL1, "method": "get", "timeout": 1, "retry": 0 }] } } config = setup_config_with_mongodb(settings=settings) p_store = setup_mongodb_processstore(config) s_store = setup_mongodb_servicestore(config) p_store.clear_processes() s_store.clear_services() with tempfile.NamedTemporaryFile(mode="w", suffix=".yml") as f: yaml.safe_dump( { # dynamic processes, only register provider explicitly, processes fetched on demand "providers": [ WPS1_URL1, # direct URL string { "url": WPS1_URL2 }, # implicit name, but as dict { "name": "test-explicit-name", "url": WPS1_URL3 }, ], # static processes, all the ones under service are registered explicitly, unless filtered "processes": [ WPS1_URL1, # direct URL string, has only 1 process that will be retrieved by DescribeProcess 'iteratively' # the 'GetCapabilities' provides which processes to iterate over resources.GET_CAPABILITIES_TEMPLATE_URL.format(WPS1_URL2), # following will call DescribeProcess resources.DESCRIBE_PROCESS_TEMPLATE_URL.format( WPS1_URL3, resources.TEST_REMOTE_PROCESS_WPS1_ID), # same as GetCapabilities with iteration on available processes with DescribeProcess, # but will replace the default server name by the provided one (so can reuse same URL) { "name": "test-static-process", "url": WPS1_URL1 }, # directly call DescribeProcess bypassing the GetCapabilities { "name": "test-filter-process", "url": WPS1_URL4, # should only fetch following two rather than the 11 (fake) ones reported by GetCapabilities "id": [ resources.WPS_ENUM_ARRAY_IO_ID, resources.WPS_LITERAL_COMPLEX_IO_ID ] } ] }, f) try: # note: # can take some time to process since OWSLib must parse all GetCapabilities/DescribeProcesses responses register_wps_processes_from_config(f.name, config) except Exception: # noqa pytest.fail( "Valid definitions in configuration file should not raise any error" ) # validate results processes = p_store.list_processes() providers = s_store.list_services() # generate equivalent of inferred named (simplified) infer_name1 = WPS1_URL1.split("://")[-1].replace(".com", "_com") infer_name2 = WPS1_URL2.split("://")[-1].replace(".com", "_com") infer_name3 = WPS1_URL3.split("://")[-1].replace(".com", "_com") # dynamic provider inferred names are sanitized/slug of URL assert len( providers ) == 3, "Number of dynamic WPS-1 providers registered should match number from file." svc1 = s_store.fetch_by_name(infer_name1) assert svc1.url == WPS1_URL1 svc2 = s_store.fetch_by_name(infer_name2) assert svc2.url == WPS1_URL2 svc3 = s_store.fetch_by_name("test-explicit-name") assert svc3.url == WPS1_URL3 # (1) first server has 1 process in GetCapabilities, the basic URL registers only that process # (1) second server also has 1 process, but GetCapabilities queries already in the URL are cleaned up # (1) third directly references the DescribeProcess request, so it is fetched directly # (1) fourth entry is the same as first, just using another name # (2) fifth entry provided 2 processes ID explicitly. Although 11 processes are available, only those 2 are created. assert len( processes ) == 6, "Number of static remote WPS-1 processes registered should match number from file." # static processes inferred names are a concatenation of the URL sanitized/slug + process-ID proc1_id = infer_name1 + "_" + resources.TEST_REMOTE_PROCESS_WPS1_ID proc1 = p_store.fetch_by_id(proc1_id) assert proc1.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "provider"] == WPS1_URL1 + "/" assert proc1.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "process"] == resources.TEST_REMOTE_PROCESS_WPS1_ID proc2_id = infer_name2 + "_" + resources.TEST_REMOTE_PROCESS_WPS1_ID proc2 = p_store.fetch_by_id(proc2_id) assert proc2.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "provider"] == WPS1_URL2 + "/" assert proc2.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "process"] == resources.TEST_REMOTE_PROCESS_WPS1_ID proc3_id = infer_name3 + "_" + resources.TEST_REMOTE_PROCESS_WPS1_ID proc3 = p_store.fetch_by_id(proc3_id) assert proc3.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "provider"] == WPS1_URL3 + "/" assert proc3.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "process"] == resources.TEST_REMOTE_PROCESS_WPS1_ID # although an explicit name is provided, the URL point to generic GetCapabilities # therefore, multiple processes *could* be registered, which require same server-name+process-id concat as above proc4_id = "test-static-process_" + resources.TEST_REMOTE_PROCESS_WPS1_ID proc4 = p_store.fetch_by_id(proc4_id) assert proc4.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "provider"] == WPS1_URL1 + "/" assert proc4.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "process"] == resources.TEST_REMOTE_PROCESS_WPS1_ID # last server is the same, but specific IDs are given # still, concat happens to avoid conflicts against multiple servers sharing process-IDs, although distinct proc5_id = "test-filter-process_" + resources.WPS_ENUM_ARRAY_IO_ID proc5 = p_store.fetch_by_id(proc5_id) assert proc5.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "provider"] == WPS1_URL4 + "/" assert proc5.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "process"] == resources.WPS_ENUM_ARRAY_IO_ID proc6_id = "test-filter-process_" + resources.WPS_LITERAL_COMPLEX_IO_ID proc6 = p_store.fetch_by_id(proc6_id) assert proc6.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "provider"] == WPS1_URL4 + "/" assert proc6.package["hints"][CWL_REQUIREMENT_APP_WPS1][ "process"] == resources.WPS_LITERAL_COMPLEX_IO_ID