[1.6.x] Fixed a test isolation issue. Refs #17062.

This test could change settings.DATABASES['default']['TIME_ZONE'] and
didn't restore the previous value.

Backport of 1c24096f from master.
[1.6.x] Fixed #21452 -- Non-autocommit connections to PostgreSQL.

When settings.DATABASES['default']['AUTOCOMMIT'] = False, the connection
wasn't in autocommit mode but Django pretended it was.

Thanks Anssi for analysing this issue.

Refs #17062.

Backport of 1afe7488 from master