Fix attachment upload for python3

The main motivation for this pull request is to fix file uploads on Python3, which currently doesn't work at all. However, in order to do so, I fixed quite a few broken things and did some refactoring, and renaming of test classes.

The fix is very small, but comes with tests.

I've made this against the django1.7 branch as requested on the README. I can rebase against master if you would like.