def test_routing_key_generation_complex(self): """ Compares the routing key generated by complex composite partition key using the model with the one generated by the equivalent bound statement @since 3.2 @jira_ticket PYTHON-535 @expected_result they should match @test_category object_mapper """ prepared = self.session.prepare(""" INSERT INTO {0}.complex_model_routing (partition, cluster, count, text, float, text_2) VALUES (?, ?, ?, ?, ?, ?) """.format(DEFAULT_KEYSPACE)) partition = uuid4() cluster = 1 count = 2 text = "text" float = 1.2 text_2 = "text_2" bound = prepared.bind((partition, cluster, count, text, float, text_2)) mrk = ComplexModelRouting._routing_key_from_values( [partition, cluster, text, float], self.session.cluster.protocol_version) simple = SimpleStatement("") simple.routing_key = mrk self.assertEqual(bound.routing_key, simple.routing_key)
def test_routing_key_is_ignored(self): """ Compares the routing key generated by simple partition key using the model with the one generated by the equivalent bound statement. It also verifies basic operations work with no routing key @since 3.2 @jira_ticket PYTHON-505 @expected_result they shouldn't match @test_category object_mapper """ prepared = self.session.prepare(""" INSERT INTO {0}.basic_model_no_routing (k, v) VALUES (?, ?) """.format(DEFAULT_KEYSPACE)) bound = prepared.bind((1, 2)) mrk = BasicModelNoRouting._routing_key_from_values( [1], self.session.cluster.protocol_version) simple = SimpleStatement("") simple.routing_key = mrk self.assertNotEqual(bound.routing_key, simple.routing_key) # Verify that basic create, update and delete work with no routing key t = BasicModelNoRouting.create(k=2, v=3) t.update(v=4).save() f = BasicModelNoRouting.objects.filter(k=2).first() self.assertEqual(t, f) t.delete() self.assertEqual(BasicModelNoRouting.objects.count(), 0)
def test_routing_key_generation_multi(self): """ Compares the routing key generated by composite partition key using the model with the one generated by the equivalent bound statement @since 3.2 @jira_ticket PYTHON-535 @expected_result they should match @test_category object_mapper """ prepared = self.session.prepare(""" INSERT INTO {0}.basic_model_routing_multi (k, v) VALUES (?, ?) """.format(DEFAULT_KEYSPACE)) bound = prepared.bind((1, 2)) mrk = BasicModelMulti._routing_key_from_values( [1, 2], self.session.cluster.protocol_version) simple = SimpleStatement("") simple.routing_key = mrk self.assertEqual(bound.routing_key, simple.routing_key)