コード例 #1
0
ファイル: test_wps_app.py プロジェクト: crim-ca/weaver
    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)
コード例 #2
0
    def test_swagger_api_request_base_path_proxied(self):
        """
        Validates that Swagger JSON properly redefines the host/path to test live requests on Swagger UI
        when the app's URI resides behind a proxy pass redirect path as specified by setting ``weaver.url``.
        """

        # fake "proxy" derived path for testing simulated server proxy pass
        # create redirect views to simulate the server proxy pass
        config = get_test_weaver_config(settings={"weaver.url": self.app_proxy_url})  # real access proxy path in config
        for service in [sd.api_swagger_json_service, sd.api_swagger_ui_service]:
            name = service.name + "_proxy"
            config.add_route(name=name, path=self.proxy_path + service.path)
            config.add_view(self.redirect_api_view, route_name=name)
        testapp = get_test_weaver_app(config)

        # setup environment that would define the new weaver location for the proxy pass
        resp = testapp.get(self.app_proxy_json, headers=self.json_headers)
        assert resp.status_code == 302, "Request should be at proxy level at this point."
        resp = resp.follow()
        assert resp.status_code == 200
        assert resp.json["host"] == self.app_host
        assert resp.json["basePath"] == self.proxy_path, \
            "Proxy path specified by setting 'weaver.url' should be used in API definition to allow live requests."

        # validate that swagger UI still renders and has valid URL
        resp = testapp.get(self.app_proxy_ui)
        assert resp.status_code == 302, "Request should be at proxy level at this point."
        resp = resp.follow()
        assert resp.status_code == 200
        assert "<title>{}</title>".format(sd.API_TITLE) in resp.text
コード例 #3
0
 def setUpClass(cls):
     cls.testapp = get_test_weaver_app(settings={
         "weaver.wps": True,
         "weaver.wps_restapi": True
     })
     cls.json_headers = {
         "Accept": CONTENT_TYPE_APP_JSON,
         "Content-Type": CONTENT_TYPE_APP_JSON
     }
コード例 #4
0
 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
コード例 #5
0
ファイル: test_processes.py プロジェクト: 00mjk/weaver
 def setUpClass(cls):
     settings = {
         "weaver.url": "https://localhost",
         "weaver.wps_path": "/ows/wps",
     }
     cls.config = setup_config_with_mongodb(settings=settings)
     cls.app = get_test_weaver_app(config=cls.config)
     cls.json_headers = {
         "Accept": CONTENT_TYPE_APP_JSON,
         "Content-Type": CONTENT_TYPE_APP_JSON
     }
     cls.app = webtest.TestApp(cls.config.make_wsgi_app())
コード例 #6
0
    def test_swagger_api_request_base_path_original(self):
        """
        Validates that Swagger JSON properly uses the original host/path to test live requests on Swagger UI
        when the app's URI results direct route access.
        """
        # base app without proxy pass
        # ensure that setting that would define the weaver's location is not defined for local app
        config = get_test_weaver_config(settings={"weaver.url": None})
        testapp = get_test_weaver_app(config)

        resp = testapp.get(sd.api_swagger_json_service.path, headers=self.json_headers)
        assert resp.status_code == 200, "API definition should be accessed directly"
        assert resp.json["host"] in [self.app_host, "{}:80".format(self.app_host)]
        assert resp.json["basePath"] == sd.api_frontpage_uri

        resp = testapp.get(sd.api_swagger_ui_service.path)
        assert resp.status_code == 200, "API definition should be accessed directly"
        assert "<title>{}</title>".format(sd.API_TITLE) in resp.text
コード例 #7
0
    def test_swagger_api_request_base_path_proxied(self):
        """
        Validates that Swagger JSON properly redefines the host/path to test live requests on Swagger UI when the app's
        URI resides behind a proxy pass redirect path as specified by setting ``weaver.url``.
        """

        # fake "proxy" derived path for testing simulated server proxy pass
        # create redirect views to simulate the server proxy pass
        config = get_test_weaver_config(
            settings={"weaver.url":
                      self.app_proxy_url})  # real access proxy path in config
        test_app = get_test_weaver_app(config=config)

        config = pyramid.testing.setUp(settings={})
        config.add_route(name="proxy",
                         path=self.proxy_path,
                         pattern=self.proxy_path + "/{remain:.*}")
        config.add_view(self.redirect_api_view, route_name="proxy")
        redirect_app = WebTestApp(config.make_wsgi_app())

        # setup environment that would define the new weaver location for the proxy pass
        resp = redirect_app.get(self.app_proxy_json, headers=self.json_headers)
        assert resp.status_code == 302, "Request should be at proxy level at this point."
        resp.test_app = test_app  # replace object to let follow redirect correctly
        resp = resp.follow()
        assert resp.status_code == 200
        assert resp.json["host"] == self.app_host
        assert resp.json["basePath"] == self.proxy_path, \
            "Proxy path specified by setting 'weaver.url' should be used in API definition to allow live requests."

        # validate that swagger UI still renders and has valid URL
        resp = redirect_app.get(self.app_proxy_ui)
        assert resp.status_code == 302, "Request should be at proxy level at this point."
        resp.test_app = test_app  # replace object to let follow redirect correctly
        resp = resp.follow()
        assert resp.status_code == 200
        assert "<title>{}</title>".format(sd.API_TITLE) in resp.text
コード例 #8
0
 def setUp(self):
     config = setup_config_with_mongodb()
     self.testapp = get_test_weaver_app(config)
コード例 #9
0
 def setUpClass(cls):
     cls.testapp = get_test_weaver_app(settings=None)
     cls.json_headers = {"Accept": CONTENT_TYPE_APP_JSON, "Content-Type": CONTENT_TYPE_APP_JSON}