def runSuite(module, tests):
    """This allows for a list of test names to be selectively run.
    Also, ensures unittest verbose output comes at end, after debug output"""
    loader = unittest.defaultTestLoader
    if 'PAL_SUITE' in os.environ:
        if tests:
            suite = loader.loadTestsFromNames(tests, module)
        else:
            raise Exception(
                "\n\n####__ 'PAL_SUITE' set, but no tests specified __####\n")
    else:
        suite = loader.loadTestsFromModule(module)
    verb = 2 if 'PAL_VERBOSE' in os.environ else 0

    res = unittest.TextTestRunner(verbosity=verb).run(suite)

    if PALREPORTS:
        teststamp = 'PAL Test Report: ' + \
                    datetime.datetime.now().strftime('%Y-%m-%d %X')
        report = '<html><head><title>{0}</title></head><body>'.format(teststamp)
        report += '\n<h2>Failed Tests: {0}</h2>'.format(len(PALREPORTS))
        for k, v in list(PALREPORTS.items()):
            report += '\n<h3>{0}</h3>\n{1}'.format(k, v)
        report += '</body></html>'

        tmp_name = getTempfilePath('html')
        with open(tmp_name, 'wt') as report_file:
            report_file.write(report)
        openInBrowserTab('file://' + tmp_name)

    return res
예제 #2
0
def run_suite(module, tests):
    """This allows for a list of test names to be selectively run.
    Also, ensures unittest verbose output comes at end, after debug output"""
    loader = unittest.defaultTestLoader
    if 'QGIS_TEST_SUITE' in os.environ and tests:
        suite = loader.loadTestsFromNames(tests, module)
    else:
        suite = loader.loadTestsFromModule(module)
    verb = 2 if 'QGIS_TEST_VERBOSE' in os.environ else 0

    res = unittest.TextTestRunner(verbosity=verb).run(suite)

    if QGIS_TEST_REPORT and len(TESTREPORTS) > 0:
        teststamp = 'Local Server Test Report: ' + \
                    datetime.datetime.now().strftime('%Y-%m-%d %X')
        report = '<html><head><title>{0}</title></head><body>'.format(teststamp)
        report += '\n<h2>Failed Image Tests: {0}</h2>'.format(len(TESTREPORTS))
        for k, v in list(TESTREPORTS.items()):
            report += '\n<h3>{0}</h3>\n{1}'.format(k, v)
        report += '</body></html>'

        tmp_name = getTempfilePath("html")
        with open(tmp_name, 'wb') as temp_file:
            temp_file.write(report)
        openInBrowserTab('file://' + tmp_name)

    return res
예제 #3
0
def runSuite(module, tests):
    """This allows for a list of test names to be selectively run.
    Also, ensures unittest verbose output comes at end, after debug output"""
    loader = unittest.defaultTestLoader
    if "PAL_SUITE" in os.environ:
        if tests:
            suite = loader.loadTestsFromNames(tests, module)
        else:
            raise Exception("\n\n####__ 'PAL_SUITE' set, but no tests specified __####\n")
    else:
        suite = loader.loadTestsFromModule(module)
    verb = 2 if "PAL_VERBOSE" in os.environ else 0

    out = StringIO.StringIO()
    res = unittest.TextTestRunner(stream=out, verbosity=verb).run(suite)
    if verb:
        print "\nIndividual test summary:"
    print "\n" + out.getvalue()
    out.close()

    if PALREPORTS:
        teststamp = "PAL Test Report: " + datetime.datetime.now().strftime("%Y-%m-%d %X")
        report = "<html><head><title>{0}</title></head><body>".format(teststamp)
        report += "\n<h2>Failed Tests: {0}</h2>".format(len(PALREPORTS))
        for k, v in PALREPORTS.iteritems():
            report += "\n<h3>{0}</h3>\n{1}".format(k, v)
        report += "</body></html>"

        tmp = tempfile.NamedTemporaryFile(suffix=".html", delete=False)
        tmp.write(report)
        tmp.close()
        openInBrowserTab("file://" + tmp.name)

    return res
