Added the possibility to pass a stdin object to a management command.

This makes testing certain features easier.

Thanks to AeroNotix for the original patch.
Use assertEqual instead of assertEquals.
Fixed #7423 -- Skip superuser creation when not running in a TTY.

Thanks to trac user galaxy4sale for the original report
and to AeroNotix for the patch.
Fixed #22023 -- Raised an error for values() followed by defer() or only().

Previously, doing so resulted in invalid data or crash.

Thanks jtiai for the report and Karol Jochelson,
Jakub Nowak, Loic Bistuer, and Baptiste Mispelon for reviews.