switch from mox to mock and fix python 3 support in middleware