예제 #4
0
def runSuite(module, tests):
    """This allows for a list of test names to be selectively run.
    Also, ensures unittest verbose output comes at end, after debug output"""
    loader = unittest.defaultTestLoader
    if 'PAL_SUITE' in os.environ and tests:
        suite = loader.loadTestsFromNames(tests, module)
    else:
        suite = loader.loadTestsFromModule(module)
    verb = 2 if 'PAL_VERBOSE' in os.environ else 0

    out = StringIO.StringIO()
    res = unittest.TextTestRunner(stream=out, verbosity=verb).run(suite)
    if verb:
        print '\nIndividual test summary:'
    print '\n' + out.getvalue()
    out.close()

    if PALREPORTS:
        teststamp = 'PAL Test Report: ' + \
                    datetime.datetime.now().strftime('%Y-%m-%d %X')
        report = '<html><head><title>{0}</title></head><body>'.format(teststamp)
        report += '\n<h2>Failed Tests: {0}</h2>'.format(len(PALREPORTS))
        for k, v in PALREPORTS.iteritems():
            report += '\n<h3>{0}</h3>\n{1}'.format(k, v)
        report += '</body></html>'

        tmp = tempfile.NamedTemporaryFile(suffix=".html", delete=False)
        tmp.write(report)
        tmp.close()
        openInBrowserTab('file://' + tmp.name)

    return res
예제 #5
0
    def get_capabilities(self, params, browser=False):
        assert self.processes_running(), "Server processes not running"

        params = self._params_to_upper(params)
        if ("REQUEST" in params and params["REQUEST"] != "GetCapabilities") or "REQUEST" not in params:
            params["REQUEST"] = "GetCapabilities"

        url = self._fcgi_url + "?" + self.process_params(params)

        res = urllib.urlopen(url)
        xml = res.read()
        if browser:
            tmp = tempfile.NamedTemporaryFile(suffix=".html", delete=False)
            tmp.write(xml)
            url = tmp.name
            tmp.close()
            openInBrowserTab(url)
            return False, ""

        success = "perhaps you left off the .qgs extension" in xml or "WMS_Capabilities" in xml
        return success, xml
예제 #6
0
    def get_capabilities(self, params, browser=False):
        assert self.processes_running(), "Server processes not running"

        params = self._params_to_upper(params)
        if ("REQUEST" in params and params["REQUEST"] != "GetCapabilities") or "REQUEST" not in params:
            params["REQUEST"] = "GetCapabilities"

        url = self._fcgi_url + "?" + self.process_params(params)

        res = urllib.request.urlopen(url)
        xml = res.read().decode("utf-8")
        if browser:
            tmp_name = getTempfilePath("html")
            with open(tmp_name, "wt") as temp_html:
                temp_html.write(xml)
            url = tmp_name
            openInBrowserTab(url)
            return False, ""

        success = "error reading the project file" in xml or "WMS_Capabilities" in xml
        return success, xml
예제 #7
0
    def get_capabilities(self, params, browser=False):
        assert self.processes_running(), 'Server processes not running'

        params = self._params_to_upper(params)
        if (('REQUEST' in params and params['REQUEST'] != 'GetCapabilities') or
                'REQUEST' not in params):
            params['REQUEST'] = 'GetCapabilities'

        url = self._fcgi_url + '?' + self.process_params(params)

        res = urllib.request.urlopen(url)
        xml = res.read().decode('utf-8')
        if browser:
            tmp_name = getTempfilePath('html')
            with open(tmp_name, 'wt') as temp_html:
                temp_html.write(xml)
            url = tmp_name
            openInBrowserTab(url)
            return False, ''

        success = ('error reading the project file' in xml or
                   'WMS_Capabilities' in xml)
        return success, xml
예제 #8
0
    def get_capabilities(self, params, browser=False):
        assert self.processes_running(), 'Server processes not running'

        params = self._params_to_upper(params)
        if (('REQUEST' in params and params['REQUEST'] != 'GetCapabilities') or
                'REQUEST' not in params):
            params['REQUEST'] = 'GetCapabilities'

        url = self._fcgi_url + '?' + self.process_params(params)

        res = urllib.urlopen(url)
        xml = res.read()
        if browser:
            tmp = tempfile.NamedTemporaryFile(suffix=".html", delete=False)
            tmp.write(xml)
            url = tmp.name
            tmp.close()
            openInBrowserTab(url)
            return False, ''

        success = ('perhaps you left off the .qgs extension' in xml or
                   'WMS_Capabilities' in xml)
        return success, xml
