From nobody Tue Apr 23 22:12:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555584401; cv=none; d=zoho.com; s=zohoarc; b=MgjCLCz0+G7ijZ4BcA4iGVe1jn1SSa08lPUCpcKk7ks5lImjcmctvbHGJksW6xKa7dwgrqazN2IcJSplz+psKH/IC5OdU9IGDy+nrY1Oqti7f+qbbWFHMeMms0PPGuWQucpDFoXl/z3fFy30hOYuaNm4ALPQRyeXFao4qU4EvGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555584401; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=zEx/bxgXHtCyTcBsxDSx/0ERtiMk3kWeTHROw4loEQI=; b=E02Xwgb66v8mNoOwaoyZK5XknmAubSCIq9VAbNUBKPC26CZ9EjW+ksOO333d72yI1JQKhz8HSRP2qDNuzP5fPpqxLgzj8N3amx0h8RWXpvhVHN+H1/m6iOaUBq6PXPVRSUGU+BG4eR0JZ+tIL3UpFLL/JjF4AebrlZdLu8bMUdM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1555584401361190.8173149714753; Thu, 18 Apr 2019 03:46:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C100F30821F8; Thu, 18 Apr 2019 10:46:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B525260BEC; Thu, 18 Apr 2019 10:46:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A86083FB11; Thu, 18 Apr 2019 10:46:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3IAka8U030547 for ; Thu, 18 Apr 2019 06:46:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id EBF7560C61; Thu, 18 Apr 2019 10:46:36 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-46.ams2.redhat.com [10.36.112.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 507C660BF7 for ; Thu, 18 Apr 2019 10:46:31 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Thu, 18 Apr 2019 12:46:30 +0200 Message-Id: <20190418104630.22446-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH] rest: add reviewers and obsoleted-by X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 18 Apr 2019 10:46:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Make the API more complete, and remove the need to access properties from the tests. Signed-off-by: Paolo Bonzini --- mods/tags.py | 20 +++++++++++++++++++- tests/test_import.py | 28 ++++++++++++++-------------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/mods/tags.py b/mods/tags.py index e31db26..c1e8d8c 100644 --- a/mods/tags.py +++ b/mods/tags.py @@ -9,10 +9,11 @@ # http://opensource.org/licenses/MIT. =20 from mod import PatchewModule -from mbox import parse_address +from mbox import addr_db_to_rest, parse_address from event import register_handler, emit_event, declare_event from api.models import Message from api.rest import PluginMethodField +import rest_framework =20 REV_BY_PREFIX =3D "Reviewed-by:" BASED_ON_PREFIX =3D "Based-on:" @@ -141,3 +142,20 @@ series cover letter, patch mail body and their replies. "row_class": "obsolete" }) =20 + def get_obsoleted_by(self, message, request, format): + obsoleted_by =3D message.get_property("obsoleted-by") + if not obsoleted_by: + return None + return rest_framework.reverse.reverse("series-detail", + kwargs=3D{'projects_pk': message.project.id, 'message= _id': obsoleted_by}, + request=3Drequest, format=3Dformat) + + def get_reviewers(self, message, request, format): + reviewers =3D message.get_property("reviewers", []) + return [addr_db_to_rest(x) for x in reviewers] + + def rest_message_fields_hook(self, request, fields): + fields['reviewers'] =3D PluginMethodField(obj=3Dself, required=3DF= alse) + + def rest_series_fields_hook(self, request, fields, detailed): + fields['obsoleted_by'] =3D PluginMethodField(obj=3Dself, required= =3DFalse) diff --git a/tests/test_import.py b/tests/test_import.py index 8fd706f..e554320 100755 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -19,7 +19,8 @@ class ImportTest(PatchewTestCase): def setUp(self): self.create_superuser() self.cli_login() - self.add_project("QEMU", "qemu-devel@nongnu.org") + self.p =3D self.add_project("QEMU", "qemu-devel@nongnu.org") + self.PROJECT_BASE =3D '%sprojects/%d/' % (self.REST_BASE, self.p.i= d) =20 def test_import_one(self): self.cli_import("0001-simple-patch.mbox.gz") @@ -35,14 +36,14 @@ class ImportTest(PatchewTestCase): =20 def test_case_insensitive(self): self.cli_import("0002-unusual-cased-tags.mbox.gz") - a, b =3D self.check_cli(["search", "-r", "-o", "subject,properties= "]) - ao =3D json.loads(a)[0] - self.assertEqual(["Fam Zheng", "famz@redhat.com"], - ao["properties"]["reviewers"][0]) + MESSAGE_ID =3D '20160628014747.20971-1-famz@redhat.com' + resp =3D self.api_client.get(self.PROJECT_BASE + 'messages/' + MES= SAGE_ID + '/') + self.assertEqual({"name": "Fam Zheng", "address": "famz@redhat.com= "}, + resp.data["reviewers"][0]) self.assertIn('Reviewed-By: Fam Zheng ', - ao["properties"]["tags"]) + resp.data["tags"]) self.assertIn('tESTed-bY: Fam Zheng ', - ao["properties"]["tags"]) + resp.data["tags"]) =20 def test_non_utf_8(self): self.cli_import("0005-non-utf-8.mbox.gz") @@ -55,13 +56,12 @@ class ImportTest(PatchewTestCase): =20 def test_obsoleted_by(self): self.cli_import("0009-obsolete-by.mbox.gz") - a, b =3D self.check_cli(["search", "-r", "-o", "subject,properties= "]) - ao =3D json.loads(a) - for m in ao: - if "[PATCH]" in m["subject"]: - self.assertTrue(m["properties"].get("obsoleted-by")) - else: - self.assertFalse(m["properties"].get("obsoleted-by")) + OLD_ID =3D '20160628014747.20971-1-famz@redhat.com' + NEW_ID =3D '20160628014747.20971-2-famz@redhat.com' + resp =3D self.api_client.get(self.PROJECT_BASE + 'series/' + OLD_I= D + '/') + self.assertEqual(self.PROJECT_BASE + 'series/' + NEW_ID + '/', res= p.data["obsoleted_by"]) + resp =3D self.api_client.get(self.PROJECT_BASE + 'series/' + NEW_I= D + '/') + self.assertEqual(None, resp.data["obsoleted_by"]) =20 def test_import_invalid_byte(self): self.add_project("EDK2", "edk2-devel@lists.01.org") --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel