def __init__(self, protocol, host, port, product, endpoint, auto_handle_connection=True, session_token=None): # Import only if necessary; some tests may not add this to PYTHONPATH. from codeCheckerDBAccess_v6 import codeCheckerDBAccess from codeCheckerDBAccess_v6.constants import MAX_QUERY_SIZE from codechecker_client.credential_manager import SESSION_COOKIE_NAME self.max_query_size = MAX_QUERY_SIZE url = util.create_product_url( protocol, host, port, '/' + product + '/v' + VERSION + endpoint) print("Setup viewer client: " + url) transport = THttpClient.THttpClient(url) protocol = TJSONProtocol.TJSONProtocol(transport) client = codeCheckerDBAccess.Client(protocol) if session_token: headers = {'Cookie': SESSION_COOKIE_NAME + '=' + session_token} transport.setCustomHeaders(headers) super(CCViewerHelper, self).__init__(transport, client, auto_handle_connection)
def add_test_package_product(server_data, test_folder, check_env=None, protocol='http'): """ Add a product for a test suite to the server provided by server_data. Server must be running before called. server_data must contain three keys: viewer_{host, port, product}. """ if not check_env: check_env = env.test_env(test_folder) codechecker_cfg = {'check_env': check_env} codechecker_cfg.update(server_data) # Clean the previous session if any exists. logout(codechecker_cfg, test_folder, protocol) url = util.create_product_url(protocol, server_data['viewer_host'], str(server_data['viewer_port']), '') add_command = ['CodeChecker', 'cmd', 'products', 'add', server_data['viewer_product'], '--url', url, '--name', os.path.basename(test_folder), '--description', "Automatically created product for test."] # If tests are running on postgres, we need to create a database. pg_config = env.get_postgresql_cfg() if pg_config: env.add_database(server_data['viewer_product'], check_env) add_command.append('--postgresql') pg_config['dbname'] = server_data['viewer_product'] add_command += _pg_db_config_to_cmdline_params(pg_config) else: # SQLite databases are put under the workspace of the appropriate test. add_command += ['--sqlite', os.path.join(test_folder, 'data.sqlite')] print(' '.join(add_command)) # Authenticate as SUPERUSER to be able to create the product. login(codechecker_cfg, test_folder, "root", "root", protocol) # The schema creation is a synchronous call. returncode = subprocess.call(add_command, env=check_env) logout(codechecker_cfg, test_folder, protocol) # After login as SUPERUSER, continue running the test as a normal user. # login() saves the relevant administrative file login(codechecker_cfg, test_folder, "cc", "test", protocol) if returncode: raise Exception("Failed to add the product to the test server!")
def __init__(self, protocol, host, port, uri, session_token=None): self.__host = host self.__port = port url = util.create_product_url(protocol, host, port, uri) self.transport = THttpClient.THttpClient(url) self.protocol = TJSONProtocol.TJSONProtocol(self.transport) self.client = codeCheckerDBAccess.Client(self.protocol) if session_token: headers = {'Cookie': SESSION_COOKIE_NAME + '=' + session_token} self.transport.setCustomHeaders(headers)
def __init__(self, protocol, host, port, uri, session_token=None): self.__host = host self.__port = port url = util.create_product_url(protocol, host, port, uri) self.transport = THttpClient.THttpClient(url) self.protocol = TJSONProtocol.TJSONProtocol(self.transport) self.client = codeCheckerProductService.Client(self.protocol) if session_token: headers = {'Cookie': SESSION_COOKIE_NAME + '=' + session_token} self.transport.setCustomHeaders(headers)
def __init__(self, proto, host, port, uri, auto_handle_connection=True, session_token=None): # Import only if necessary; some tests may not add this to PYTHONPATH. from Authentication_v6 import codeCheckerAuthentication from codechecker_client.credential_manager import SESSION_COOKIE_NAME url = util.create_product_url(proto, host, port, '/v' + VERSION + uri) transport = THttpClient.THttpClient(url) protocol = TJSONProtocol.TJSONProtocol(transport) client = codeCheckerAuthentication.Client(protocol) if session_token: headers = {'Cookie': SESSION_COOKIE_NAME + '=' + session_token} transport.setCustomHeaders(headers) super(CCAuthHelper, self).__init__(transport, client, auto_handle_connection)
def __init__(self, proto, host, port, uri, auto_handle_connection=True, session_token=None): from Configuration_v6 import configurationService from codechecker_client.credential_manager import SESSION_COOKIE_NAME full_uri = '/v' + VERSION + uri url = util.create_product_url(proto, host, port, full_uri) transport = THttpClient.THttpClient(url) protocol = TJSONProtocol.TJSONProtocol(transport) client = configurationService.Client(protocol) if session_token: headers = {'Cookie': SESSION_COOKIE_NAME + '=' + session_token} transport.setCustomHeaders(headers) super(CCConfigHelper, self).__init__(transport, client, auto_handle_connection)
def __init__(self, protocol, host, port, product, endpoint, auto_handle_connection=True, session_token=None): # Import only if necessary; some tests may not add this to PYTHONPATH. from codeCheckerDBAccess_v6 import codeCheckerDBAccess from codeCheckerDBAccess_v6.constants import MAX_QUERY_SIZE from codechecker_client.credential_manager import SESSION_COOKIE_NAME self.max_query_size = MAX_QUERY_SIZE url = util.create_product_url(protocol, host, port, '/' + product + '/v' + VERSION + endpoint) print("Setup viewer client: "+url) transport = THttpClient.THttpClient(url) protocol = TJSONProtocol.TJSONProtocol(transport) client = codeCheckerDBAccess.Client(protocol) if session_token: headers = {'Cookie': SESSION_COOKIE_NAME + '=' + session_token} transport.setCustomHeaders(headers) super(CCViewerHelper, self).__init__(transport, client, auto_handle_connection)
def remove_test_package_product(test_folder, check_env=None, protocol='http'): """ Remove the product associated with the given test folder. The folder must exist, as the server configuration is read from the folder. """ if not check_env: check_env = env.test_env(test_folder) server_data = env.import_test_cfg(test_folder)['codechecker_cfg'] print(server_data) if 'check_env' not in server_data: server_data['check_env'] = check_env # Clean the previous session if any exists. logout(server_data, test_folder, protocol) url = util.create_product_url(protocol, server_data['viewer_host'], str(server_data['viewer_port']), '') del_command = ['CodeChecker', 'cmd', 'products', 'del', server_data['viewer_product'], '--url', url] print(' '.join(del_command)) # Authenticate as SUPERUSER to be able to create the product. login(server_data, test_folder, "root", "root", protocol) returncode = subprocess.call(del_command, env=check_env) logout(server_data, test_folder, protocol) # If tests are running on postgres, we need to delete the database. # SQLite databases are deleted automatically as part of the # workspace removal. if env.get_postgresql_cfg(): env.del_database(server_data['viewer_product'], check_env) if returncode: raise Exception("Failed to remove the product from the test server!")