예제 #9
0
    def get_map(self, params, browser=False):
        assert self.processes_running(), 'Server processes not running'

        msg = ('Map request parameters should be passed in as a dict '
               '(key case can be mixed)')
        assert isinstance(params, dict), msg

        params = self._params_to_upper(params)
        try:
            proj = params['MAP']
        except KeyError as err:
            raise KeyError(str(err) + '\nMAP not found in parameters dict')

        if not os.path.exists(proj):
            msg = '{0}'.format(proj)
            w_proj = os.path.join(self._web_dir, proj)
            if os.path.exists(w_proj):
                params['MAP'] = w_proj
            else:
                msg += '\n  or\n' + w_proj
                raise ServerProcessError(
                    'GetMap Request Error',
                    'Project not found at:\n{0}'.format(msg)
                )

        if (('REQUEST' in params and params['REQUEST'] != 'GetMap') or
                'REQUEST' not in params):
            params['REQUEST'] = 'GetMap'

        url = self._fcgi_url + '?' + self.process_params(params)

        if browser:
            openInBrowserTab(url)
            return False, ''

        # try until qgis_mapserv.fcgi process is available (for 20 seconds)
        # on some platforms the fcgi_server_process is a daemon handling the
        # launch of the fcgi-spawner, which may be running quickly, but the
        # qgis_mapserv.fcgi spawned process is not yet accepting connections
        resp = None
        tmp_png = None
        # noinspection PyUnusedLocal
        filepath = ''
        # noinspection PyUnusedLocal
        success = False
        start_time = time.time()
        while time.time() - start_time < 20:
            resp = None
            try:
                tmp_png = urllib.request.urlopen(url)
            except urllib.error.HTTPError as resp:
                if resp.code == 503 or resp.code == 500:
                    time.sleep(1)
                else:
                    raise ServerProcessError(
                        'Web/FCGI Process Request HTTPError',
                        'Cound not connect to process: ' + str(resp.code),
                        resp.message
                    )
            except urllib.error.URLError as resp:
                raise ServerProcessError(
                    'Web/FCGI Process Request URLError',
                    'Cound not connect to process',
                    resp.reason
                )
            else:
                delta = time.time() - start_time
                print(('Seconds elapsed for server GetMap: ' + str(delta)))
                break

        if resp is not None:
            raise ServerProcessError(
                'Web/FCGI Process Request Error',
                'Cound not connect to process: ' + str(resp.code)
            )

        if (tmp_png is not None
                and tmp_png.info().getmaintype() == 'image'
                and tmp_png.info().getheader('Content-Type') == 'image/png'):

            filepath = getTempfilePath('png')
            with open(filepath, 'wb') as temp_image:
                temp_image.write(tmp_png.read())
            success = True
        else:
            raise ServerProcessError(
                'FCGI Process Request Error',
                'No valid PNG output'
            )

        return success, filepath, url
예제 #10
0
        # 'BBOX': QgsRectangle(606510, 4823130, 612510, 4827130)
        'BBOX': '606510,4823130,612510,4827130',
        'FORMAT': 'image/png',  # or: 'image/png; mode=8bit'
        'WIDTH': '600',
        'HEIGHT': '400',
        'DPI': '72',
        'MAP_RESOLUTION': '72',
        'FORMAT_OPTIONS': 'dpi:72',
        'TRANSPARENT': 'FALSE',
        'IgnoreGetMapUrl': '1'
    }

    # local_srv.web_server_process().start()
    # openInBrowserTab('http://127.0.0.1:8448')
    # local_srv.web_server_process().stop()
    # sys.exit()
    local_srv.startup(False)
    openInBrowserTab('http://127.0.0.1:8448')
    try:
        local_srv.check_server_capabilities()
        # open resultant png with system
        result, png, url = local_srv.get_map(req_params)
    finally:
        local_srv.shutdown()

    if result:
        # print png
        openInBrowserTab('file://' + png)
    else:
        raise ServerProcessError('GetMap Test', 'Failed to generate PNG')
예제 #11
0
        if not os.path.exists(proj):
            msg = "{0}".format(proj)
            w_proj = os.path.join(self._web_dir, proj)
            if os.path.exists(w_proj):
                params["MAP"] = w_proj
            else:
                msg += "\n  or\n" + w_proj
                raise ServerProcessError("GetMap Request Error", "Project not found at:\n{0}".format(msg))

        if ("REQUEST" in params and params["REQUEST"] != "GetMap") or "REQUEST" not in params:
            params["REQUEST"] = "GetMap"

        url = self._fcgi_url + "?" + self.process_params(params)

        if browser:
            openInBrowserTab(url)
            return False, ""

        # try until qgis_mapserv.fcgi process is available (for 20 seconds)
        # on some platforms the fcgi_server_process is a daemon handling the
        # launch of the fcgi-spawner, which may be running quickly, but the
        # qgis_mapserv.fcgi spawned process is not yet accepting connections
        resp = None
        tmp_png = None
        # noinspection PyUnusedLocal
        filepath = ""
        # noinspection PyUnusedLocal
        success = False
        start_time = time.time()
        while time.time() - start_time < 20:
            resp = None
