def setUpClass(cls):
        """Run before all tests:
        Creates an auth configuration"""
        cls.port = QGIS_SERVER_ENDPOINT_PORT
        # Clean env just to be sure
        env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
        for ev in env_vars:
            try:
                del os.environ[ev]
            except KeyError:
                pass
        cls.testdata_path = unitTestDataPath('qgis_server')
        cls.certsdata_path = os.path.join(unitTestDataPath('auth_system'), 'certs_keys')
        cls.project_path = os.path.join(cls.testdata_path, "test_project.qgs")
        # cls.hostname = 'localhost'
        cls.protocol = 'https'
        cls.hostname = '127.0.0.1'

        cls.setUpAuth()

        server_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                   'qgis_wrapped_server.py')
        cls.server = subprocess.Popen([sys.executable, server_path],
                                      env=os.environ, stdout=subprocess.PIPE)
        line = cls.server.stdout.readline()
        cls.port = int(re.findall(b':(\d+)', line)[0])
        assert cls.port != 0
        # Wait for the server process to start
        assert waitServer('%s://%s:%s' % (cls.protocol, cls.hostname, cls.port)), "Server is not responding! %s://%s:%s" % (cls.protocol, cls.hostname, cls.port)
Example #2
0
 def setUpClass(cls):
     """Run before all tests"""
     cls.port = QGIS_SERVER_WFST_PORT
     # Create tmp folder
     cls.temp_path = tempfile.mkdtemp()
     cls.testdata_path = cls.temp_path + '/' + 'wfs_transactional' + '/'
     copytree(unitTestDataPath('wfs_transactional') + '/',
              cls.temp_path + '/' + 'wfs_transactional')
     cls.project_path = cls.temp_path + '/' + 'wfs_transactional' + '/' + \
         'wfs_transactional.qgs'
     assert os.path.exists(cls.project_path), "Project not found: %s" % \
         cls.project_path
     # Clean env just to be sure
     env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
     for ev in env_vars:
         try:
             del os.environ[ev]
         except KeyError:
             pass
     # Clear all test layers
     for ln in ['test_point', 'test_polygon', 'test_linestring']:
         cls._clearLayer(ln)
     os.environ['QGIS_SERVER_PORT'] = str(cls.port)
     server_path = os.path.dirname(os.path.realpath(__file__)) + \
         '/qgis_wrapped_server.py'
     cls.server = subprocess.Popen([sys.executable, server_path],
                                   env=os.environ, stdout=subprocess.PIPE)
     line = cls.server.stdout.readline()
     cls.port = int(re.findall(b':(\d+)', line)[0])
     assert cls.port != 0
     # Wait for the server process to start
     assert waitServer('http://127.0.0.1:%s' % cls.port), "Server is not responding!"
Example #3
0
 def setUp(self):
     """Run before each test."""
     self.server = subprocess.Popen([sys.executable, self.server_path], env=os.environ, stdout=subprocess.PIPE)
     line = self.server.stdout.readline()
     self.port = int(re.findall(b":(\d+)", line)[0])
     assert self.port != 0
     # Wait for the server process to start
     assert waitServer("http://127.0.0.1:%s" % self.port), "Server is not responding!"
     self._setUp()
 def setUp(self):
     """Run before each test."""
     self.server = subprocess.Popen([sys.executable, self.server_path],
                                    env=os.environ, stdout=subprocess.PIPE)
     line = self.server.stdout.readline()
     self.port = int(re.findall(b':(\d+)', line)[0])
     assert self.port != 0
     # Wait for the server process to start
     assert waitServer('http://127.0.0.1:%s' % self.port), "Server is not responding!"
     self._setUp()
