[1.7.x] Fixed #22811 -- Allowed setting both the old and new TEST database settings.

An ImproperlyConfigured exception will be raised they mismatch.

Backport of 1c58cabad7 and a2cd0e12c9 from master