def test_generate_configuration_override_defaults_generic(self): ssl = False config = Configuration(self.generic_host, self.port, ssl=ssl) c = generate_config(config.host, config.port, ssl=config.ssl) c.write_to_file(self.test_file_path) config_from_file = get_config(self.test_file_path) self.assertEqual(config.to_dict(), config_from_file.to_dict())
def test_generate_configuration_with_defaults_neptune(self): config = Configuration(self.neptune_host, self.port) c = generate_config(config.host, config.port, auth_mode=config.auth_mode, ssl=config.ssl, load_from_s3_arn=config.load_from_s3_arn, aws_region=config.aws_region) c.write_to_file(self.test_file_path) config_from_file = get_config(self.test_file_path) self.assertEqual(config.to_dict(), config_from_file.to_dict())
def generate_config_from_main_and_test(self, source_config: Configuration): # This will run the main method that our install script runs on a Sagemaker notebook. # The return code should be 0, but more importantly, we need to assert that the # Configuration object we get from the resulting file is what we expect. result = os.system(f'{self.python_cmd} -m graph_notebook.configuration.generate_config --host "{source_config.host}" --port "{source_config.port}" --auth_mode "{source_config.auth_mode.value}" --ssl "{source_config.ssl}" --iam_credentials_provider "{source_config.iam_credentials_provider_type.value}" --load_from_s3_arn "{source_config.load_from_s3_arn}" --config_destination="{self.test_file_path}" ') self.assertEqual(result, 0) config = get_config(self.test_file_path) self.assertEqual(source_config.to_dict(), config.to_dict())
def test_generate_configuration_with_defaults(self): config = Configuration(self.host, self.port) c = generate_config(config.host, config.port, config.auth_mode, config.ssl, config.iam_credentials_provider_type, config.load_from_s3_arn, config.aws_region) c.write_to_file(self.test_file_path) config_from_file = get_config(self.test_file_path) self.assertEqual(config.to_dict(), config_from_file.to_dict())
def test_generate_configuration_main_empty_args(self): expected_config = Configuration(self.host, self.port) result = os.system( f'{self.python_cmd} -m graph_notebook.configuration.generate_config --host "{expected_config.host}" --port "{expected_config.port}" --auth_mode "" --ssl "" --iam_credentials_provider "" --load_from_s3_arn "" --config_destination="{self.test_file_path}" ' ) self.assertEqual(0, result) config = get_config(self.test_file_path) self.assert_configs_are_equal(expected_config, config)
def setUpClass(cls): config = get_config(TEST_CONFIG_PATH) cls.host = config.host cls.port = config.port cls.auth_mode = config.auth_mode cls.ssl = config.ssl cls.iam_credentials_provider_type = config.iam_credentials_provider_type cls.load_from_s3_arn = config.load_from_s3_arn
def test_generate_configuration_main_empty_args_generic(self): expected_config = Configuration(self.generic_host, self.port) result = os.system( f'{self.python_cmd} -m graph_notebook.configuration.generate_config ' f'--host "{expected_config.host}" --port "{expected_config.port}" --ssl "" ' f'--config_destination="{self.test_file_path}" ') self.assertEqual(0, result) config = get_config(self.test_file_path) self.assertEqual(expected_config.to_dict(), config.to_dict())
def graph_notebook_config(self, line='', cell=''): if cell != '': data = json.loads(cell) config = get_config_from_dict(data) self.graph_notebook_config = config elif line == 'reset': self.graph_notebook_config = get_config() print('reset notebook config to:') print(json.dumps(self.graph_notebook_config.to_dict(), indent=2)) else: config_dict = self.graph_notebook_config.to_dict() return print(json.dumps(config_dict, indent=2))
def test_generate_configuration_override_defaults_neptune(self): auth_mode = AuthModeEnum.IAM ssl = False loader_arn = 'foo' aws_region = 'us-west-2' config = Configuration(self.neptune_host, self.port, auth_mode=auth_mode, load_from_s3_arn=loader_arn, ssl=ssl, aws_region=aws_region) c = generate_config(config.host, config.port, auth_mode=config.auth_mode, ssl=config.ssl, load_from_s3_arn=config.load_from_s3_arn, aws_region=config.aws_region) c.write_to_file(self.test_file_path) config_from_file = get_config(self.test_file_path) self.assertEqual(config.to_dict(), config_from_file.to_dict())
def __init__(self, shell): # You must call the parent constructor super(Graph, self).__init__(shell) try: self.config_location = os.getenv('GRAPH_NOTEBOOK_CONFIG', DEFAULT_CONFIG_LOCATION) self.graph_notebook_config = get_config(self.config_location) except FileNotFoundError: self.graph_notebook_config = generate_default_config() print( 'Could not find a valid configuration. Do not forgot to validate your settings using %graph_notebook_config') self.max_results = DEFAULT_MAX_RESULTS self.graph_notebook_vis_options = OPTIONS_DEFAULT_DIRECTED logger.setLevel(logging.ERROR)
def test_generate_configuration_override_defaults(self): auth_mode = AuthModeEnum.IAM credentials_provider = IAMAuthCredentialsProvider.ENV ssl = False loader_arn = 'foo' aws_region = 'us-west-2' config = Configuration(self.host, self.port, auth_mode, credentials_provider, loader_arn, ssl, aws_region) c = generate_config(config.host, config.port, config.auth_mode, config.ssl, config.iam_credentials_provider_type, config.load_from_s3_arn, config.aws_region) c.write_to_file(self.test_file_path) config_from_file = get_config(self.test_file_path) self.assertEqual(config.to_dict(), config_from_file.to_dict())
def __init__(self, shell): # You must call the parent constructor super(Graph, self).__init__(shell) try: self.graph_notebook_config = get_config() except FileNotFoundError: self.graph_notebook_config = generate_default_config() print( 'Could not find a valid configuration. Do not forgot to validate your settings using %graph_notebook_config' ) self.max_results = DEFAULT_MAX_RESULTS self.mode = QueryMode.DEFAULT self.graph_notebook_vis_options = OPTIONS_DEFAULT_DIRECTED logger.setLevel(logging.ERROR)
def graph_notebook_config(self, line='', cell=''): if cell != '': data = json.loads(cell) config = get_config_from_dict(data) print('set notebook config to:') print(json.dumps(self.graph_notebook_config.to_dict(), indent=2)) self.graph_notebook_config = config elif line == 'reset': self.graph_notebook_config = get_config(self.config_location) print('reset notebook config to:') print(json.dumps(self.graph_notebook_config.to_dict(), indent=2)) elif line == 'silent': """ silent option to that our neptune_menu extension can receive json instead of python Configuration object """ config_dict = self.graph_notebook_config.to_dict() return print(json.dumps(config_dict, indent=2)) else: config_dict = self.graph_notebook_config.to_dict() print(json.dumps(config_dict, indent=2)) return self.graph_notebook_config
def setup_module(): global client client = setup_iam_client(get_config())
def setUpClass(cls): super().setUpClass() cls.config = get_config(TEST_CONFIG_PATH) cls.client_builder = setup_client_builder(cls.config)