Fix Django 1.7+ compatibility issues with RelationCounterField tests.

Review Request #9419 - Created Dec. 3, 2017 and submitted

Christian Hammond

The unit tests for RelationCounterField didn't work properly on newer
versions of Django. The field itself was fine, but the tests needed some

A big part of this was due to a difference in how signals worked on
newer versions of Django. When a weak reference disappeared under Django
1.6, the connections would immediately be cleaned up, but on newer
versions, they'd just be flagged for cleanup the next time connect(),
disconnect(), or _live_receivers() was called, making our
Signal.receivers check fail. The fix for this is to just call
_live_receivers() instead in the tests, which will give us the correct
results and even let us specify the model we care about (simplifying a
lot of test code).

The other problem was that one of the tests no longer made sense in
newer versions of Django. It was testing to make sure that a reused ID
from a Model.delete() call wouldn't cause the wrong state to be looked
up. This could happen due to delete() working within the same
transaction as the caller, but in newer versions of Django, deletions
have their own transaction, preventing this problem.

Unit tests pass on Django 1.6, 1.9, 1.10, and 1.11. For other reasons,
1.7 and 1.8 are not tested.

David Trowbridge
  1. Ship It!
Christian Hammond
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-1.0.x (56686c0)