Testclient user have not enough permissions to create another users.
|Reported by:||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
During Django unit-testing the testclient user is creating another users, and if someone (like we are) added security checks like one below, tests will fail.
def check_change_permissions(sender, instance, **kwargs): user = get_current_user() # WARNING! This is used for passing Django unit-testing. if not user: return #WARNING! For successful login. if user.is_anonymous(): return if user.is_superuser: return if user != instance: raise PermissionDenied pre_save.connect(check_change_permissions, sender = User)
The fix is trivial - add superuser permissions to the testclient user. Patch is included.