From patchwork Fri Apr 17 22:15:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 1272493 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 493r5V24mlz9sPF for ; Sat, 18 Apr 2020 08:15:58 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" header.d=that.guru header.i=@that.guru header.a=rsa-sha256 header.s=default header.b=JwMPTvS3; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 493r5T3xpDzDrgK for ; Sat, 18 Apr 2020 08:15:57 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=that.guru (client-ip=199.181.239.151; helo=relay0151.mxlogin.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" header.d=that.guru header.i=@that.guru header.a=rsa-sha256 header.s=default header.b=JwMPTvS3; dkim-atps=neutral Received: from relay0151.mxlogin.com (relay0151.mxlogin.com [199.181.239.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 493r5K2T5qzDrQM for ; Sat, 18 Apr 2020 08:15:48 +1000 (AEST) Received: from filter003.mxroute.com ([168.235.111.26] 168-235-111-26.cloud.ramnode.com) (Authenticated sender: mN4UYu2MZsgR) by relay0151.mxlogin.com (ZoneMTA) with ESMTPSA id 1718a3638110000766.001 for (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256); Fri, 17 Apr 2020 22:15:41 +0000 X-Zone-Loop: 0ae83e3e8901b6c5377d9bce5cda2402dc68dcd7cc8b X-Originating-IP: [168.235.111.26] Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter003.mxroute.com (Postfix) with ESMTPS id 841766003F for ; Fri, 17 Apr 2020 22:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=pJcAnpZH1qpcQxy9PIc5c7a3ToWy7bw28O72P6tB/50=; b=JwMPTvS3uFMtqW0US1IBhHqtem yb28o9iwZr8SKmHogEjBky/SSV7rMLcmydkXHV+O1JZRwEjjQ5sjBIGvzyK+GDpu9oGzWkSvxFvM6 KURWcXT+46FuEmYrRG/lWvfS7Bti0QIWgZjl1okgY6Gpp2QS28Fie466G+wOIlS19dRSXHkvxYEmN 6TRFq2BN63DXv/EoIlepkLvZNVMJIlJHbYNsl3+/dJOZJVgkuqsdj1qSOV4wBrkiuZcl+RXZh6WDS WhALOZqUQMqIgTPLooRBvyvMhGMCszLvSVmZQx9FrGPVu7g7EWHPaxGK2pPHz2i+lMI2sjDgz1nA0 a2/Tnitg==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH] REST: Allow update of bundle without patches Date: Fri, 17 Apr 2020 23:15:32 +0100 Message-Id: <20200417221532.175709-1-stephen@that.guru> X-Mailer: git-send-email 2.25.2 MIME-Version: 1.0 X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Presently, when updating a patch we assume that patches are provided. This isn't necessary - you might just want to make it public - and isn't enforced by the API itself. However, because we make this assumption, we see a HTTP 500. Resolve the issue and add tests to prevent a regression. Signed-off-by: Stephen Finucane Resolves: #357 --- patchwork/api/bundle.py | 8 +++--- patchwork/tests/api/test_bundle.py | 25 +++++++++++++++++++ .../notes/issue-357-1bef23dbfda2722d.yaml | 6 +++++ 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/issue-357-1bef23dbfda2722d.yaml diff --git patchwork/api/bundle.py patchwork/api/bundle.py index 54a9266e..93e32316 100644 --- patchwork/api/bundle.py +++ patchwork/api/bundle.py @@ -80,10 +80,11 @@ class BundleSerializer(BaseHyperlinkedModelSerializer): return instance def update(self, instance, validated_data): - patches = validated_data.pop('patches') + patches = validated_data.pop('patches', None) instance = super(BundleSerializer, self).update( instance, validated_data) - instance.overwrite_patches(patches) + if patches: + instance.overwrite_patches(patches) return instance def validate_patches(self, value): @@ -97,7 +98,8 @@ class BundleSerializer(BaseHyperlinkedModelSerializer): return value def validate(self, data): - data['project'] = data['patches'][0].project + if data.get('patches'): + data['project'] = data['patches'][0].project return super(BundleSerializer, self).validate(data) diff --git patchwork/tests/api/test_bundle.py patchwork/tests/api/test_bundle.py index d03f26f1..79924486 100644 --- patchwork/tests/api/test_bundle.py +++ patchwork/tests/api/test_bundle.py @@ -288,9 +288,34 @@ class TestBundleAPI(utils.APITestCase): self.assertEqual(status.HTTP_200_OK, resp.status_code) self.assertEqual(2, len(resp.data['patches'])) self.assertEqual('hello-bundle', resp.data['name']) + self.assertFalse(resp.data['public']) self.assertEqual(1, Bundle.objects.all().count()) self.assertEqual(2, len(Bundle.objects.first().patches.all())) self.assertEqual('hello-bundle', Bundle.objects.first().name) + self.assertFalse(Bundle.objects.first().public) + + def test_update_no_patches(self): + """Validate we handle updating only the name.""" + user, project, patch_a, patch_b = self._test_create_update() + bundle = create_bundle(owner=user, project=project) + + bundle.append_patch(patch_a) + bundle.append_patch(patch_b) + + self.assertEqual(1, Bundle.objects.all().count()) + self.assertEqual(2, len(Bundle.objects.first().patches.all())) + + resp = self.client.patch(self.api_url(bundle.id), { + 'name': 'hello-bundle', 'public': True, + }) + self.assertEqual(status.HTTP_200_OK, resp.status_code) + self.assertEqual(2, len(resp.data['patches'])) + self.assertEqual('hello-bundle', resp.data['name']) + self.assertTrue(resp.data['public']) + self.assertEqual(1, Bundle.objects.all().count()) + self.assertEqual(2, len(Bundle.objects.first().patches.all())) + self.assertEqual('hello-bundle', Bundle.objects.first().name) + self.assertTrue(Bundle.objects.first().public) @utils.store_samples('bundle-delete-not-found') def test_delete_anonymous(self): diff --git releasenotes/notes/issue-357-1bef23dbfda2722d.yaml releasenotes/notes/issue-357-1bef23dbfda2722d.yaml new file mode 100644 index 00000000..1f337c72 --- /dev/null +++ releasenotes/notes/issue-357-1bef23dbfda2722d.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + An issue that preventing updating bundles via the REST API without + updating the included patches has been resolved. + (`#357 `__)