def test_consistency_passing(self): """ Test to validated that graph consistency levels are properly surfaced to the base dirver @since 1.0.0 @jira_ticket PYTHON-509 @expected_result graph consistency levels are surfaced correctly @test_category dse graph """ cl_attrs = ('graph_read_consistency_level', 'graph_write_consistency_level') # Iterates over the graph options and constructs an array containing # The graph_options that correlate to graoh read and write consistency levels graph_params = [a[2] for a in _graph_options if a[0] in cl_attrs] s = self.session default_profile = s.cluster.profile_manager.profiles[EXEC_PROFILE_GRAPH_DEFAULT] default_graph_opts = default_profile.graph_options try: # Checks the default graph attributes and ensures that both graph_read_consistency_level and graph_write_consistency_level # Are None by default for attr in cl_attrs: self.assertIsNone(getattr(default_graph_opts, attr)) res = s.execute_graph("null") for param in graph_params: self.assertNotIn(param, res.response_future.message.custom_payload) # session defaults are passed opts = GraphOptions() opts.update(default_graph_opts) cl = {0: ConsistencyLevel.ONE, 1: ConsistencyLevel.LOCAL_QUORUM} for k, v in cl.items(): setattr(opts, cl_attrs[k], v) default_profile.graph_options = opts res = s.execute_graph("null") for k, v in cl.items(): self.assertEqual(res.response_future.message.custom_payload[graph_params[k]], six.b(ConsistencyLevel.value_to_name[v])) # passed profile values override session defaults cl = {0: ConsistencyLevel.ALL, 1: ConsistencyLevel.QUORUM} opts = GraphOptions() opts.update(default_graph_opts) for k, v in cl.items(): attr_name = cl_attrs[k] setattr(opts, attr_name, v) self.assertNotEqual(getattr(default_profile.graph_options, attr_name), getattr(opts, attr_name)) tmp_profile = s.execution_profile_clone_update(EXEC_PROFILE_GRAPH_DEFAULT, graph_options=opts) res = s.execute_graph("null", execution_profile=tmp_profile) for k, v in cl.items(): self.assertEqual(res.response_future.message.custom_payload[graph_params[k]], six.b(ConsistencyLevel.value_to_name[v])) finally: default_profile.graph_options = default_graph_opts
def test_set_attr(self): expected = 'test@@@@' opts = GraphOptions(graph_name=expected) self.assertEqual(opts.graph_name, six.b(expected)) expected = 'somethingelse####' opts.graph_name = expected self.assertEqual(opts.graph_name, six.b(expected)) # will update options with set value another = GraphOptions() self.assertIsNone(another.graph_name) another.update(opts) self.assertEqual(another.graph_name, six.b(expected)) opts.graph_name = None self.assertIsNone(opts.graph_name) # will not update another with its set-->unset value another.update(opts) self.assertEqual(another.graph_name, six.b(expected)) # remains unset opt_map = another.get_options_map(opts) self.assertEqual(opt_map, another._graph_options)
def test_update(self): opts = GraphOptions(**self.api_params) new_params = dict((k, str(int(v) + 1)) for k, v in self.api_params.items()) opts.update(GraphOptions(**new_params)) self._verify_api_params(opts, new_params)