'A PUT request to /json/users/me/avatar with a valid file should return a url and actually create an avatar.'

def test_valid_avatars(self):

    version = 2
    for (fname, rfname) in self.correct_files:
        self.login(self.example_email('hamlet'))
        with get_test_image_file(fname) as fp:
            result = self.client_post('/json/users/me/avatar', {'file': fp})
        self.assert_json_success(result)
        json = ujson.loads(result.content)
        self.assertIn('avatar_url', json)
        url = json['avatar_url']
        base = '/user_avatars/'
        self.assertEqual(base, url[:len(base)])
        if (rfname is not None):
            response = self.client_get(url)
            data = ''.join(response.streaming_content)
            self.assertEqual(Image.open(io.BytesIO(data)).size, (100, 100))
        user_profile = self.example_user('hamlet')
        medium_avatar_disk_path = avatar_disk_path(user_profile, medium=True)
        self.assertTrue(os.path.exists(medium_avatar_disk_path))
        os.remove(medium_avatar_disk_path)
        self.assertFalse(os.path.exists(medium_avatar_disk_path))
        zerver.lib.upload.upload_backend.ensure_medium_avatar_image(user_profile)
        self.assertTrue(os.path.exists(medium_avatar_disk_path))
        self.assertEqual(user_profile.avatar_version, version)
        version += 1
