[Patchew-devel] [PATCH] rest: add reviewers and obsoleted-by

Paolo Bonzini posted 1 patch 21 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew next tags/patchew/20190418104630.22446-1-pbonzini@redhat.com
mods/tags.py         | 20 +++++++++++++++++++-
tests/test_import.py | 28 ++++++++++++++--------------
2 files changed, 33 insertions(+), 15 deletions(-)

[Patchew-devel] [PATCH] rest: add reviewers and obsoleted-by

Posted by Paolo Bonzini 21 weeks ago
Make the API more complete, and remove the need to access properties from
the tests.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 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.
 
 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
 
 REV_BY_PREFIX = "Reviewed-by:"
 BASED_ON_PREFIX = "Based-on:"
@@ -141,3 +142,20 @@ series cover letter, patch mail body and their replies.
                     "row_class": "obsolete"
                     })
 
+    def get_obsoleted_by(self, message, request, format):
+        obsoleted_by = message.get_property("obsoleted-by")
+        if not obsoleted_by:
+            return None
+        return rest_framework.reverse.reverse("series-detail",
+                     kwargs={'projects_pk': message.project.id, 'message_id': obsoleted_by},
+                     request=request, format=format)
+
+    def get_reviewers(self, message, request, format):
+        reviewers = message.get_property("reviewers", [])
+        return [addr_db_to_rest(x) for x in reviewers]
+
+    def rest_message_fields_hook(self, request, fields):
+        fields['reviewers'] = PluginMethodField(obj=self, required=False)
+
+    def rest_series_fields_hook(self, request, fields, detailed):
+        fields['obsoleted_by'] = PluginMethodField(obj=self, required=False)
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 = self.add_project("QEMU", "qemu-devel@nongnu.org")
+        self.PROJECT_BASE = '%sprojects/%d/' % (self.REST_BASE, self.p.id)
 
     def test_import_one(self):
         self.cli_import("0001-simple-patch.mbox.gz")
@@ -35,14 +36,14 @@ class ImportTest(PatchewTestCase):
 
     def test_case_insensitive(self):
         self.cli_import("0002-unusual-cased-tags.mbox.gz")
-        a, b = self.check_cli(["search", "-r", "-o", "subject,properties"])
-        ao = json.loads(a)[0]
-        self.assertEqual(["Fam Zheng", "famz@redhat.com"],
-                         ao["properties"]["reviewers"][0])
+        MESSAGE_ID = '20160628014747.20971-1-famz@redhat.com'
+        resp = self.api_client.get(self.PROJECT_BASE + 'messages/' + MESSAGE_ID + '/')
+        self.assertEqual({"name": "Fam Zheng", "address": "famz@redhat.com"},
+                         resp.data["reviewers"][0])
         self.assertIn('Reviewed-By: Fam Zheng <famz@redhat.com>',
-                      ao["properties"]["tags"])
+                      resp.data["tags"])
         self.assertIn('tESTed-bY: Fam Zheng <famz@redhat.com>',
-                      ao["properties"]["tags"])
+                      resp.data["tags"])
 
     def test_non_utf_8(self):
         self.cli_import("0005-non-utf-8.mbox.gz")
@@ -55,13 +56,12 @@ class ImportTest(PatchewTestCase):
 
     def test_obsoleted_by(self):
         self.cli_import("0009-obsolete-by.mbox.gz")
-        a, b = self.check_cli(["search", "-r", "-o", "subject,properties"])
-        ao = 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 = '20160628014747.20971-1-famz@redhat.com'
+        NEW_ID = '20160628014747.20971-2-famz@redhat.com'
+        resp = self.api_client.get(self.PROJECT_BASE + 'series/' + OLD_ID + '/')
+        self.assertEqual(self.PROJECT_BASE + 'series/' + NEW_ID + '/', resp.data["obsoleted_by"])
+        resp = self.api_client.get(self.PROJECT_BASE + 'series/' + NEW_ID + '/')
+        self.assertEqual(None, resp.data["obsoleted_by"])
 
     def test_import_invalid_byte(self):
         self.add_project("EDK2", "edk2-devel@lists.01.org")
-- 
2.21.0

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel