From patchwork Tue Mar 7 19:46:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 736350 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 ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vd6cb2cXkz9sDb for ; Wed, 8 Mar 2017 06:47:11 +1100 (AEDT) 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="WnyNH38D"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3vd6cb1NQhzDqYQ for ; Wed, 8 Mar 2017 06:47:11 +1100 (AEDT) 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="WnyNH38D"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from relay1007.mymailcheap.com (relay1007.mymailcheap.com [144.217.215.67]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3vd6c35SDmzDqXr for ; Wed, 8 Mar 2017 06:46:43 +1100 (AEDT) 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="WnyNH38D"; dkim-atps=neutral Received: from filter1001.mymailcheap.com (filter1001.mymailcheap.com [158.69.67.251]) by relay1007.mymailcheap.com (Postfix) with ESMTPS id 4CB6B1E045 for ; Tue, 7 Mar 2017 14:46:40 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by filter1001.mymailcheap.com (Postfix) with ESMTP id ED1D52004A for ; Tue, 7 Mar 2017 19:46:40 +0000 (UTC) Authentication-Results: filter1001.mymailcheap.com; dkim=permerror reason="key not found" header.d=that.guru header.i=@that.guru header.b=WnyNH38D; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at filter1001.mymailcheap.com Received: from filter1001.mymailcheap.com ([127.0.0.1]) by localhost (filter1001.mymailcheap.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 36wGLjPSufru for ; Tue, 7 Mar 2017 19:46:40 +0000 (UTC) Received: from one.mxroute.com (one-outgoing.mxroute.com [23.92.70.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by filter1001.mymailcheap.com (Postfix) with ESMTPS for ; Tue, 7 Mar 2017 19:46:40 +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=pg2Yke5aCkkwTcqg6S9IkmSP641U8EUwxpUT4HtpCQA=; b=WnyNH38DBD/+DWub4wneQhPhoy 0EnW0Lf/PPQ4YnuEpx0JTkNTGwfjIjYXs55TMnJNB3hzOZavypp9EB9pk1ddyxxbx1MrU4+81CX16 VSf5f8aP/B2wrmJPZVzV2tT8zMlmwsYp4r6Y33aGuWyiYStvrq6gJNT7vrsjBi2/o3fT+QZhJJmdV 3IiZfLykmkxRI8MEtX1fMoYe4CoZrS6jbx1E42Po9FowyVBp14ZxazCdonWY6N1iBQGo/mbPZnE8M GdQf+RxKjj7dI0bY0qjmm7khtrAHrPcG6m3a5MVPdsak//KlVNyqVkzkEypAQORYV0z9ZVy1WMeJ8 DeAuhfrA==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v3 5/9] utils: Add 'bundle_to_mbox' helper Date: Tue, 7 Mar 2017 19:46:20 +0000 Message-Id: <20170307194624.21582-6-stephen@that.guru> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170307194624.21582-1-stephen@that.guru> References: <20170307194624.21582-1-stephen@that.guru> X-OutGoing-Spam-Status: No, score=-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 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" This includes unit tests to validate correct behavior and prevent regressions. Signed-off-by: Stephen Finucane Reviewed-by: Daniel Axtens --- v2: - Move code to views/utils instead - Break out other refactoring work --- patchwork/tests/test_bundles.py | 20 ++++++++++++++++++++ patchwork/views/bundle.py | 5 ++--- patchwork/views/utils.py | 12 ++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/patchwork/tests/test_bundles.py b/patchwork/tests/test_bundles.py index c185110..2e34174 100644 --- a/patchwork/tests/test_bundles.py +++ b/patchwork/tests/test_bundles.py @@ -42,6 +42,11 @@ def bundle_url(bundle): 'username': bundle.owner.username, 'bundlename': bundle.name}) +def bundle_mbox_url(bundle): + return reverse('bundle-mbox', kwargs={ + 'username': bundle.owner.username, 'bundlename': bundle.name}) + + class BundleListTest(TestCase): def setUp(self): @@ -120,6 +125,21 @@ class BundleViewTest(BundleTestBase): pos = next_pos +class BundleMboxTest(BundleTestBase): + + def test_empty_bundle(self): + response = self.client.get(bundle_mbox_url(self.bundle)) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.content, '') + + def test_non_empty_bundle(self): + self.bundle.append_patch(self.patches[0]) + + response = self.client.get(bundle_mbox_url(self.bundle)) + self.assertEqual(response.status_code, 200) + self.assertNotEqual(response.content, '') + + class BundleUpdateTest(BundleTestBase): def test_no_action(self): diff --git a/patchwork/views/bundle.py b/patchwork/views/bundle.py index 53e1b21..ef82c98 100644 --- a/patchwork/views/bundle.py +++ b/patchwork/views/bundle.py @@ -32,7 +32,7 @@ from patchwork.models import Bundle from patchwork.models import BundlePatch from patchwork.models import Project from patchwork.views import generic_list -from patchwork.views.utils import patch_to_mbox +from patchwork.views.utils import bundle_to_mbox @login_required @@ -140,8 +140,7 @@ def bundle_mbox(request, username, bundlename): response = HttpResponse(content_type='text/plain') response['Content-Disposition'] = \ 'attachment; filename=bundle-%d-%s.mbox' % (bundle.id, bundle.name) - response.write('\n'.join( - [patch_to_mbox(p) for p in bundle.ordered_patches()])) + response.write(bundle_to_mbox(bundle)) return response diff --git a/patchwork/views/utils.py b/patchwork/views/utils.py index c998647..900480b 100644 --- a/patchwork/views/utils.py +++ b/patchwork/views/utils.py @@ -104,3 +104,15 @@ def patch_to_mbox(patch): mail = mail.as_string(True) return mail + + +def bundle_to_mbox(bundle): + """Get an mbox representation of a bundle. + + Arguments: + patch: The Bundle object to convert. + + Returns: + A string for the mbox file. + """ + return '\n'.join([patch_to_mbox(p) for p in bundle.ordered_patches()])