Fixed bugs in manage.py test