library.py: Add helper methods.
library.py: Optimise imports.
test_delete.py: Use new helpers.
test_{delete,chgrp}.py: Add tests.

This commit implements tests from tickets #12452 and #12544.
test_chgrp.py: Optimise imports.