Boolean difference not making any diiference (Python scripting)
Setting the context object to cube1 with context.scene.objects.active = cube1 before running the apply modifier fixes it.  Object operators run on the context.active_object, which was cube2.

import bpy
context = bpy.context 
scene = context.scene
cube1 = context.active_object
bpy.ops.transform.resize(value=(2.0, 2.0, 0.9))
bpy.ops.object.modifier_add(type = 'BOOLEAN')
bpy.ops.mesh.primitive_cube_add(location=(0.0, 0.0, 0.0))
cube2 = context.active_object
cube1.modifiers[0].object = cube2
cube1.modifiers[0].operation = 'DIFFERENCE'

scene.objects.active = cube1
bpy.ops.object.modifier_apply(apply_as='DATA',modifier=cube1.modifiers[0].name)


A less operator-centric approach

import bpy
context = bpy.context 
scene = context.scene

cube1 = context.active_object
cube2 = cube1.copy()
# create a copy of mesh data, for bool mod
cube2.data = cube1.data.copy()
cube1.scale = (2.0, 2.0, 0.9)
mod = cube1.modifiers.new("SomeName", type='BOOLEAN')
mod.operation = 'DIFFERENCE'
# uncomment below to have cube2 in scene
#scene.objects.link(cube2)
mod.object = cube2
bpy.ops.object.modifier_apply(apply_as='DATA', modifier=mod.name)


The modifier apply operator can also be replaced with

scene.update()
cube1.data = cube1.to_mesh(scene, True, 'PREVIEW')
cube1.modifiers.remove(mod)