Example #5
0
    def setUpClass(cls):
        """Run before all tests:
        Creates an auth configuration"""
        cls.port = QGIS_SERVER_ENDPOINT_PORT
        # Clean env just to be sure
        env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
        for ev in env_vars:
            try:
                del os.environ[ev]
            except KeyError:
                pass
        cls.testdata_path = unitTestDataPath('qgis_server')
        cls.certsdata_path = os.path.join(unitTestDataPath('auth_system'),
                                          'certs_keys')
        cls.project_path = os.path.join(cls.testdata_path, "test_project.qgs")
        # cls.hostname = 'localhost'
        cls.protocol = 'https'
        cls.hostname = '127.0.0.1'
        cls.username = '******'
        cls.password = '******'
        cls.setUpAuth()

        server_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                   'qgis_wrapped_server.py')
        cls.server = subprocess.Popen([sys.executable, server_path],
                                      env=os.environ,
                                      stdout=subprocess.PIPE)
        line = cls.server.stdout.readline()
        cls.port = int(re.findall(br':(\d+)', line)[0])
        assert cls.port != 0

        # We need a valid port before we setup the oauth configuration
        cls.token_uri = '%s://%s:%s/token' % (cls.protocol, cls.hostname,
                                              cls.port)
        cls.refresh_token_uri = '%s://%s:%s/refresh' % (cls.protocol,
                                                        cls.hostname, cls.port)
        # Need a random authcfg or the cache will bites us back!
        cls.authcfg_id = setup_oauth(cls.username, cls.password, cls.token_uri,
                                     cls.refresh_token_uri,
                                     str(random.randint(0, 10000000)))
        # This is to test wrong credentials
        cls.wrong_authcfg_id = setup_oauth('wrong', 'wrong', cls.token_uri,
                                           cls.refresh_token_uri,
                                           str(random.randint(0, 10000000)))
        # Get the authentication configuration instance:
        cls.auth_config = QgsApplication.authManager(
        ).availableAuthMethodConfigs()[cls.authcfg_id]
        assert cls.auth_config.isValid()

        # Wait for the server process to start
        assert waitServer(
            '%s://%s:%s' % (cls.protocol, cls.hostname, cls.port)
        ), "Server is not responding! %s://%s:%s" % (cls.protocol,
                                                     cls.hostname, cls.port)
    def setUpClass(cls):
        """Run before all tests:
        Creates an auth configuration"""
        cls.port = QGIS_SERVER_ENDPOINT_PORT
        # Clean env just to be sure
        env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
        for ev in env_vars:
            try:
                del os.environ[ev]
            except KeyError:
                pass
        cls.testdata_path = unitTestDataPath('qgis_server') + '/'
        cls.project_path = cls.testdata_path + "test_project.qgs"
        # Enable auth
        # os.environ['QGIS_AUTH_PASSWORD_FILE'] = QGIS_AUTH_PASSWORD_FILE
        authm = QgsApplication.authManager()
        assert (authm.setMasterPassword('masterpassword', True))
        cls.auth_config = QgsAuthMethodConfig('Basic')
        cls.auth_config.setName('test_auth_config')
        cls.username = ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for _ in range(6))
        cls.password = cls.username[::-1]  # reversed
        cls.auth_config.setConfig('username', cls.username)
        cls.auth_config.setConfig('password', cls.password)
        assert (authm.storeAuthenticationConfig(cls.auth_config)[0])
        cls.hostname = '127.0.0.1'
        cls.protocol = 'http'

        os.environ['QGIS_SERVER_HTTP_BASIC_AUTH'] = '1'
        os.environ['QGIS_SERVER_USERNAME'] = cls.username
        os.environ['QGIS_SERVER_PASSWORD'] = cls.password
        os.environ['QGIS_SERVER_PORT'] = str(cls.port)
        os.environ['QGIS_SERVER_HOST'] = cls.hostname

        server_path = os.path.dirname(os.path.realpath(__file__)) + \
            '/qgis_wrapped_server.py'
        cls.server = subprocess.Popen([sys.executable, server_path],
                                      env=os.environ,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE)

        line = cls.server.stdout.readline()
        cls.port = int(re.findall(b':(\d+)', line)[0])
        assert cls.port != 0
        # Wait for the server process to start
        assert waitServer(
            '%s://%s:%s' % (cls.protocol, cls.hostname, cls.port)
        ), "Server is not responding! %s://%s:%s" % (cls.protocol,
                                                     cls.hostname, cls.port)
    def setUpClass(cls):
        """Run before all tests:
        Creates an auth configuration"""
        cls.port = QGIS_SERVER_ENDPOINT_PORT
        # Clean env just to be sure
        env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
        for ev in env_vars:
            try:
                del os.environ[ev]
            except KeyError:
                pass
        cls.testdata_path = unitTestDataPath('qgis_server') + '/'
        cls.project_path = cls.testdata_path + "test_project.qgs"
        # Enable auth
        #os.environ['QGIS_AUTH_PASSWORD_FILE'] = QGIS_AUTH_PASSWORD_FILE
        authm = QgsAuthManager.instance()
        assert (authm.setMasterPassword('masterpassword', True))
        cls.auth_config = QgsAuthMethodConfig('Basic')
        cls.auth_config.setName('test_auth_config')
        cls.username = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
        cls.password = cls.username[::-1] # reversed
        cls.auth_config.setConfig('username', cls.username)
        cls.auth_config.setConfig('password', cls.password)
        assert (authm.storeAuthenticationConfig(cls.auth_config)[0])
        cls.hostname = '127.0.0.1'
        cls.protocol = 'http'

        os.environ['QGIS_SERVER_HTTP_BASIC_AUTH'] = '1'
        os.environ['QGIS_SERVER_USERNAME'] = cls.username
        os.environ['QGIS_SERVER_PASSWORD'] = cls.password
        os.environ['QGIS_SERVER_PORT'] = str(cls.port)
        os.environ['QGIS_SERVER_HOST'] = cls.hostname

        server_path = os.path.dirname(os.path.realpath(__file__)) + \
            '/qgis_wrapped_server.py'
        cls.server = subprocess.Popen([sys.executable, server_path],
                                      env=os.environ, stdout=subprocess.PIPE)

        line = cls.server.stdout.readline()
        cls.port = int(re.findall(b':(\d+)', line)[0])
        assert cls.port != 0
        # Wait for the server process to start
        assert waitServer('%s://%s:%s' % (cls.protocol, cls.hostname, cls.port)), "Server is not responding! %s://%s:%s" % (cls.protocol, cls.hostname, cls.port)
    def setUpClass(cls):
        """Run before all tests:
        Creates an auth configuration"""
        cls.port = QGIS_SERVER_ENDPOINT_PORT
        # Clean env just to be sure
        env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
        for ev in env_vars:
            try:
                del os.environ[ev]
            except KeyError:
                pass
        cls.testdata_path = unitTestDataPath('qgis_server')
        cls.certsdata_path = os.path.join(unitTestDataPath('auth_system'), 'certs_keys')
        cls.project_path = os.path.join(cls.testdata_path, "test_project.qgs")
        # cls.hostname = 'localhost'
        cls.protocol = 'https'
        cls.hostname = '127.0.0.1'
        cls.username = '******'
        cls.password = '******'
        cls.setUpAuth()

        server_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                   'qgis_wrapped_server.py')
        cls.server = subprocess.Popen([sys.executable, server_path],
                                      env=os.environ, stdout=subprocess.PIPE)
        line = cls.server.stdout.readline()
        cls.port = int(re.findall(b':(\d+)', line)[0])
        assert cls.port != 0

        # We need a valid port before we setup the oauth configuration
        cls.token_uri = '%s://%s:%s/token' % (cls.protocol, cls.hostname, cls.port)
        cls.refresh_token_uri = '%s://%s:%s/refresh' % (cls.protocol, cls.hostname, cls.port)
        # Need a random authcfg or the cache will bites us back!
        cls.authcfg_id = setup_oauth(cls.username, cls.password, cls.token_uri, cls.refresh_token_uri, str(random.randint(0, 10000000)))
        # This is to test wrong credentials
        cls.wrong_authcfg_id = setup_oauth('wrong', 'wrong', cls.token_uri, cls.refresh_token_uri, str(random.randint(0, 10000000)))
        # Get the authentication configuration instance:
        cls.auth_config = QgsApplication.authManager().availableAuthMethodConfigs()[cls.authcfg_id]
        assert cls.auth_config.isValid()

        # Wait for the server process to start
        assert waitServer('%s://%s:%s' % (cls.protocol, cls.hostname, cls.port)), "Server is not responding! %s://%s:%s" % (cls.protocol, cls.hostname, cls.port)
Example #9
0
    def setUpClass(cls):
        # setup network timeout
        cls.settings = QSettings()
        cls.settings.setValue(cls.timeoutEntry, 60000)

        if USE_ONLINE_HTTPBIN:
            cls.serverUrl = 'https://httpbin.org'
            return

        # start httpbin server locally
        cls.server = subprocess.Popen(['gunicorn', 'httpbin:app'],
                                      env=os.environ,
                                      stdout=subprocess.PIPE)
        cls.port = 8000
        cls.hostname = '127.0.0.1'
        cls.protocol = 'http'
        cls.serverUrl = '{0}://{1}:{2}'.format(cls.protocol, cls.hostname,
                                               cls.port)
        # Wait for the server process to start
        assert waitServer(cls.serverUrl,
                          timeout=2), "Server is not responding! {}".format(
                              cls.serverUrl)