From patchwork Tue Oct 30 11:31:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 990768 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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kqFK6Hhhz9s7W for ; Tue, 30 Oct 2018 22:37:09 +1100 (AEDT) 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="DRzat5hG"; 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 42kqFK4BRYzDr4R for ; Tue, 30 Oct 2018 22:37:09 +1100 (AEDT) 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="DRzat5hG"; 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.17; helo=relay017.mxrelay.co; 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="DRzat5hG"; dkim-atps=neutral Received: from relay017.mxrelay.co (relay017.mxrelay.co [185.234.75.17]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42kq860T58zDrhk for ; Tue, 30 Oct 2018 22:32:38 +1100 (AEDT) Received: from filter001.mxrelay.co (filter001.mxrelay.co [64.52.23.203]) by relay017.mxrelay.co (Postfix) with ESMTP id 80AFF42C61 for ; Tue, 30 Oct 2018 11:32:05 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter001.mxrelay.co (Postfix) with ESMTPS id AA7D5100065 for ; Tue, 30 Oct 2018 11:32:04 +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=gmOmgTU9uW4DKUt9lVxx0HczLBHfIDtYWZk8fB63k2E=; b=DRzat5hGyavrfsfqmemDQ8/u8a bHBezF1tYm4rH2VqN6KIXg7dO3Srmi2t1ADSaySMHcOIGbQcZHf/KxfPjsGx1rqXi9x2zzhNJ202M S5w4O+KJeKjC+NxVb5CytRDl/shj8isTGTO1wdaBwbstD928qZxuKy5oS4HnzFd/slqUf898V84WO nszQAGMTtoOfQJphtSrGXwcq2Sjzmk20Bzj2xDeOGiIen8yZznftOdrogMhpQkENLRZDen7E04xiN znJxTpWpsa0LoQOsGqhXUxayyv9orecas8YVeuS8YvGbIanZF8djTt0peSkT3GNC0FATXg/NBREyP /wjxXFYA==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 08/13] tests: Add 'store_samples' decorator to 'test_series' Date: Tue, 30 Oct 2018 11:31:48 +0000 Message-Id: <20181030113153.7855-9-stephen@that.guru> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181030113153.7855-1-stephen@that.guru> References: <20181030113153.7855-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" Signed-off-by: Stephen Finucane --- patchwork/tests/api/test_series.py | 65 +++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/patchwork/tests/api/test_series.py b/patchwork/tests/api/test_series.py index 21ce2547..b377880a 100644 --- a/patchwork/tests/api/test_series.py +++ b/patchwork/tests/api/test_series.py @@ -8,6 +8,7 @@ import unittest from django.conf import settings from django.urls import reverse +from patchwork.tests.api import utils from patchwork.tests.utils import create_cover from patchwork.tests.utils import create_maintainer from patchwork.tests.utils import create_patch @@ -61,53 +62,77 @@ class TestSeriesAPI(APITestCase): self.assertEqual(series_obj.patches.count(), len(series_json['patches'])) - def test_list(self): - """Validate we can list series.""" + def test_list_empty(self): + """List series when none are present.""" resp = self.client.get(self.api_url()) self.assertEqual(status.HTTP_200_OK, resp.status_code) self.assertEqual(0, len(resp.data)) + def _create_series(self): project_obj = create_project(linkname='myproject') person_obj = create_person(email='test@example.com') series_obj = create_series(project=project_obj, submitter=person_obj) create_cover(series=series_obj) create_patch(series=series_obj) - # anonymous users + return series_obj + + def test_list_anonymous(self): + """List patches as anonymous user.""" + series = self._create_series() + resp = self.client.get(self.api_url()) self.assertEqual(status.HTTP_200_OK, resp.status_code) self.assertEqual(1, len(resp.data)) series_rsp = resp.data[0] - self.assertSerialized(series_obj, series_rsp) + self.assertSerialized(series, series_rsp) - # authenticated user + @utils.store_samples('series-list') + def test_list_authenticated(self): + """List series as an authenticated user.""" + series = self._create_series() user = create_user() + self.client.force_authenticate(user=user) resp = self.client.get(self.api_url()) self.assertEqual(status.HTTP_200_OK, resp.status_code) self.assertEqual(1, len(resp.data)) series_rsp = resp.data[0] - self.assertSerialized(series_obj, series_rsp) + self.assertSerialized(series, series_rsp) + + def test_list_filter_project(self): + """Filter series by project.""" + series = self._create_series() - # test filtering by project resp = self.client.get(self.api_url(), {'project': 'myproject'}) - self.assertEqual([series_obj.id], [x['id'] for x in resp.data]) + self.assertEqual([series.id], [x['id'] for x in resp.data]) + resp = self.client.get(self.api_url(), {'project': 'invalidproject'}) self.assertEqual(0, len(resp.data)) - # test filtering by owner, both ID and email - resp = self.client.get(self.api_url(), {'submitter': person_obj.id}) - self.assertEqual([series_obj.id], [x['id'] for x in resp.data]) + def test_list_filter_owner(self): + """Filter series by owner.""" + series = self._create_series() + submitter = series.submitter + + resp = self.client.get(self.api_url(), {'submitter': submitter.id}) + self.assertEqual([series.id], [x['id'] for x in resp.data]) + resp = self.client.get(self.api_url(), { 'submitter': 'test@example.com'}) - self.assertEqual([series_obj.id], [x['id'] for x in resp.data]) + self.assertEqual([series.id], [x['id'] for x in resp.data]) + resp = self.client.get(self.api_url(), { 'submitter': 'test@example.org'}) self.assertEqual(0, len(resp.data)) - def test_list_old_version(self): - """Validate that newer fields are dropped for older API versions.""" - create_series() + @utils.store_samples('series-list-1-0') + def test_list_version_1_0(self): + """List patches using API v1.0. + + Validate that newer fields are dropped for older API versions. + """ + self._create_series() resp = self.client.get(self.api_url(version='1.0')) self.assertEqual(status.HTTP_200_OK, resp.status_code) @@ -115,17 +140,19 @@ class TestSeriesAPI(APITestCase): self.assertIn('url', resp.data[0]) self.assertNotIn('web_url', resp.data[0]) + @utils.store_samples('series-detail') def test_detail(self): - """Validate we can get a specific series.""" - series = create_series() - create_cover(series=series) + """Show series.""" + series = self._create_series() resp = self.client.get(self.api_url(series.id)) self.assertEqual(status.HTTP_200_OK, resp.status_code) self.assertSerialized(series, resp.data) + @utils.store_samples('series-detail-1-0') def test_detail_version_1_0(self): - series = create_series() + """Show series using API v1.0.""" + series = self._create_series() resp = self.client.get(self.api_url(series.id, version='1.0')) self.assertIn('url', resp.data)