From patchwork Fri Sep 21 17:51:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 973377 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42H1QB0Vfrz9sCS for ; Sat, 22 Sep 2018 03:52:18 +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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="fkB2r8mg"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42H1Q9241CzF3SF for ; Sat, 22 Sep 2018 03:52:17 +1000 (AEST) 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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="fkB2r8mg"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.9; helo=relay002.mxroute.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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="fkB2r8mg"; dkim-atps=neutral Received: from relay002.mxroute.com (relay002.mxroute.com [185.234.75.9]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42H1PW39f6zF3SV for ; Sat, 22 Sep 2018 03:51:43 +1000 (AEST) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay002.mxroute.com (Postfix) with ESMTP id EEA963F152 for ; Fri, 21 Sep 2018 17:51:10 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id C06D63F3BD for ; Fri, 21 Sep 2018 17:51:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=3CkNSRyXjvoks2yqKXitW2EQ56N913tZwHnJqPhS0Tk=; b=fkB2r8mgfaT6cVR4Y62m9LvusK x8W2Lt5phby8tg/tVtAmg4fN1y4ReXnzxZMtfhPkl1wXIZex8V3axNxgQCWIkRmFASS6u+BBK2tz0 +47+E5xl4PFmYJmaFA93F7UCBFPbOsp881FqUOGztrqwiNgtq0mHI4PpYywUD2T0qtARMmn6afuc+ MNNx32wcXQTtv6seaGa+WZPjNNs79iaZC9LLRif5pfOJ7jhyrd1j2QhQS5g2Z4swUYNr5pDq8v/nb EFZVA5lF2PCQFoVQOTweJJ5S4bqv6N1KOHwy1UdN0a+Jt7/y03+cCdB80ih8BUI8WjxQckrkqV95c Bp+aqCgw==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v3 1/5] tests: Add more tests for series-ified mbox views Date: Fri, 21 Sep 2018 18:51:01 +0100 Message-Id: <20180921175105.18000-2-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921175105.18000-1-stephen@that.guru> References: <20180921175105.18000-1-stephen@that.guru> 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: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Cover some testing gaps identified during the migration from a M:N to a 1:N series-patch relationship, namely: - Downloading a patch's mbox with dependencies using a numerical series ID - Downloading a series' mbox Signed-off-by: Stephen Finucane Reviewed-by: Daniel Axtens --- patchwork/tests/test_mboxviews.py | 40 ++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/patchwork/tests/test_mboxviews.py b/patchwork/tests/test_mboxviews.py index eadfd81c..9de9c762 100644 --- a/patchwork/tests/test_mboxviews.py +++ b/patchwork/tests/test_mboxviews.py @@ -17,6 +17,7 @@ from patchwork.tests.utils import create_comment from patchwork.tests.utils import create_patch from patchwork.tests.utils import create_project from patchwork.tests.utils import create_person +from patchwork.tests.utils import create_series from patchwork.tests.utils import create_series_patch from patchwork.tests.utils import create_user @@ -197,16 +198,40 @@ class MboxCommentPostcriptUnchangedTest(TestCase): class MboxSeriesDependencies(TestCase): - def test_patch_with_dependencies(self): + @staticmethod + def _create_patches(): patch_a = create_series_patch() patch_b = create_series_patch(series=patch_a.series) + return patch_a.series, patch_a, patch_b + + def test_patch_with_wildcard_series(self): + _, patch_a, patch_b = self._create_patches() + response = self.client.get('%s?series=*' % reverse( 'patch-mbox', args=[patch_b.patch.id])) self.assertContains(response, patch_a.patch.content) self.assertContains(response, patch_b.patch.content) + def test_patch_with_numeric_series(self): + series, patch_a, patch_b = self._create_patches() + + response = self.client.get('%s?series=%d' % ( + reverse('patch-mbox', args=[patch_b.patch.id]), series.id)) + + self.assertContains(response, patch_a.patch.content) + self.assertContains(response, patch_b.patch.content) + + def test_patch_with_invalid_series(self): + series, patch_a, patch_b = self._create_patches() + + for value in ('foo', str(series.id + 1)): + response = self.client.get('%s?series=%s' % ( + reverse('patch-mbox', args=[patch_b.patch.id]), value)) + + self.assertEqual(response.status_code, 404) + def test_legacy_patch(self): """Validate a patch with non-existent dependencies raises a 404.""" # we're explicitly creating a patch without a series @@ -216,3 +241,16 @@ class MboxSeriesDependencies(TestCase): 'patch-mbox', args=[patch.id])) self.assertEqual(response.status_code, 404) + + +class MboxSeries(TestCase): + + def test_series(self): + series = create_series() + patch_a = create_series_patch(series=series) + patch_b = create_series_patch(series=series) + + response = self.client.get(reverse('series-mbox', args=[series.id])) + + self.assertContains(response, patch_a.patch.content) + self.assertContains(response, patch_b.patch.content) From patchwork Fri Sep 21 17:51:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 973378 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42H1QY4DwRz9sCV for ; Sat, 22 Sep 2018 03:52:37 +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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="MMfdzspT"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42H1QY1sZ6zF3Ry for ; Sat, 22 Sep 2018 03:52:37 +1000 (AEST) 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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="MMfdzspT"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.9; helo=relay002.mxroute.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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="MMfdzspT"; dkim-atps=neutral Received: from relay002.mxroute.com (relay002.mxroute.com [185.234.75.9]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42H1PW5Y85zF3Qj for ; Sat, 22 Sep 2018 03:51:43 +1000 (AEST) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay002.mxroute.com (Postfix) with ESMTP id 4CE123FF5A for ; Fri, 21 Sep 2018 17:51:11 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 34A483F39E for ; Fri, 21 Sep 2018 17:51:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=oHu26weZ9iMemEBbhiF20XvoszGFziTObvSOZ7C01ck=; b=MMfdzspTBJH4hoxyS0El99Ec7H iSiLDlbuIDCYIHt3HWbuCFsEeIr1DHVJDL2EdTc8zilIfsgG0rDxQj6RCormAm1FZq2xFYHC8VRGB 3+nOSlf9hUISFh2bAIRBPyPTJbVkw33Jy3gg+wG6C5dnQ4XuIPbAocBKFsjcg0+F/6RzKPetNEgZl 6LZihKnEQLr3/RTXo4aOTPnTrLxS+Dd8MUvyHsW1lqZEp1IPp3HfCJ4W4dD9KWrTkFhb2CTBrwTBa zocJez3qHY4JHLot3jPS8lUnU/fPa9nnrHaDoxoPC4nMKmT9ADlFaKFMZmc1njSfgilOQppdqHaBc chIQRqEA==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v3 2/5] tests: Hardcode expected values Date: Fri, 21 Sep 2018 18:51:02 +0100 Message-Id: <20180921175105.18000-3-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921175105.18000-1-stephen@that.guru> References: <20180921175105.18000-1-stephen@that.guru> 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: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Compare against known values to ensure bugs introduced in the function are caught. Signed-off-by: Stephen Finucane Reviewed-by: Daniel Axtens --- patchwork/tests/test_series.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/patchwork/tests/test_series.py b/patchwork/tests/test_series.py index bb44e39d..ff3412e6 100644 --- a/patchwork/tests/test_series.py +++ b/patchwork/tests/test_series.py @@ -623,10 +623,6 @@ class SeriesNameTestCase(TestCase): def _parse_mail(self, mail): return parser.parse_mail(mail, self.project.listid) - @staticmethod - def _format_name(cover): - return models.Series._format_name(cover) - def test_cover_letter(self): """Cover letter name set as series name. @@ -642,7 +638,7 @@ class SeriesNameTestCase(TestCase): mbox = self._get_mbox('base-cover-letter.mbox') cover = self._parse_mail(mbox[0]) - cover_name = self._format_name(cover) + cover_name = 'A sample series' self.assertEqual(cover.series.first().name, cover_name) self._parse_mail(mbox[1]) @@ -697,7 +693,7 @@ class SeriesNameTestCase(TestCase): self.assertEqual(patch.series.first().name, patch.name) cover = self._parse_mail(mbox[2]) - self.assertEqual(cover.series.first().name, self._format_name(cover)) + self.assertEqual(cover.series.first().name, 'A sample series') mbox.close() From patchwork Fri Sep 21 17:51:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 973379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42H1R04ptnz9sCS for ; Sat, 22 Sep 2018 03:53:00 +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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="W+zKc/eR"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42H1R039HLzF3Rv for ; Sat, 22 Sep 2018 03:53:00 +1000 (AEST) 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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="W+zKc/eR"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.7; helo=relay-direct7.mxroute.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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="W+zKc/eR"; dkim-atps=neutral Received: from relay-direct7.mxroute.com (relay-direct7.mxroute.com [185.234.75.7]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42H1PZ3r7XzF3R7 for ; Sat, 22 Sep 2018 03:51:45 +1000 (AEST) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay-direct7.mxroute.com (Postfix) with ESMTP id 74CDE3F0FD for ; Fri, 21 Sep 2018 17:51:12 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 59F473F39E for ; Fri, 21 Sep 2018 17:51:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=m56TNNvY7asTFq4rsE/Pkbpn/herGo6tcnsGmIKSmwY=; b=W+zKc/eRYiz7CQndE6uQDgYNaB zwKu+N2Dk5TIIjOAd7t5srKIwZ8pNTaujdaDgH9tHjiHBQ4JQgaUD3ucYJKzQD/WAqvbp2NRV8RsW 5v7Y4brN8qtJy2KmAI9Ei5z1fg9xuslm1n4Lw5U7Xk8dWnnGG31Lsj+e286nXkw89zRvnxr0nqn7y EMvgubstB06NVaAndxGHbHv49iYZEv/gwiOED2dL0wDfhDFtTPHyPofjF8B6d9VFdity+em/3i4U6 logUStZS7pePBv+pF2VsKZSGVKupXvhkJj7fQ38yW6STaag3DCUYy+ysYJZRfO9pFkf80ubOpy1hs 9GhZ8g2Q==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v3 4/5] tests: Remove 'create_series_patch' Date: Fri, 21 Sep 2018 18:51:04 +0100 Message-Id: <20180921175105.18000-5-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921175105.18000-1-stephen@that.guru> References: <20180921175105.18000-1-stephen@that.guru> 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: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" The 'SeriesPatch' object was recently removed, but the 'create_series_patch' was retained in order to minimize the changes necessary. This can now be removed and the logic moved to the 'create_patch' and 'create_cover' functions instead. Signed-off-by: Stephen Finucane --- patchwork/tests/api/test_series.py | 12 +++---- patchwork/tests/test_events.py | 34 ++++++++++---------- patchwork/tests/test_mboxviews.py | 28 ++++++++-------- patchwork/tests/utils.py | 51 ++++++++++++++++-------------- 4 files changed, 65 insertions(+), 60 deletions(-) diff --git a/patchwork/tests/api/test_series.py b/patchwork/tests/api/test_series.py index 4d576fc0..21ce2547 100644 --- a/patchwork/tests/api/test_series.py +++ b/patchwork/tests/api/test_series.py @@ -10,10 +10,10 @@ from django.urls import reverse from patchwork.tests.utils import create_cover from patchwork.tests.utils import create_maintainer -from patchwork.tests.utils import create_project +from patchwork.tests.utils import create_patch from patchwork.tests.utils import create_person +from patchwork.tests.utils import create_project from patchwork.tests.utils import create_series -from patchwork.tests.utils import create_series_patch from patchwork.tests.utils import create_user if settings.ENABLE_REST_API: @@ -69,10 +69,9 @@ class TestSeriesAPI(APITestCase): project_obj = create_project(linkname='myproject') person_obj = create_person(email='test@example.com') - cover_obj = create_cover() series_obj = create_series(project=project_obj, submitter=person_obj) - series_obj.add_cover_letter(cover_obj) - create_series_patch(series=series_obj) + create_cover(series=series_obj) + create_patch(series=series_obj) # anonymous users resp = self.client.get(self.api_url()) @@ -118,9 +117,8 @@ class TestSeriesAPI(APITestCase): def test_detail(self): """Validate we can get a specific series.""" - cover = create_cover() series = create_series() - series.add_cover_letter(cover) + create_cover(series=series) resp = self.client.get(self.api_url(series.id)) self.assertEqual(status.HTTP_200_OK, resp.status_code) diff --git a/patchwork/tests/test_events.py b/patchwork/tests/test_events.py index bd4f9be1..7d03d65d 100644 --- a/patchwork/tests/test_events.py +++ b/patchwork/tests/test_events.py @@ -44,45 +44,46 @@ class PatchCreateTest(_BaseTestCase): def test_patch_dependencies_present_series(self): """Patch dependencies already exist.""" - series_patch = utils.create_series_patch() + series = utils.create_series() + patch = utils.create_patch(series=series) # This should raise both the CATEGORY_PATCH_CREATED and # CATEGORY_PATCH_COMPLETED events - events = _get_events(patch=series_patch.patch) + events = _get_events(patch=patch) self.assertEqual(events.count(), 2) self.assertEqual(events[0].category, Event.CATEGORY_PATCH_CREATED) - self.assertEqual(events[0].project, series_patch.patch.project) + self.assertEqual(events[0].project, patch.project) self.assertEqual(events[1].category, Event.CATEGORY_PATCH_COMPLETED) - self.assertEqual(events[1].project, series_patch.patch.project) + self.assertEqual(events[1].project, patch.project) self.assertEventFields(events[0]) self.assertEventFields(events[1]) # This shouldn't be affected by another update to the patch - series_patch.patch.commit_ref = 'aac76f0b0f8dd657ff07bb' - series_patch.patch.save() + patch.commit_ref = 'aac76f0b0f8dd657ff07bb32df369705696d4831' + patch.save() - events = _get_events(patch=series_patch.patch) + events = _get_events(patch=patch) self.assertEqual(events.count(), 2) def test_patch_dependencies_out_of_order(self): series = utils.create_series() - series_patch_3 = utils.create_series_patch(series=series, number=3) - series_patch_2 = utils.create_series_patch(series=series, number=2) + patch_3 = utils.create_patch(series=series, number=3) + patch_2 = utils.create_patch(series=series, number=2) # This should only raise the CATEGORY_PATCH_CREATED event for # both patches as they are both missing dependencies - for series_patch in [series_patch_2, series_patch_3]: - events = _get_events(patch=series_patch.patch) + for patch in [patch_2, patch_3]: + events = _get_events(patch=patch) self.assertEqual(events.count(), 1) self.assertEqual(events[0].category, Event.CATEGORY_PATCH_CREATED) self.assertEventFields(events[0]) - series_patch_1 = utils.create_series_patch(series=series, number=1) + patch_1 = utils.create_patch(series=series, number=1) # We should now see the CATEGORY_PATCH_COMPLETED event for all patches # as the dependencies for all have been met - for series_patch in [series_patch_1, series_patch_2, series_patch_3]: - events = _get_events(patch=series_patch.patch) + for patch in [patch_1, patch_2, patch_3]: + events = _get_events(patch=patch) self.assertEqual(events.count(), 2) self.assertEqual(events[0].category, Event.CATEGORY_PATCH_CREATED) self.assertEqual(events[1].category, @@ -91,11 +92,12 @@ class PatchCreateTest(_BaseTestCase): self.assertEventFields(events[1]) def test_patch_dependencies_missing(self): - series_patch = utils.create_series_patch(number=2) + series = utils.create_series() + patch = utils.create_patch(series=series, number=2) # This should only raise the CATEGORY_PATCH_CREATED event as # there is a missing dependency (patch 1) - events = _get_events(patch=series_patch.patch) + events = _get_events(patch=patch) self.assertEqual(events.count(), 1) self.assertEqual(events[0].category, Event.CATEGORY_PATCH_CREATED) self.assertEventFields(events[0]) diff --git a/patchwork/tests/test_mboxviews.py b/patchwork/tests/test_mboxviews.py index 9de9c762..5c29226b 100644 --- a/patchwork/tests/test_mboxviews.py +++ b/patchwork/tests/test_mboxviews.py @@ -18,7 +18,6 @@ from patchwork.tests.utils import create_patch from patchwork.tests.utils import create_project from patchwork.tests.utils import create_person from patchwork.tests.utils import create_series -from patchwork.tests.utils import create_series_patch from patchwork.tests.utils import create_user @@ -200,28 +199,29 @@ class MboxSeriesDependencies(TestCase): @staticmethod def _create_patches(): - patch_a = create_series_patch() - patch_b = create_series_patch(series=patch_a.series) + series = create_series() + patch_a = create_patch(series=series) + patch_b = create_patch(series=series) - return patch_a.series, patch_a, patch_b + return series, patch_a, patch_b def test_patch_with_wildcard_series(self): _, patch_a, patch_b = self._create_patches() response = self.client.get('%s?series=*' % reverse( - 'patch-mbox', args=[patch_b.patch.id])) + 'patch-mbox', args=[patch_b.id])) - self.assertContains(response, patch_a.patch.content) - self.assertContains(response, patch_b.patch.content) + self.assertContains(response, patch_a.content) + self.assertContains(response, patch_b.content) def test_patch_with_numeric_series(self): series, patch_a, patch_b = self._create_patches() response = self.client.get('%s?series=%d' % ( - reverse('patch-mbox', args=[patch_b.patch.id]), series.id)) + reverse('patch-mbox', args=[patch_b.id]), series.id)) - self.assertContains(response, patch_a.patch.content) - self.assertContains(response, patch_b.patch.content) + self.assertContains(response, patch_a.content) + self.assertContains(response, patch_b.content) def test_patch_with_invalid_series(self): series, patch_a, patch_b = self._create_patches() @@ -247,10 +247,10 @@ class MboxSeries(TestCase): def test_series(self): series = create_series() - patch_a = create_series_patch(series=series) - patch_b = create_series_patch(series=series) + patch_a = create_patch(series=series) + patch_b = create_patch(series=series) response = self.client.get(reverse('series-mbox', args=[series.id])) - self.assertContains(response, patch_a.patch.content) - self.assertContains(response, patch_b.patch.content) + self.assertContains(response, patch_a.content) + self.assertContains(response, patch_b.content) diff --git a/patchwork/tests/utils.py b/patchwork/tests/utils.py index 0c3bbff2..c8acda40 100644 --- a/patchwork/tests/utils.py +++ b/patchwork/tests/utils.py @@ -149,6 +149,12 @@ def create_patch(**kwargs): """Create 'Patch' object.""" num = Patch.objects.count() + # NOTE(stephenfin): Even though we could simply pass 'series' into the + # constructor, we don't as that's not what we do in the parser and not what + # our signal handlers (for events) expect + series = kwargs.pop('series', None) + number = kwargs.pop('number', None) + values = { 'submitter': create_person() if 'submitter' not in kwargs else None, 'delegate': None, @@ -161,16 +167,31 @@ def create_patch(**kwargs): 'diff': SAMPLE_DIFF, } values.update(kwargs) + if 'patch_project' not in values: values['patch_project'] = values['project'] - return Patch.objects.create(**values) + patch = Patch.objects.create(**values) + + if series: + number = number or series.patches.count() + 1 + series.add_patch(patch, number) + + return patch def create_cover(**kwargs): """Create 'CoverLetter' object.""" num = CoverLetter.objects.count() + # NOTE(stephenfin): Despite first appearances, passing 'series' to the + # 'create' function doesn't actually cause the relationship to be created. + # This is probably a bug in Django. However, it's convenient to do so we + # emulate that here. For more info, see [1]. + # + # [1] https://stackoverflow.com/q/43119575/ + series = kwargs.pop('series', None) + values = { 'submitter': create_person() if 'person' not in kwargs else None, 'project': create_project() if 'project' not in kwargs else None, @@ -181,7 +202,12 @@ def create_cover(**kwargs): } values.update(kwargs) - return CoverLetter.objects.create(**values) + cover = CoverLetter.objects.create(**values) + + if series: + series.add_cover_letter(cover) + + return cover def create_comment(**kwargs): @@ -226,27 +252,6 @@ def create_series(**kwargs): return Series.objects.create(**values) -def create_series_patch(**kwargs): - """Create 'Patch' object and associate with a series.""" - # TODO(stephenfin): Remove this and all callers - num = 1 if 'series' not in kwargs else kwargs['series'].patches.count() + 1 - if 'number' in kwargs: - num = kwargs['number'] - - series = create_series() if 'series' not in kwargs else kwargs['series'] - patch = create_patch() if 'patch' not in kwargs else kwargs['patch'] - - series.add_patch(patch, num) - - class SeriesPatch(object): - """Simple wrapper to avoid needing to update all tests at once.""" - def __init__(self, series, patch): - self.series = series - self.patch = patch - - return SeriesPatch(series=series, patch=patch) - - def create_series_reference(**kwargs): """Create 'SeriesReference' object.""" values = { From patchwork Fri Sep 21 17:51:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 973380 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42H1RS1SJFz9sCS for ; Sat, 22 Sep 2018 03:53:24 +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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="sadLo+Vz"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42H1RR6kN5zF3SF for ; Sat, 22 Sep 2018 03:53:23 +1000 (AEST) 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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="sadLo+Vz"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.9; helo=relay002.mxroute.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" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="sadLo+Vz"; dkim-atps=neutral Received: from relay002.mxroute.com (relay002.mxroute.com [185.234.75.9]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42H1PZ6X4wzF3R1 for ; Sat, 22 Sep 2018 03:51:45 +1000 (AEST) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay002.mxroute.com (Postfix) with ESMTP id 368063F0F1 for ; Fri, 21 Sep 2018 17:51:13 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 21AD53F39E for ; Fri, 21 Sep 2018 17:51:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Bgq/ByNA4XmJSmrpKvNBMXxgiKWcoQ1rffJqxBWmas4=; b=sadLo+Vza/7J8wESIzPFC2lmtU /ZYpaDa+adFrMSROevWGjXDcXOJTSWijwvs1kGWZw+F69YK7e7Nd3BDUgWVFu7IvC9Z6dnpSzgQQG 0jebl2R27tLBtVNqLL6BJ83/Y/mGlTSLS6tbS334wOEyWR1qC9IrPfhMZPGjym8yhCJ58JMfjpW70 K7+uRTNC+dowa0izN6S3L943QCVHCw1Bh5mXEMHtCgcRBKLnhfZdc3VuIj1SI5PVaWzuIFr8oRtYf T/lJHndMxkS2XGGcggtU+w80xBjD3eFfYpCDgU1ef4q9Oy3N2OK7c0FYMBZ2BnahL5DGQAHa5Kfte pi2ifGrw==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v3 5/5] views: Add support for boolean 'series' parameters Date: Fri, 21 Sep 2018 18:51:05 +0100 Message-Id: <20180921175105.18000-6-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921175105.18000-1-stephen@that.guru> References: <20180921175105.18000-1-stephen@that.guru> 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: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Previously, we allowed users to download patch mboxes with dependencies included using a 'series' parameter. This accepted either a numeric ID, corresponding to the ID of the patch series that dependencies should be included from, or a wildcard value ('*'). /patch/{patchID}/mbox/?series=123 /patch/{patchID}/mbox/?series=* With switch to a 1:N series-patch relationship, this is clearly unnecessary now but must be retained to avoid breaking users. However, that doesn't mean we can't things a little clearer. Add support for boolean parameters, which make more sense for this kind of relationship: /patch/{patchID}/mbox/?series=true /patch/{patchID}/mbox/?series=1 /patch/{patchID}/mbox/?series=false /patch/{patchID}/mbox/?series=0 Signed-off-by: Stephen Finucane --- TODO: I'm not sure if I should do this or introduce a new parameter (maybe 'dependencies'?). Thoughts? --- patchwork/tests/test_mboxviews.py | 17 +++++++++++++++++ patchwork/views/patch.py | 2 +- patchwork/views/utils.py | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/patchwork/tests/test_mboxviews.py b/patchwork/tests/test_mboxviews.py index 5c29226b..8f6a51f2 100644 --- a/patchwork/tests/test_mboxviews.py +++ b/patchwork/tests/test_mboxviews.py @@ -223,6 +223,23 @@ class MboxSeriesDependencies(TestCase): self.assertContains(response, patch_a.content) self.assertContains(response, patch_b.content) + def test_patch_with_boolean_series(self): + _, patch_a, patch_b = self._create_patches() + + for value in ('true', '1'): + response = self.client.get('%s?series=%s' % ( + reverse('patch-mbox', args=[patch_b.id]), value)) + + self.assertContains(response, patch_a.content) + self.assertContains(response, patch_b.content) + + for value in ('false', '0'): + response = self.client.get('%s?series=%s' % ( + reverse('patch-mbox', args=[patch_b.id]), value)) + + self.assertNotContains(response, patch_a.content) + self.assertContains(response, patch_b.content) + def test_patch_with_invalid_series(self): series, patch_a, patch_b = self._create_patches() diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index 277b2816..446a0c4b 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -130,7 +130,7 @@ def patch_mbox(request, patch_id): series_id = request.GET.get('series') response = HttpResponse(content_type='text/plain') - if series_id: + if series_id and series_id.lower() not in ('false', '0'): if not patch.series: raise Http404('Patch does not have an associated series. This is ' 'because the patch was processed with an older ' diff --git a/patchwork/views/utils.py b/patchwork/views/utils.py index 3c5d2982..d6f54ea6 100644 --- a/patchwork/views/utils.py +++ b/patchwork/views/utils.py @@ -127,7 +127,7 @@ def series_patch_to_mbox(patch, series_id): Returns: A string for the mbox file. """ - if series_id != '*': + if series_id.lower() not in ('*', 'true', '1'): try: series_id = int(series_id) except ValueError: