[{"id":1762278,"web_url":"http://patchwork.ozlabs.org/comment/1762278/","msgid":"<874lsj4ydv.fsf@linkitivity.dja.id.au>","list_archive_url":null,"date":"2017-09-03T15:04:12","subject":"Re: [PATCH] REST: Filter projects by 'linkname', not 'name'","submitter":{"id":65792,"url":"http://patchwork.ozlabs.org/api/people/65792/","name":"Daniel Axtens","email":"dja@axtens.net"},"content":"Hi Stephen,\n\nI was just reading though this before applying it when it occurred to\nme:\n>          except ValueError:\n> -            filters = {'name__iexact': ' '.join(value.split('-'))}\n> +            filters = {'linkname__iexact': ' '.join(value.split('-'))}\n\nSurely a linkname shouldn't have spaces in it? It'd be of the form\nfoo.bar.org, right?\n\nHappy to fix this up as:\n {'linkname__iexact': value}\nbut thought I should probably check I haven't radically misunderstood\nfirst!\n\nRegards,\nDaniel\n\n>  \n>          try:\n>              value = self.queryset.get(**filters)\n> diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py\n> index 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> -- \n> 2.13.5","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 [IPv6:2401:3900:2:1::3])\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 3xlbqJ1Ljfz9t2y\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon,  4 Sep 2017 01:04:28 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xlbqH71QmzDrn0\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon,  4 Sep 2017 01:04:27 +1000 (AEST)","from mail-pf0-x233.google.com (mail-pf0-x233.google.com\n\t[IPv6:2607:f8b0:400e:c00::233])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3xlbq90q29zDqjs\n\tfor <patchwork@lists.ozlabs.org>;\n\tMon,  4 Sep 2017 01:04:20 +1000 (AEST)","by mail-pf0-x233.google.com with SMTP id r187so11845492pfr.3\n\tfor <patchwork@lists.ozlabs.org>;\n\tSun, 03 Sep 2017 08:04:20 -0700 (PDT)","from localhost (124-171-202-56.dyn.iinet.net.au. [124.171.202.56])\n\tby smtp.gmail.com with ESMTPSA id\n\tl185sm7191818pfc.128.2017.09.03.08.04.15\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tSun, 03 Sep 2017 08:04:15 -0700 (PDT)"],"Authentication-Results":["ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"LudKw/5d\"; dkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"LudKw/5d\"; dkim-atps=neutral","lists.ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"LudKw/5d\"; dkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google;\n\th=from:to:cc:subject:in-reply-to:references:date:message-id\n\t:mime-version; bh=kM55GBvqPuFc/Ib04Dzq7/JETuvH3MkvcONOg9K5ONE=;\n\tb=LudKw/5dNMSLrhnJeiTdz+UJQ19e/eB+KSHLBmFQUbGRGQNd58JokksvI0J4sc4Wyy\n\tslz8/tno8mbIXs+FX02AaaiS9ixM/g0pQMGIlU/nS8v0NSHyJPG2PMcmSTCsajStoHpR\n\tP86SX2NVTEJn+uQKHCN2brokC9pwybXY5b2Zs=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date\n\t:message-id:mime-version;\n\tbh=kM55GBvqPuFc/Ib04Dzq7/JETuvH3MkvcONOg9K5ONE=;\n\tb=GIdkoVhoFabL/gh3D0JIsBQ5KFEetrdSSHmBfCW3ySjkziuDPiKCjcNqJ6fwZtoJEX\n\tlyCdWkwsmGgb+Afz6M2YdyX4WbbD4OlVlnYN8KsDuHZXvyo0IMDWewOzjUo3i77mJf91\n\tBCJG2oraTFy1tSbYZuSCDR1zACu6l1O4vMl8NIwtP5Xu0WBAIAXTCVNZMlzQyYUtU+Up\n\t4o+xmATtEj3upUhMfRHnLXeAQSFRmYSFMaFBdXiH/8g0yBYd2IwlxV34b8rZA4wAV4ki\n\tusyi/0ru343AOTfZKD58bhA0AUNz3TsgxhicYqBPEiup4poV1DW0YnuDTwFp3HgLQinD\n\tObLw==","X-Gm-Message-State":"AHPjjUjYAKaMIDNGU0d+L+tOEVaW0dFmUI3z95XD5t3uCC9J22SeYxVi\n\tmsj6R2dhOpmeJH2DHTJ2Ag==","X-Google-Smtp-Source":"ADKCNb5Rve24ecmNz/rsxma5vwNJ1kh3Wyx6786vWexTYbji2xKklRKkuFzXVeMfWAXhlSSflUm4ZA==","X-Received":"by 10.84.224.205 with SMTP id k13mr500907pln.424.1504451056695; \n\tSun, 03 Sep 2017 08:04:16 -0700 (PDT)","From":"Daniel Axtens <dja@axtens.net>","To":"Stephen Finucane <stephen@that.guru>, patchwork@lists.ozlabs.org","Subject":"Re: [PATCH] REST: Filter projects by 'linkname', not 'name'","In-Reply-To":"<20170831084851.9633-1-stephen@that.guru>","References":"<20170831084851.9633-1-stephen@that.guru>","Date":"Mon, 04 Sep 2017 01:04:12 +1000","Message-ID":"<874lsj4ydv.fsf@linkitivity.dja.id.au>","MIME-Version":"1.0","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>","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>"}},{"id":1762440,"web_url":"http://patchwork.ozlabs.org/comment/1762440/","msgid":"<e7efee26-d0f9-a4a0-711f-23c40f240385@ozlabs.org>","list_archive_url":null,"date":"2017-09-04T06:16:00","subject":"Re: [PATCH] REST: Filter projects by 'linkname', not 'name'","submitter":{"id":1,"url":"http://patchwork.ozlabs.org/api/people/1/","name":"Jeremy Kerr","email":"jk@ozlabs.org"},"content":"Hi Dnaiel,\n\n> I was just reading though this before applying it when it occurred to\n> me:\n>>          except ValueError:\n>> -            filters = {'name__iexact': ' '.join(value.split('-'))}\n>> +            filters = {'linkname__iexact': ' '.join(value.split('-'))}\n> \n> Surely a linkname shouldn't have spaces in it? It'd be of the form\n> foo.bar.org, right?\n\npatchwork=# select linkname from patchwork_project limit 10;\n     linkname\n-------------------\n cbe-oss-dev\n linux-mtd\n linuxppc-embedded\n linux-ext4\n netdev\n sparclinux\n linux-ide\n qemu-devel\n ubuntu-kernel\n yaboot\n\nSo yes, we wouldn't expect spaces, and we tend to use dashes instead of\ndots. This is essentially used as a path component in URLs.\n\nCheers,\n\n\nJeremy","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 [IPv6:2401:3900:2:1::3])\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 3xm03K0PXcz9s7h\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon,  4 Sep 2017 16:16: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 3xm03J4RSPzDqmT\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon,  4 Sep 2017 16:16:12 +1000 (AEST)","from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2])\n\t(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3xm03518f2zDqkX\n\tfor <patchwork@lists.ozlabs.org>;\n\tMon,  4 Sep 2017 16:16:01 +1000 (AEST)","from authenticated.ozlabs.org (localhost [127.0.0.1])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPSA id 3xm0345MQZz9s7f;\n\tMon,  4 Sep 2017 16:16:00 +1000 (AEST)"],"Authentication-Results":["ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tsecure) header.d=ozlabs.org header.i=@ozlabs.org header.b=\"wVmoqAH9\";\n\tdkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tsecure) header.d=ozlabs.org header.i=@ozlabs.org header.b=\"wVmoqAH9\";\n\tdkim-atps=neutral","lists.ozlabs.org; dkim=pass (2048-bit key;\n\tsecure) header.d=ozlabs.org header.i=@ozlabs.org header.b=\"wVmoqAH9\"; \n\tdkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; \n\tt=1504505760; bh=p/BWnky2ITb4N7+W6+DQA6ooQDSKZUCUytJAd5chA84=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=wVmoqAH9SF+M0awe1P/rTpzLGUv0Gg6aKDytaBE7UiS1ikbfUwaPowsDi+tob1U8J\n\tQSZx0xl7TxikqAwZDtcPSONAJqLB0RIvlE9f+c/k7SGrP9etZyn/MSaokrssy/J1p/\n\truZkJP8o7Ph+PyI8s/ZLvyuR3o3e4gf7vUxHYHnsO2U8hXz7uOvB571tfeM0u8OEg7\n\tHnga1xuxaMH3fJF079U3xOAFQf64fqz51SegxBJi6EfJSTwWzEZpwvnjod+1b0AGSr\n\tE9of9Rsi+IRLdCeN2Xi4flPJKnQDQlEl/KPX6Qxk3YL8FKIkeadgnwFrgu7LNV/bwl\n\t6vcMLgAEnqEMA==","Subject":"Re: [PATCH] REST: Filter projects by 'linkname', not 'name'","To":"Daniel Axtens <dja@axtens.net>, Stephen Finucane <stephen@that.guru>,\n\tpatchwork@lists.ozlabs.org","References":"<20170831084851.9633-1-stephen@that.guru>\n\t<874lsj4ydv.fsf@linkitivity.dja.id.au>","From":"Jeremy Kerr <jk@ozlabs.org>","Message-ID":"<e7efee26-d0f9-a4a0-711f-23c40f240385@ozlabs.org>","Date":"Mon, 4 Sep 2017 16:16:00 +1000","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-Version":"1.0","In-Reply-To":"<874lsj4ydv.fsf@linkitivity.dja.id.au>","Content-Language":"en-AU","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>","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>"}},{"id":1762524,"web_url":"http://patchwork.ozlabs.org/comment/1762524/","msgid":"<1504514547.4943.15.camel@that.guru>","list_archive_url":null,"date":"2017-09-04T08:42:27","subject":"Re: [PATCH] REST: Filter projects by 'linkname', not 'name'","submitter":{"id":69991,"url":"http://patchwork.ozlabs.org/api/people/69991/","name":"Stephen Finucane","email":"stephen@that.guru"},"content":"On Mon, 2017-09-04 at 16:16 +1000, Jeremy Kerr wrote:\n> Hi Dnaiel,\n> \n> > I was just reading though this before applying it when it occurred to\n> > me:\n> > >          except ValueError:\n> > > -            filters = {'name__iexact': ' '.join(value.split('-'))}\n> > > +            filters = {'linkname__iexact': ' '.join(value.split('-'))}\n> > \n> > Surely a linkname shouldn't have spaces in it? It'd be of the form\n> > foo.bar.org, right?\n> \n> patchwork=# select linkname from patchwork_project limit 10;\n>      linkname\n> -------------------\n>  cbe-oss-dev\n>  linux-mtd\n>  linuxppc-embedded\n>  linux-ext4\n>  netdev\n>  sparclinux\n>  linux-ide\n>  qemu-devel\n>  ubuntu-kernel\n>  yaboot\n> \n> So yes, we wouldn't expect spaces, and we tend to use dashes instead of\n> dots. This is essentially used as a path component in URLs.\n\nYup, I wouldn't expect to see any spaces. If this isn't already forced\nsomewhere, we should probably add a validator to do so. For now though, feel\nfree to fix this bit when you merge.\n\nStephen","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 3xm3Sq66j9z9s7m\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon,  4 Sep 2017 18:50:03 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xm3Sq48g4zDqmT\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon,  4 Sep 2017 18:50:03 +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 3xm3Sh5sHCzDqjv\n\tfor <patchwork@lists.ozlabs.org>;\n\tMon,  4 Sep 2017 18:49:56 +1000 (AEST)","from relay.mailchannels.net (localhost [127.0.0.1])\n\tby relay.mailchannels.net (Postfix) with ESMTP id BCC325C8088;\n\tMon,  4 Sep 2017 08:42:32 +0000 (UTC)","from one.mxroute.com (unknown [100.96.129.223])\n\t(Authenticated sender: mxroute)\n\tby relay.mailchannels.net (Postfix) with ESMTPA id 641115C7EA6;\n\tMon,  4 Sep 2017 08:42:31 +0000 (UTC)","from one.mxroute.com (one-outgoing.mxroute.com [172.20.67.103])\n\t(using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384)\n\tby 0.0.0.0:2500 (trex/5.9.14); Mon, 04 Sep 2017 08:42:32 +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=\"bIYziAB2\"; 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=\"bIYziAB2\"; dkim-atps=neutral","ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=that.guru\n\t(client-ip=23.83.209.52; helo=duck.birch.relay.mailchannels.net;\n\tenvelope-from=stephen@that.guru; receiver=<UNKNOWN>)","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=\"bIYziAB2\"; 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-Attack-Versed":"509546286c70cd78_1504514552572_4268183222","X-MC-Loop-Signature":"1504514552572:1974895089","X-MC-Ingress-Time":"1504514552572","DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru;\n\ts=default;\n\th=Content-Transfer-Encoding:Mime-Version:Content-Type:References:\n\tIn-Reply-To:Date:To:From:Subject:Message-ID:Sender:Reply-To:Cc:Content-ID:\n\tContent-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n\t:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:\n\tList-Post:List-Owner:List-Archive;\n\tbh=jP9rLOKWiWhTyRgwOV9ruXvSiuFpJHHa1ZGCUsWg9L0=;\n\tb=bIYziAB2kkm4hjtDMzTc1oZ+AY\n\t5H61HADZOe8J7VJM9USyT1zC5g/zXGuuS6pEiugvLM/pzOvckxnVuluy6/5qEKYNMhkdAbwOLQSpP\n\tm9IDBNkC3ooGKgWIMVx5vKP/hMRLdY3aKX6HV3vFDZJjtl6yQp+MW4uIDktZ8KKPA0s/p60ljxv27\n\t1WWCiNtTnYff9y9AZo4eDorxryBii/zpUCOSDX8K2KoEs1W2NTt0Zwaq6bLdwopvzH+OiloiKPJDX\n\ttUciBrgpmDvOqgDBENHdG3YZp4V0sB3F+E/hlNQk1L1aIK1fGHROY5adL5uSW8zDi6/gnGtyPa/x/\n\tDuyOutKQ==;","Message-ID":"<1504514547.4943.15.camel@that.guru>","Subject":"Re: [PATCH] REST: Filter projects by 'linkname', not 'name'","From":"Stephen Finucane <stephen@that.guru>","To":"Jeremy Kerr <jk@ozlabs.org>, Daniel Axtens <dja@axtens.net>, \n\tpatchwork@lists.ozlabs.org","Date":"Mon, 04 Sep 2017 09:42:27 +0100","In-Reply-To":"<e7efee26-d0f9-a4a0-711f-23c40f240385@ozlabs.org>","References":"<20170831084851.9633-1-stephen@that.guru>\n\t<874lsj4ydv.fsf@linkitivity.dja.id.au>\n\t<e7efee26-d0f9-a4a0-711f-23c40f240385@ozlabs.org>","X-Mailer":"Evolution 3.24.5 (3.24.5-1.fc26) ","Mime-Version":"1.0","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>","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>"}},{"id":1763485,"web_url":"http://patchwork.ozlabs.org/comment/1763485/","msgid":"<87pob58629.fsf@linkitivity.dja.id.au>","list_archive_url":null,"date":"2017-09-05T16:26:54","subject":"Re: [PATCH] REST: Filter projects by 'linkname', not 'name'","submitter":{"id":65792,"url":"http://patchwork.ozlabs.org/api/people/65792/","name":"Daniel Axtens","email":"dja@axtens.net"},"content":"Hi Stephen,\n\nMerged to master     at 174de19d41d76f8387027e789e5975fc078f2d08\nMerged to stable/2.0 at b23f206b941694a03bf3d0a94fcbdb4f3d146f85\n\nThanks!\n\nRegards,\nDaniel\n\nStephen Finucane <stephen@that.guru> writes:\n\n> Based on a report on the OVS mailing list, it appears that projects are\n> being filtered on the 'Project.name' field instead of the\n> 'Project.linkname' field. Correct this and add regression tests to\n> prevent it happening again.\n>\n> Signed-off-by: Stephen Finucane <stephen@that.guru>\n> Fixes: 08b2115 (\"REST: Allow filtering by both project ID and linkname\")\n> Closes-bug: #117 (\"Projects are filtered on the wrong field\")\n> Cc: Daniel Axtens <dja@axtens.net>\n> ---\n> daxtens - if you've time (and this looks good), you might handle the\n> merge and backport part of this. Everything about the latter should be\n> documented in enough detail:\n>\n>   https://patchwork.readthedocs.io/en/latest/development/releasing/#backporting\n>\n> Feel 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(-)\n>\n> diff --git a/patchwork/api/filters.py b/patchwork/api/filters.py\n> index 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)\n> diff --git a/patchwork/tests/test_rest_api.py b/patchwork/tests/test_rest_api.py\n> index 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> -- \n> 2.13.5","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 3xmsYk3Zklz9s7C\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  6 Sep 2017 02:27:06 +1000 (AEST)","from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 3xmsYk2NW3zDrJd\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  6 Sep 2017 02:27:06 +1000 (AEST)","from mail-pg0-x22a.google.com (mail-pg0-x22a.google.com\n\t[IPv6:2607:f8b0:400e:c05::22a])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits)) (No client certificate requested)\n\tby lists.ozlabs.org (Postfix) with ESMTPS id 3xmsYd0RXVzDqnQ\n\tfor <patchwork@lists.ozlabs.org>;\n\tWed,  6 Sep 2017 02:27:00 +1000 (AEST)","by mail-pg0-x22a.google.com with SMTP id 188so7079535pgb.2\n\tfor <patchwork@lists.ozlabs.org>;\n\tTue, 05 Sep 2017 09:27:00 -0700 (PDT)","from localhost (124-171-202-56.dyn.iinet.net.au. [124.171.202.56])\n\tby smtp.gmail.com with ESMTPSA id\n\tt16sm1987893pfj.117.2017.09.05.09.26.57\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tTue, 05 Sep 2017 09:26:57 -0700 (PDT)"],"Authentication-Results":["ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"qa/IijrR\"; dkim-atps=neutral","lists.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"qa/IijrR\"; dkim-atps=neutral","ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=axtens.net\n\t(client-ip=2607:f8b0:400e:c05::22a; helo=mail-pg0-x22a.google.com;\n\tenvelope-from=dja@axtens.net; receiver=<UNKNOWN>)","lists.ozlabs.org; dkim=pass (1024-bit key;\n\tunprotected) header.d=axtens.net header.i=@axtens.net\n\theader.b=\"qa/IijrR\"; dkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google;\n\th=from:to:cc:subject:in-reply-to:references:date:message-id\n\t:mime-version; bh=OcVIFxHjMNdnARbgQio4uTkQuaqfmIIaXsXc5sNZZ90=;\n\tb=qa/IijrRJ2k0/+d88E7pd3Peg9J1HWDGWdHWnNwRQC7cCGowvuGZfWHnpenv37P2LP\n\tt+kV5o91yf0RSFP+8/R8M/6F7f6GF5Qn0lvaVjf6wslBddmnurlmBdi9pseVLwIb8EIY\n\tQWGIfAjf9VPTGnBKmcgOnQMemoldXxvBYWKqU=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date\n\t:message-id:mime-version;\n\tbh=OcVIFxHjMNdnARbgQio4uTkQuaqfmIIaXsXc5sNZZ90=;\n\tb=l8cEZFjKQIZ/YTfwCPnz211t8H+jALcXCtZw88DSPWKJkGFO+iVxStCeA9VPIsJb3Y\n\tO9ERN0ZXty/0QveQlX7nWypqaW2DdcIc89rgdQmL7kW/37FojHSNCUqTHLV9oRiwjiPh\n\t4YHV8ce08MKRaCc1TAklXBFVo1r4DMhh2TaMmaE/0TTFpN4eoKUT4F344zFKUO1HDWnr\n\tjygsOiSmdL01+YVefu0lItgH6Z6/sP0Qzw+aPhbjE7H3U9D516DrWO40GuLwJ68bqAYF\n\tcQBvftU/FIwzSRwL5m6HqeQHkKibiwv+sQUYy7scRy24LW/z9XJztIUtnXkdjRwko7ZL\n\tMgKA==","X-Gm-Message-State":"AHPjjUiEgsikdeNvy7WO/NezQjXIPCmm2eLzh+4C/RnDK4H4Dic98Hkd\n\tVP8jEjaqsjs4pwi89n+UmQ==","X-Google-Smtp-Source":"ADKCNb7rQSpaPzbuJcE3lHos11L4GNDbxxi++zkyW1ySfRHvkemVxHwFzuvqGgcFF8uRgsJyA3jVnA==","X-Received":"by 10.98.155.87 with SMTP id r84mr4384583pfd.66.1504628818276;\n\tTue, 05 Sep 2017 09:26:58 -0700 (PDT)","From":"Daniel Axtens <dja@axtens.net>","To":"Stephen Finucane <stephen@that.guru>, patchwork@lists.ozlabs.org","Subject":"Re: [PATCH] REST: Filter projects by 'linkname', not 'name'","In-Reply-To":"<20170831084851.9633-1-stephen@that.guru>","References":"<20170831084851.9633-1-stephen@that.guru>","Date":"Wed, 06 Sep 2017 02:26:54 +1000","Message-ID":"<87pob58629.fsf@linkitivity.dja.id.au>","MIME-Version":"1.0","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>","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>"}}]