rigging elections is once every 15 turns.
it checks all the spies in the CS, and sorts by spy rank. I don't believe the effectiveness boost from tourism is used from the spy because you aren't putting it in an AI city.
if there are spies of the same rank, then the longest one rigging elections wins.
usually I like to coup one turn before elections, and when I pull off the rigged election, it becomes much harder for the AI to coup back. as far as the coup is concerned, I believe when its successful, your influence and the previous ally's influence are exchanged, but I'm not certain about that.