def _patch(request: Request): db_issue: Issue = request.validated['issue'] db_user: User = request.validated['user'] if db_user.is_admin() or db_user is db_issue.author: shallow_patch(db_issue, request.json_body, allowed_fields=ApiIssue.modifiable) return db_issue else: return HTTPUnauthorized()
def test_shallow_patch(self): a = A() allowed_fields = frozenset({"a"}) patch_value = {"a": 5, "c": 6, "d": 7} shallow_patch(a, patch_value, allowed_fields=allowed_fields) self.assertEqual(a.a, 5) self.assertEqual(a.b, 2) self.assertEqual(a.c, 3) self.assertNotIn("d", dir(A()))