Ensure mocked User.get_profile is removed by @ensure_user_profile
Review Request #8869 — Created April 3, 2017 and submitted
@ensure_user_profiledecorator ensures that
exists because it has been removed in Django 1.7+. For compatability,
some functionality (and therefore unit tests) require it to exist
(i.e., be on Django 1.6 or have it added by a third party).
One issue is that when using this in conjunction with KGB to replace the
get_profilethat the profile will not be deleted, as
SpyAgency.tear_downwill execute after
finished, which results in the original method not being deleted.
Furthermore, the mock method we add will stick around as
To combat this issue, we now check to see if the function has been
replaced by a
FunctionSpyand unspy on it if that is the case. That
will result in
SpyAgencynot modifying the
Additionally, we were comparing
User.get_profileto our mock method,
which will never be equal because
User.get_profilewill be an unbound
method and not the original function. We now compare to the underlying
Ran unit tests on Django 1.6 and 1.8.