Finally, I decided to do some tests for my applications, but I was stuck on testing if the user can change another user (depends on the type of user - I use django rules to be able to do logical permissions checks, but that doesn't matter)
Here is the code that I still have
class RulesAndPermissionsTests(TestCase): fixtures = ['auth_no_permissions.json', 'profiles.json', 'rules.json'] def setUp(self): self.c = Client() self.user = User.objects.get(username="estagiario") self.non_staff = User.objects.get(username="fisica") self.admin = User.objects.get(username="admin") login = self.c.login(username='estagiario', password='estagiario') def test_can_change_non_staff_users(self): self.assertFalse(self.user.has_perm('logical_change_user', self.non_staff.profile))
Even after adding permission, my user still does not have permissions. Is it because I am not allowed to create anything during tests (is this bad practice?)? Or does django cache permissions in some way? If I add permission to setUp, it will work, but I would like to change it during the same test (testing with permission and without permission).
Thanks in advance!
django django-testing django-permissions
Clash
source share