예제 #12
0
                params['MAP'] = w_proj
            else:
                msg += '\n  or\n' + w_proj
                raise ServerProcessError(
                    'GetMap Request Error',
                    'Project not found at:\n{0}'.format(msg)
                )

        if (('REQUEST' in params and params['REQUEST'] != 'GetMap') or
                'REQUEST' not in params):
            params['REQUEST'] = 'GetMap'

        url = self._fcgi_url + '?' + self.process_params(params)

        if browser:
            openInBrowserTab(url)
            return False, ''

        tmp = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
        success = True
        filepath = tmp.name
        # print 'filepath: ' + filepath
        tmp.close()
        filepath2, headers = urllib.urlretrieve(url, tmp.name)

        if (headers.getmaintype() != 'image' or
                headers.getheader('Content-Type') != 'image/png'):
            success = False
            if os.path.exists(filepath):
                os.unlink(filepath)
            filepath = ''
예제 #13
0
        # 'BBOX': QgsRectangle(606510, 4823130, 612510, 4827130)
        'BBOX': '606510,4823130,612510,4827130',
        'FORMAT': 'image/png',  # or: 'image/png; mode=8bit'
        'WIDTH': '600',
        'HEIGHT': '400',
        'DPI': '72',
        'MAP_RESOLUTION': '72',
        'FORMAT_OPTIONS': 'dpi:72',
        'TRANSPARENT': 'FALSE',
        'IgnoreGetMapUrl': '1'
    }

    # local_srv.web_server_process().start()
    # openInBrowserTab('http://127.0.0.1:8448')
    # local_srv.web_server_process().stop()
    # sys.exit()
    local_srv.startup(False)
    openInBrowserTab('http://127.0.0.1:8448')
    try:
        local_srv.check_server_capabilities()
        # open resultant png with system
        result, png, url = local_srv.get_map(req_params)
    finally:
        local_srv.shutdown()

    if result:
        # print png
        openInBrowserTab('file://' + png)
    else:
        raise ServerProcessError('GetMap Test', 'Failed to generate PNG')
예제 #14
0
    def get_map(self, params, browser=False):
        assert self.processes_running(), 'Server processes not running'

        msg = ('Map request parameters should be passed in as a dict '
               '(key case can be mixed)')
        assert isinstance(params, dict), msg

        params = self._params_to_upper(params)
        try:
            proj = params['MAP']
        except KeyError as err:
            raise KeyError(str(err) + '\nMAP not found in parameters dict')

        if not os.path.exists(proj):
            msg = '{0}'.format(proj)
            w_proj = os.path.join(self._web_dir, proj)
            if os.path.exists(w_proj):
                params['MAP'] = w_proj
            else:
                msg += '\n  or\n' + w_proj
                raise ServerProcessError(
                    'GetMap Request Error',
                    'Project not found at:\n{0}'.format(msg))

        if (('REQUEST' in params and params['REQUEST'] != 'GetMap')
                or 'REQUEST' not in params):
            params['REQUEST'] = 'GetMap'

        url = self._fcgi_url + '?' + self.process_params(params)

        if browser:
            openInBrowserTab(url)
            return False, ''

        # try until qgis_mapserv.fcgi process is available (for 20 seconds)
        # on some platforms the fcgi_server_process is a daemon handling the
        # launch of the fcgi-spawner, which may be running quickly, but the
        # qgis_mapserv.fcgi spawned process is not yet accepting connections
        resp = None
        tmp_png = None
        # noinspection PyUnusedLocal
        filepath = ''
        # noinspection PyUnusedLocal
        success = False
        start_time = time.time()
        while time.time() - start_time < 20:
            resp = None
            try:
                tmp_png = urllib.request.urlopen(url)
            except urllib.error.HTTPError as resp:
                if resp.code == 503 or resp.code == 500:
                    time.sleep(1)
                else:
                    raise ServerProcessError(
                        'Web/FCGI Process Request HTTPError',
                        'Could not connect to process: ' + str(resp.code),
                        resp.message)
            except urllib.error.URLError as resp:
                raise ServerProcessError('Web/FCGI Process Request URLError',
                                         'Could not connect to process',
                                         resp.reason)
            else:
                delta = time.time() - start_time
                print(('Seconds elapsed for server GetMap: ' + str(delta)))
                break

        if resp is not None:
            raise ServerProcessError(
                'Web/FCGI Process Request Error',
                'Could not connect to process: ' + str(resp.code))

        if (tmp_png is not None and tmp_png.info().getmaintype() == 'image'
                and tmp_png.info().getheader('Content-Type') == 'image/png'):

            filepath = getTempfilePath('png')
            with open(filepath, 'wb') as temp_image:
                temp_image.write(tmp_png.read())
            success = True
        else:
            raise ServerProcessError('FCGI Process Request Error',
                                     'No valid PNG output')

        return success, filepath, url
