You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding a model class in the unit tests, users seem to get permissions they should not have.
See the following commit on my forked project: rjekker@27179a1
I create a new Model class with permissions in tests/testapp/models.py:
@rules.predicate
def is_car_owner(user, car):
return car.owner == user
class Car(RulesModel):
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
class Meta:
rules_permissions = {"wash": rules.always_allow,
"drive": is_car_owner,
"crash": rules.always_deny
I create two car instances with different owners:
if sys.version_info.major >= 3:
from testapp.models import Car
Car.objects.create(
owner=adrian
)
Car.objects.create(
owner=martin
)
Then the following test fails:
def test_cars_owner(self):
# adrian can *not* drive martins car
car1 = Car.objects.get(pk=1)
assert car1.owner.username == "adrian"
car2 = Car.objects.get(pk=2)
assert car2.owner.username == "martin"
adrian = get_user_model().objects.get(pk=1)
martin = get_user_model().objects.get(pk=2)
assert adrian == car1.owner
assert martin == car2.owner
assert not adrian.has_perm(Car.get_perm("drive"), car2) # <---- Fails here
assert not martin.has_perm(Car.get_perm("drive"), car1)
The unit test seems to decide that adrian can drive martins car, even though he should not.
The text was updated successfully, but these errors were encountered:
Adding a model class in the unit tests, users seem to get permissions they should not have.
See the following commit on my forked project: rjekker@27179a1
I create a new Model class with permissions in
tests/testapp/models.py
:I create two car instances with different owners:
Then the following test fails:
The unit test seems to decide that adrian can drive martins car, even though he should not.
The text was updated successfully, but these errors were encountered: