def test_insert_statement_execute(self):
        """
        Test to verify the execution of BaseCQLStatements using connection.execute

        @since 3.10
        @jira_ticket PYTHON-505
        @expected_result inserts a row in C*, updates the rows and then deletes
        all the rows using BaseCQLStatements

        @test_category data_types:object_mapper
        """
        partition = uuid4()
        cluster = 1
        self._insert_statement(partition, cluster)

        # Verifying update statement
        where = [WhereClause('partition', EqualsOperator(), partition),
                 WhereClause('cluster', EqualsOperator(), cluster)]

        st = UpdateStatement(self.table_name, where=where)
        st.add_assignment(Column(db_field='count'), 2)
        st.add_assignment(Column(db_field='text'), "text_for_db_update")
        st.add_assignment(Column(db_field='text_set'), set(("foo_update", "bar_update")))
        st.add_assignment(Column(db_field='text_list'), ["foo_update", "bar_update"])
        st.add_assignment(Column(db_field='text_map'), {"foo": '3', "bar": '4'})

        execute(st)
        self._verify_statement(st)

        # Verifying delete statement
        execute(DeleteStatement(self.table_name, where=where))
        self.assertEqual(TestQueryUpdateModel.objects.count(), 0)
 def test_context_update(self):
     us = UpdateStatement('table')
     us.add_assignment(Column(db_field='a'), 'b')
     us.add_assignment(Column(db_field='c'), 'd')
     us.add_where(Column(db_field='a'), EqualsOperator(), 'x')
     us.update_context_id(3)
     self.assertEqual(six.text_type(us), 'UPDATE table SET "a" = %(4)s, "c" = %(5)s WHERE "a" = %(3)s')
     self.assertEqual(us.get_context(), {'4': 'b', '5': 'd', '3': 'x'})
Beispiel #3
0
 def test_context_update(self):
     us = UpdateStatement('table')
     us.add_assignment(Column(db_field='a'), 'b')
     us.add_assignment(Column(db_field='c'), 'd')
     us.add_where(Column(db_field='a'), EqualsOperator(), 'x')
     us.update_context_id(3)
     self.assertEqual(six.text_type(us), 'UPDATE table SET "a" = %(4)s, "c" = %(5)s WHERE "a" = %(3)s')
     self.assertEqual(us.get_context(), {'4': 'b', '5': 'd', '3': 'x'})
Beispiel #4
0
    def test_rendering(self):
        us = UpdateStatement('table')
        us.add_assignment(Column(db_field='a'), 'b')
        us.add_assignment(Column(db_field='c'), 'd')
        us.add_where(Column(db_field='a'), EqualsOperator(), 'x')
        self.assertEqual(six.text_type(us), 'UPDATE table SET "a" = %(0)s, "c" = %(1)s WHERE "a" = %(2)s', six.text_type(us))

        us.add_where(Column(db_field='a'), NotEqualsOperator(), 'y')
        self.assertEqual(six.text_type(us), 'UPDATE table SET "a" = %(0)s, "c" = %(1)s WHERE "a" = %(2)s AND "a" != %(3)s', six.text_type(us))
Beispiel #5
0
 def test_additional_rendering(self):
     us = UpdateStatement('table', ttl=60)
     us.add_assignment(Column(db_field='a'), 'b')
     us.add_where(Column(db_field='a'), EqualsOperator(), 'x')
     self.assertIn('USING TTL 60', six.text_type(us))
Beispiel #6
0
 def test_context(self):
     us = UpdateStatement('table')
     us.add_assignment(Column(db_field='a'), 'b')
     us.add_assignment(Column(db_field='c'), 'd')
     us.add_where(Column(db_field='a'), EqualsOperator(), 'x')
     self.assertEqual(us.get_context(), {'0': 'b', '1': 'd', '2': 'x'})
 def test_additional_rendering(self):
     us = UpdateStatement('table', ttl=60)
     us.add_assignment(Column(db_field='a'), 'b')
     us.add_where(Column(db_field='a'), EqualsOperator(), 'x')
     self.assertIn('USING TTL 60', six.text_type(us))
 def test_context(self):
     us = UpdateStatement('table')
     us.add_assignment(Column(db_field='a'), 'b')
     us.add_assignment(Column(db_field='c'), 'd')
     us.add_where(Column(db_field='a'), EqualsOperator(), 'x')
     self.assertEqual(us.get_context(), {'0': 'b', '1': 'd', '2': 'x'})