def test_statement(self): ist = InsertStatement('table', None) ist.add_assignment(Column(db_field='a'), 'b') ist.add_assignment(Column(db_field='c'), 'd') self.assertEqual(six.text_type(ist), 'INSERT INTO table ("a", "c") VALUES (%(0)s, %(1)s)')
def test_context_update(self): ist = InsertStatement('table', None) ist.add_assignment(Column(db_field='a'), 'b') ist.add_assignment(Column(db_field='c'), 'd') ist.update_context_id(4) self.assertEqual(six.text_type(ist), 'INSERT INTO table ("a", "c") VALUES (%(4)s, %(5)s)') ctx = ist.get_context() self.assertEqual(ctx, {'4': 'b', '5': 'd'})
def test_additional_rendering(self): ist = InsertStatement('table', ttl=60) ist.add_assignment(Column(db_field='a'), 'b') ist.add_assignment(Column(db_field='c'), 'd') self.assertIn('USING TTL 60', six.text_type(ist))
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 #Verifying insert statement st = InsertStatement(self.table_name) st.add_assignment(Column(db_field='partition'), partition) st.add_assignment(Column(db_field='cluster'), cluster) st.add_assignment(Column(db_field='count'), 1) st.add_assignment(Column(db_field='text'), "text_for_db") st.add_assignment(Column(db_field='text_set'), set(("foo", "bar"))) st.add_assignment(Column(db_field='text_list'), ["foo", "bar"]) st.add_assignment(Column(db_field='text_map'), { "foo": '1', "bar": '2' }) execute(st) self._verify_statement(st) # 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)