def test_user_has_permission_product_member_success(self, mock_get): other_user = User() other_user.id = 2 product_member_other_user = Product_Member() product_member_other_user.id = 2 product_member_other_user.user = other_user product_member_other_user.product_type = self.product product_member_other_user.role = Roles.Owner mock_get.return_value = product_member_other_user result = user_has_permission(other_user, self.product_member_reader, Permissions.Product_Member_Delete) self.assertTrue(result) self.assertEqual(mock_get.call_args[1]['user'], other_user) self.assertEqual(mock_get.call_args[1]['product'], self.product)
def test_user_has_permission_product_member_success(self, mock_foo): other_user = User() other_user.id = 2 product_member_other_user = Product_Member() product_member_other_user.id = 2 product_member_other_user.user = other_user product_member_other_user.product = self.product product_member_other_user.role = Role.objects.get(id=Roles.Owner) mock_foo.select_related.return_value = mock_foo mock_foo.select_related.return_value = mock_foo mock_foo.filter.return_value = [product_member_other_user] result = user_has_permission(other_user, self.product_member_reader, Permissions.Product_Member_Delete) self.assertTrue(result) mock_foo.filter.assert_called_with(user=other_user)
def test_user_has_permission_product_member_no_permission(self, mock_get): other_user = User() other_user.id = 2 product_member_other_user = Product_Member() product_member_other_user.id = 2 product_member_other_user.user = other_user product_member_other_user.product = self.product product_member_other_user.role = Roles.Reader mock_get.return_value = product_member_other_user result = user_has_permission(other_user, self.product_member_owner, Permissions.Product_Remove_Member) self.assertFalse(result) self.assertEqual(mock_get.call_args[1]['user'], other_user) self.assertEqual(mock_get.call_args[1]['product'], self.product)