Adapted invalid cookie test to all Python versions

Refs #23638. Older Python versions are less strict when parsing
invalid cookie content. The test just has to ensure Django doesn't
crash.
Fixed #22977 -- Check clashes between related_name and manager name