Reorganize tests and fix Windows bugs

Move tests to a tests folder with subfolders for unit tests and integration tests.

Also, fix bugs detected in Windows testing
 * make sure to close open files in tests
 * use binary mode to upload/download files