예제 #15
0
                params['MAP'] = w_proj
            else:
                msg += '\n  or\n' + w_proj
                raise ServerProcessError(
                    'GetMap Request Error',
                    'Project not found at:\n{0}'.format(msg)
                )

        if (('REQUEST' in params and params['REQUEST'] != 'GetMap') or
                'REQUEST' not in params):
            params['REQUEST'] = 'GetMap'

        url = self._fcgi_url + '?' + self.process_params(params)

        if browser:
            openInBrowserTab(url)
            return False, ''

        # try until qgis_mapserv.fcgi process is available (for 20 seconds)
        # on some platforms the fcgi_server_process is a daemon handling the
        # launch of the fcgi-spawner, which may be running quickly, but the
        # qgis_mapserv.fcgi spawned process is not yet accepting connections
        resp = None
        tmp_png = None
        # noinspection PyUnusedLocal
        filepath = ''
        # noinspection PyUnusedLocal
        success = False
        start_time = time.time()
        while time.time() - start_time < 20:
            resp = None
예제 #16
0
    def get_map(self, params, browser=False):
        assert self.processes_running(), "Server processes not running"

        msg = "Map request parameters should be passed in as a dict " "(key case can be mixed)"
        assert isinstance(params, dict), msg

        params = self._params_to_upper(params)
        try:
            proj = params["MAP"]
        except KeyError as err:
            raise KeyError(str(err) + "\nMAP not found in parameters dict")

        if not os.path.exists(proj):
            msg = "{0}".format(proj)
            w_proj = os.path.join(self._web_dir, proj)
            if os.path.exists(w_proj):
                params["MAP"] = w_proj
            else:
                msg += "\n  or\n" + w_proj
                raise ServerProcessError("GetMap Request Error", "Project not found at:\n{0}".format(msg))

        if ("REQUEST" in params and params["REQUEST"] != "GetMap") or "REQUEST" not in params:
            params["REQUEST"] = "GetMap"

        url = self._fcgi_url + "?" + self.process_params(params)

        if browser:
            openInBrowserTab(url)
            return False, ""

        # try until qgis_mapserv.fcgi process is available (for 20 seconds)
        # on some platforms the fcgi_server_process is a daemon handling the
        # launch of the fcgi-spawner, which may be running quickly, but the
        # qgis_mapserv.fcgi spawned process is not yet accepting connections
        resp = None
        tmp_png = None
        # noinspection PyUnusedLocal
        filepath = ""
        # noinspection PyUnusedLocal
        success = False
        start_time = time.time()
        while time.time() - start_time < 20:
            resp = None
            try:
                tmp_png = urllib.request.urlopen(url)
            except urllib.error.HTTPError as resp:
                if resp.code == 503 or resp.code == 500:
                    time.sleep(1)
                else:
                    raise ServerProcessError(
                        "Web/FCGI Process Request HTTPError",
                        "Cound not connect to process: " + str(resp.code),
                        resp.message,
                    )
            except urllib.error.URLError as resp:
                raise ServerProcessError(
                    "Web/FCGI Process Request URLError", "Cound not connect to process", resp.reason
                )
            else:
                delta = time.time() - start_time
                print(("Seconds elapsed for server GetMap: " + str(delta)))
                break

        if resp is not None:
            raise ServerProcessError(
                "Web/FCGI Process Request Error", "Cound not connect to process: " + str(resp.code)
            )

        if (
            tmp_png is not None
            and tmp_png.info().getmaintype() == "image"
            and tmp_png.info().getheader("Content-Type") == "image/png"
        ):

            filepath = getTempfilePath("png")
            with open(filepath, "wb") as temp_image:
                temp_image.write(tmp_png.read())
            success = True
        else:
            raise ServerProcessError("FCGI Process Request Error", "No valid PNG output")

        return success, filepath, url