|
6 | 6 | import os |
7 | 7 | import unittest |
8 | 8 |
|
9 | | -from graph_notebook.configuration.get_config import get_config |
| 9 | +from graph_notebook.configuration.get_config import get_config, get_config_from_dict |
10 | 10 | from graph_notebook.configuration.generate_config import Configuration, DEFAULT_AUTH_MODE, AuthModeEnum, \ |
11 | 11 | generate_config, generate_default_config, GremlinSection |
12 | 12 | from graph_notebook.neptune.client import NEPTUNE_DB_SERVICE_NAME, NEPTUNE_ANALYTICS_SERVICE_NAME, \ |
13 | | - DEFAULT_GREMLIN_PROTOCOL, DEFAULT_HTTP_PROTOCOL |
| 13 | + DEFAULT_GREMLIN_PROTOCOL, DEFAULT_HTTP_PROTOCOL, NEPTUNE_CONFIG_HOST_IDENTIFIERS |
14 | 14 |
|
15 | 15 |
|
16 | 16 | class TestGenerateConfiguration(unittest.TestCase): |
@@ -121,6 +121,227 @@ def test_configuration_override_defaults_generic(self): |
121 | 121 | config = Configuration(self.generic_host, self.port, ssl=ssl) |
122 | 122 | self.assertEqual(ssl, config.ssl) |
123 | 123 |
|
| 124 | + def test_get_configuration_empty_input(self): |
| 125 | + input_config = {} |
| 126 | + with self.assertRaises(KeyError): |
| 127 | + get_config_from_dict(input_config, neptune_hosts=NEPTUNE_CONFIG_HOST_IDENTIFIERS) |
| 128 | + |
| 129 | + def test_get_configuration_no_host(self): |
| 130 | + input_config = { |
| 131 | + "port": 8182, |
| 132 | + "ssl": True |
| 133 | + } |
| 134 | + with self.assertRaises(KeyError): |
| 135 | + get_config_from_dict(input_config, neptune_hosts=NEPTUNE_CONFIG_HOST_IDENTIFIERS) |
| 136 | + |
| 137 | + def test_get_configuration_generic_no_port(self): |
| 138 | + input_config = { |
| 139 | + "host": "localhost", |
| 140 | + "ssl": True |
| 141 | + } |
| 142 | + with self.assertRaises(KeyError): |
| 143 | + get_config_from_dict(input_config, neptune_hosts=NEPTUNE_CONFIG_HOST_IDENTIFIERS) |
| 144 | + |
| 145 | + def test_get_configuration_generic_no_ssl(self): |
| 146 | + input_config = { |
| 147 | + "host": "localhost", |
| 148 | + "port": 8182 |
| 149 | + } |
| 150 | + with self.assertRaises(KeyError): |
| 151 | + get_config_from_dict(input_config, neptune_hosts=NEPTUNE_CONFIG_HOST_IDENTIFIERS) |
| 152 | + |
| 153 | + def test_get_configuration_generic_required_input(self): |
| 154 | + input_config = { |
| 155 | + "host": "localhost", |
| 156 | + "port": 8182, |
| 157 | + "ssl": True |
| 158 | + } |
| 159 | + expected_config = { |
| 160 | + 'host': 'localhost', |
| 161 | + 'port': 8182, |
| 162 | + 'proxy_host': '', |
| 163 | + 'proxy_port': 8182, |
| 164 | + 'ssl': True, |
| 165 | + 'ssl_verify': True, |
| 166 | + 'sparql': { |
| 167 | + 'path': '' |
| 168 | + }, |
| 169 | + 'gremlin': { |
| 170 | + 'traversal_source': 'g', |
| 171 | + 'username': '', |
| 172 | + 'password': '', |
| 173 | + 'message_serializer': 'graphsonv3' |
| 174 | + }, |
| 175 | + 'neo4j': { |
| 176 | + 'username': 'neo4j', |
| 177 | + 'password': 'password', |
| 178 | + 'auth': True, |
| 179 | + 'database': None |
| 180 | + } |
| 181 | + } |
| 182 | + config = get_config_from_dict(input_config, neptune_hosts=NEPTUNE_CONFIG_HOST_IDENTIFIERS) |
| 183 | + self.assertEqual(config.to_dict(), expected_config) |
| 184 | + |
| 185 | + def test_get_configuration_generic_all_input(self): |
| 186 | + input_and_expected_config = { |
| 187 | + 'host': 'a_host', |
| 188 | + 'port': 9999, |
| 189 | + 'proxy_host': 'a_proxy_host', |
| 190 | + 'proxy_port': 9999, |
| 191 | + 'ssl': False, |
| 192 | + 'ssl_verify': False, |
| 193 | + 'sparql': { |
| 194 | + 'path': 'a_path' |
| 195 | + }, |
| 196 | + 'gremlin': { |
| 197 | + 'traversal_source': 'a', |
| 198 | + 'username': 'user', |
| 199 | + 'password': 'pass', |
| 200 | + 'message_serializer': 'graphbinaryv1' |
| 201 | + }, |
| 202 | + 'neo4j': { |
| 203 | + 'username': 'neo_user', |
| 204 | + 'password': 'neo_pass', |
| 205 | + 'auth': False, |
| 206 | + 'database': 'neo_db' |
| 207 | + } |
| 208 | + } |
| 209 | + config = get_config_from_dict(input_and_expected_config, neptune_hosts=NEPTUNE_CONFIG_HOST_IDENTIFIERS) |
| 210 | + self.assertEqual(config.to_dict(), input_and_expected_config) |
| 211 | + |
| 212 | + def test_get_configuration_neptune_no_auth_mode(self): |
| 213 | + input_config = { |
| 214 | + "host": "db.cluster-xxxxxxxxx.us-west-2.neptune.amazonaws.com", |
| 215 | + "port": 8182, |
| 216 | + "ssl": True, |
| 217 | + "load_from_s3_arn": "", |
| 218 | + "aws_region": "us-west-2" |
| 219 | + } |
| 220 | + with self.assertRaises(KeyError): |
| 221 | + get_config_from_dict(input_config, neptune_hosts=NEPTUNE_CONFIG_HOST_IDENTIFIERS) |
| 222 | + |
| 223 | + def test_get_configuration_neptune_no_load_arn(self): |
| 224 | + input_config = { |
| 225 | + "host": "db.cluster-xxxxxxxxx.us-west-2.neptune.amazonaws.com", |
| 226 | + "port": 8182, |
| 227 | + "ssl": True, |
| 228 | + "aws_region": "us-west-2" |
| 229 | + } |
| 230 | + with self.assertRaises(KeyError): |
| 231 | + get_config_from_dict(input_config, neptune_hosts=NEPTUNE_CONFIG_HOST_IDENTIFIERS) |
| 232 | + |
| 233 | + def test_get_configuration_neptune_no_region(self): |
| 234 | + input_config = { |
| 235 | + "host": "db.cluster-xxxxxxxxx.us-west-2.neptune.amazonaws.com", |
| 236 | + "port": 8182, |
| 237 | + "ssl": True, |
| 238 | + "load_from_s3_arn": "" |
| 239 | + } |
| 240 | + with self.assertRaises(KeyError): |
| 241 | + get_config_from_dict(input_config, neptune_hosts=NEPTUNE_CONFIG_HOST_IDENTIFIERS) |
| 242 | + |
| 243 | + def test_get_configuration_neptune_required_input(self): |
| 244 | + input_config = { |
| 245 | + "host": "db.cluster-xxxxxxxxx.us-west-2.neptune.amazonaws.com", |
| 246 | + "port": 8182, |
| 247 | + "auth_mode": "IAM", |
| 248 | + "load_from_s3_arn": "", |
| 249 | + "ssl": True, |
| 250 | + "aws_region": "us-west-2" |
| 251 | + } |
| 252 | + expected_config = { |
| 253 | + 'host': 'db.cluster-xxxxxxxxx.us-west-2.neptune.amazonaws.com', |
| 254 | + 'neptune_service': 'neptune-db', |
| 255 | + 'port': 8182, |
| 256 | + 'proxy_host': '', |
| 257 | + 'proxy_port': 8182, |
| 258 | + 'auth_mode': 'IAM', |
| 259 | + 'load_from_s3_arn': '', |
| 260 | + 'ssl': True, |
| 261 | + 'ssl_verify': True, |
| 262 | + 'aws_region': 'us-west-2', |
| 263 | + 'sparql': { |
| 264 | + 'path': '' |
| 265 | + }, |
| 266 | + 'gremlin': { |
| 267 | + 'traversal_source': 'g', |
| 268 | + 'username': '', |
| 269 | + 'password': '', |
| 270 | + 'message_serializer': 'graphsonv3', |
| 271 | + 'connection_protocol': 'websockets' |
| 272 | + }, |
| 273 | + 'neo4j': { |
| 274 | + 'username': 'neo4j', |
| 275 | + 'password': 'password', |
| 276 | + 'auth': True, |
| 277 | + 'database': None |
| 278 | + } |
| 279 | + } |
| 280 | + |
| 281 | + config = get_config_from_dict(input_config, neptune_hosts=NEPTUNE_CONFIG_HOST_IDENTIFIERS) |
| 282 | + self.assertEqual(config.to_dict(), expected_config) |
| 283 | + |
| 284 | + def test_get_configuration_neptune_all_input(self): |
| 285 | + input_config = { |
| 286 | + 'host': 'db.cluster-xxxxxxxxx.us-west-2.neptune.amazonaws.com', |
| 287 | + 'neptune_service': 'neptune-graph', |
| 288 | + 'port': 9999, |
| 289 | + 'proxy_host': 'a_proxy+port', |
| 290 | + 'proxy_port': 9999, |
| 291 | + 'auth_mode': 'DEFAULT', |
| 292 | + 'load_from_s3_arn': 'a_role', |
| 293 | + 'ssl': False, |
| 294 | + 'ssl_verify': False, |
| 295 | + 'aws_region': 'us-west-2', |
| 296 | + 'sparql': { |
| 297 | + 'path': 'a_path' |
| 298 | + }, |
| 299 | + 'gremlin': { |
| 300 | + 'traversal_source': 'a', |
| 301 | + 'username': 'a_user', |
| 302 | + 'password': 'a_pass', |
| 303 | + 'message_serializer': 'graphbinaryv1', |
| 304 | + 'connection_protocol': 'http' |
| 305 | + }, |
| 306 | + 'neo4j': { |
| 307 | + 'username': 'a_user', |
| 308 | + 'password': 'a_pass', |
| 309 | + 'auth': False, |
| 310 | + 'database': 'a_db' |
| 311 | + } |
| 312 | + } |
| 313 | + expected_config = { |
| 314 | + 'host': 'db.cluster-xxxxxxxxx.us-west-2.neptune.amazonaws.com', |
| 315 | + 'neptune_service': 'neptune-graph', |
| 316 | + 'port': 9999, |
| 317 | + 'proxy_host': 'a_proxy+port', |
| 318 | + 'proxy_port': 9999, |
| 319 | + 'auth_mode': 'DEFAULT', |
| 320 | + 'load_from_s3_arn': 'a_role', |
| 321 | + 'ssl': False, |
| 322 | + 'ssl_verify': False, |
| 323 | + 'aws_region': 'us-west-2', |
| 324 | + 'sparql': { |
| 325 | + 'path': 'a_path' |
| 326 | + }, |
| 327 | + 'gremlin': { |
| 328 | + 'traversal_source': 'g', |
| 329 | + 'username': '', |
| 330 | + 'password': '', |
| 331 | + 'message_serializer': 'graphbinaryv1', |
| 332 | + 'connection_protocol': 'http' |
| 333 | + }, |
| 334 | + 'neo4j': { |
| 335 | + 'username': 'neo4j', |
| 336 | + 'password': 'password', |
| 337 | + 'auth': True, |
| 338 | + 'database': None |
| 339 | + } |
| 340 | + } |
| 341 | + |
| 342 | + config = get_config_from_dict(input_config, neptune_hosts=NEPTUNE_CONFIG_HOST_IDENTIFIERS) |
| 343 | + self.assertEqual(config.to_dict(), expected_config) |
| 344 | + |
124 | 345 | def test_generate_configuration_with_defaults_neptune_reg(self): |
125 | 346 | config = Configuration(self.neptune_host_reg, self.port) |
126 | 347 | c = generate_config(config.host, config.port, auth_mode=config.auth_mode, ssl=config.ssl, |
|
0 commit comments