{"id":808139,"url":"http://patchwork.ozlabs.org/api/patches/808139/?format=json","web_url":"http://patchwork.ozlabs.org/project/patchwork/patch/20170831084851.9633-1-stephen@that.guru/","project":{"id":16,"url":"http://patchwork.ozlabs.org/api/projects/16/?format=json","name":"Patchwork","link_name":"patchwork","list_id":"patchwork.lists.ozlabs.org","list_email":"patchwork@lists.ozlabs.org","web_url":"http://jk.ozlabs.org/projects/patchwork/","scm_url":"git://github.com/getpatchwork/patchwork","webscm_url":"https://github.com/getpatchwork/patchwork","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170831084851.9633-1-stephen@that.guru>","list_archive_url":null,"date":"2017-08-31T08:48:51","name":"REST: Filter projects by 'linkname', not 'name'","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"78daf664a431c764c679977b4fd340e63275ed4f","submitter":{"id":69991,"url":"http://patchwork.ozlabs.org/api/people/69991/?format=json","name":"Stephen Finucane","email":"stephen@that.guru"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/patchwork/patch/20170831084851.9633-1-stephen@that.guru/mbox/","series":[{"id":772,"url":"http://patchwork.ozlabs.org/api/series/772/?format=json","web_url":"http://patchwork.ozlabs.org/project/patchwork/list/?series=772","date":"2017-08-31T08:48:51","name":"REST: Filter projects by 'linkname', not 'name'","version":1,"mbox":"http://patchwork.ozlabs.org/series/772/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/808139/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/808139/checks/","tags":{},"related":[],"headers":{"Return-Path":"<patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>","X-Original-To":["incoming@patchwork.ozlabs.org","patchwork@lists.ozlabs.org"],"Delivered-To":["patchwork-incoming@bilbo.ozlabs.org","patchwork@lists.ozlabs.org"],"Received":["from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xjbdj6FTSz9s3w\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 31 Aug 2017 18:49:13 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xjbdj56p6zDqVg\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 31 Aug 2017 18:49:13 +1000 (AEST)","from duck.birch.relay.mailchannels.net\n\t(duck.birch.relay.mailchannels.net [23.83.209.52])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3xjbdY11H9zDqGZ\n\tfor <patchwork@lists.ozlabs.org>;\n\tThu, 31 Aug 2017 18:49:04 +1000 (AEST)","from relay.mailchannels.net (localhost [127.0.0.1])\n\tby relay.mailchannels.net (Postfix) with ESMTP id 79C73127361;\n\tThu, 31 Aug 2017 08:49:00 +0000 (UTC)","from one.mxroute.com (unknown [100.96.128.157])\n\t(Authenticated sender: mxroute)\n\tby relay.mailchannels.net (Postfix) with ESMTPA id 08C7512875A;\n\tThu, 31 Aug 2017 08:48:59 +0000 (UTC)","from one.mxroute.com (one-outgoing.mxroute.com [172.20.97.179])\n\t(using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384)\n\tby 0.0.0.0:2500 (trex/5.9.14); Thu, 31 Aug 2017 08:49:00 +0000"],"Authentication-Results":["ozlabs.org;\n\tdkim=fail reason=\"key not found in DNS\" (0-bit key;\n\tunprotected) header.d=that.guru header.i=@that.guru\n\theader.b=\"b/aVmbCc\"; dkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"key not found in DNS\" (0-bit key;\n\tunprotected) header.d=that.guru header.i=@that.guru\n\theader.b=\"b/aVmbCc\"; dkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"key not found in DNS\" (0-bit key;\n\tunprotected) header.d=that.guru header.i=@that.guru\n\theader.b=\"b/aVmbCc\"; dkim-atps=neutral"],"X-Sender-Id":["mxroute|x-authuser|stephen@that.guru","mxroute|x-authuser|stephen@that.guru"],"X-MC-Relay":"Neutral","X-MailChannels-SenderId":"mxroute|x-authuser|stephen@that.guru","X-MailChannels-Auth-Id":"mxroute","X-Duck-Fumbling":"51c7b71b1f9072d3_1504169340348_1156267704","X-MC-Loop-Signature":"1504169340348:2083035254","X-MC-Ingress-Time":"1504169340348","DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru;\n\ts=default;\n\th=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version\n\t:Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description:\n\tResent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:\n\tIn-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:\n\tList-Post:List-Owner:List-Archive;\n\tbh=RGyPIsBcUXDDava6XtJyeJbPAWHdRWkhVakbI2BweCY=;\n\tb=b/aVmbCcWPU5s3AD6OCiNJWcnG\n\tDbVeBqaXGKuswvyXN2zvmWm/R/0FrkfLlfOGHAUi4lxK5xLJxKi+1fyAqFrTJr45JFslcYNVRxPQG\n\tKwAAYzJkqSdiWDtBGgc7wn4rg5jsrGKM1jTkX5DVRqGLIm1EUNC7fV8OPbaT5fF1xgE+qdHQNi0dq\n\tvp3Lou2GWJxrQ6zXBz+822OxWdgxzu8KgUpn9ct/6DZAWsnko0jTZB6QK1P2Y/W2byr7zUQWxrKSK\n\t7DOtJi45zPyVJNAP7WTIToy9hy1sHhnJ+ljaFBfZRnwEqQ4cK7jETqu9LYhwwFVwYP32XGFNqvin0\n\tas8XoVHA==;","From":"Stephen Finucane <stephen@that.guru>","To":"patchwork@lists.ozlabs.org","Subject":"[PATCH] REST: Filter projects by 'linkname', not 'name'","Date":"Thu, 31 Aug 2017 09:48:51 +0100","Message-Id":"<20170831084851.9633-1-stephen@that.guru>","X-Mailer":"git-send-email 2.13.5","X-AuthUser":"stephen@that.guru","X-BeenThere":"patchwork@lists.ozlabs.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"Patchwork development <patchwork.lists.ozlabs.org>","List-Unsubscribe":"<https://lists.ozlabs.org/options/patchwork>,\n\t<mailto:patchwork-request@lists.ozlabs.org?subject=unsubscribe>","List-Archive":"<http://lists.ozlabs.org/pipermail/patchwork/>","List-Post":"<mailto:patchwork@lists.ozlabs.org>","List-Help":"<mailto:patchwork-request@lists.ozlabs.org?subject=help>","List-Subscribe":"<https://lists.ozlabs.org/listinfo/patchwork>,\n\t<mailto:patchwork-request@lists.ozlabs.org?subject=subscribe>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org","Sender":"\"Patchwork\"\n\t<patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>"},"content":"Based on a report on the OVS mailing list, it appears that projects are\nbeing filtered on the 'Project.name' field instead of the\n'Project.linkname' field. Correct this and add regression tests to\nprevent it happening again.\n\nSigned-off-by: Stephen Finucane <stephen@that.guru>\nFixes: 08b2115 (\"REST: Allow filtering by both project ID and linkname\")\nCloses-bug: #117 (\"Projects are filtered on the wrong field\")\nCc: Daniel Axtens <dja@axtens.net>\n---\ndaxtens - if you've time (and this looks good), you might handle the\nmerge and backport part of this. Everything about the latter should be\ndocumented in enough detail:\n\n  https://patchwork.readthedocs.io/en/latest/development/releasing/#backporting\n\nFeel free to ping me here on IRC (stephenfin on #freenode) if necessary.\n---\n patchwork/api/filters.py         |  2 +-\n patchwork/tests/test_rest_api.py | 39 +++++++++++++++++++++++++++++++--------\n 2 files changed, 32 insertions(+), 9 deletions(-)","diff":"diff --git a/patchwork/api/filters.py b/patchwork/api/filters.py\nindex 9966543..314aa47 100644\n--- a/patchwork/api/filters.py\n+++ b/patchwork/api/filters.py\n@@ -50,7 +50,7 @@ class ProjectChoiceField(ModelChoiceField):\n         try:\n             filters = {'pk': int(value)}\n         except ValueError:\n-            filters = {'name__iexact': ' '.join(value.split('-'))}\n+            filters = {'linkname__iexact': ' '.join(value.split('-'))}\n \n         try:\n             value = self.queryset.get(**filters)\ndiff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py\nindex abffd17..14e53b2 100644\n--- a/patchwork/tests/test_rest_api.py\n+++ b/patchwork/tests/test_rest_api.py\n@@ -97,7 +97,23 @@ class TestProjectAPI(APITestCase):\n         self.assertEqual(status.HTTP_200_OK, resp.status_code)\n         self.assertSerialized(project, resp.data)\n \n-    def test_get_numeric_linkname(self):\n+    def test_get_by_id(self):\n+        \"\"\"Validate that it's possible to filter by pk.\"\"\"\n+        project = create_project()\n+\n+        resp = self.client.get(self.api_url(project.pk))\n+        self.assertEqual(status.HTTP_200_OK, resp.status_code)\n+        self.assertSerialized(project, resp.data)\n+\n+    def test_get_by_linkname(self):\n+        \"\"\"Validate that it's possible to filter by linkname.\"\"\"\n+        project = create_project(linkname='project', name='Sample project')\n+\n+        resp = self.client.get(self.api_url('project'))\n+        self.assertEqual(status.HTTP_200_OK, resp.status_code)\n+        self.assertSerialized(project, resp.data)\n+\n+    def test_get_by_numeric_linkname(self):\n         \"\"\"Validate we try to do the right thing for numeric linkname\"\"\"\n         project = create_project(linkname='12345')\n \n@@ -326,7 +342,8 @@ class TestPatchAPI(APITestCase):\n         self.assertEqual(0, len(resp.data))\n \n         state_obj = create_state(name='Under Review')\n-        patch_obj = create_patch(state=state_obj)\n+        project_obj = create_project(linkname='myproject')\n+        patch_obj = create_patch(state=state_obj, project=project_obj)\n \n         # anonymous user\n         resp = self.client.get(self.api_url())\n@@ -338,12 +355,6 @@ class TestPatchAPI(APITestCase):\n         self.assertNotIn('content', patch_rsp)\n         self.assertNotIn('diff', patch_rsp)\n \n-        # test filtering by state\n-        resp = self.client.get(self.api_url(), {'state': 'under-review'})\n-        self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])\n-        resp = self.client.get(self.api_url(), {'state': 'missing-state'})\n-        self.assertEqual(0, len(resp.data))\n-\n         # authenticated user\n         user = create_user()\n         self.client.force_authenticate(user=user)\n@@ -353,6 +364,18 @@ class TestPatchAPI(APITestCase):\n         patch_rsp = resp.data[0]\n         self.assertSerialized(patch_obj, patch_rsp)\n \n+        # test filtering by state\n+        resp = self.client.get(self.api_url(), {'state': 'under-review'})\n+        self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])\n+        resp = self.client.get(self.api_url(), {'state': 'missing-state'})\n+        self.assertEqual(0, len(resp.data))\n+\n+        # test filtering by project\n+        resp = self.client.get(self.api_url(), {'project': 'myproject'})\n+        self.assertEqual([patch_obj.id], [x['id'] for x in resp.data])\n+        resp = self.client.get(self.api_url(), {'project': 'invalidproject'})\n+        self.assertEqual(0, len(resp.data))\n+\n     def test_detail(self):\n         \"\"\"Validate we can get a specific patch.\"\"\"\n         patch = create_patch(\n","prefixes":[]}