From patchwork Tue Oct 30 11:31:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 990765 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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42kqCP4WfDz9s7W for ; Tue, 30 Oct 2018 22:35:29 +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="T9UNPTC7"; 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 42kqCP2j0HzF1PT for ; Tue, 30 Oct 2018 22:35:29 +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="T9UNPTC7"; 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.3; helo=relay-direct21.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="T9UNPTC7"; dkim-atps=neutral Received: from relay-direct21.mxroute.com (relay-direct21.mxroute.com [185.234.75.3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42kq8315wGzF1Pt for ; Tue, 30 Oct 2018 22:32:35 +1100 (AEDT) Received: from filter001.mxrelay.co (filter001.mxrelay.co [64.52.23.203]) by relay-direct21.mxroute.com (Postfix) with ESMTP id 0887A3F345 for ; Tue, 30 Oct 2018 11:32:02 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter001.mxrelay.co (Postfix) with ESMTPS id 23547100065 for ; Tue, 30 Oct 2018 11:32:01 +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=1IlmW36EebKEz7vfuRvSW0nWjbWimqHrLFwNeH5tHnI=; b=T9UNPTC7aUnezpbCSvU06nFN4q JwH2+hOLnmC4I3jQhGaH2T6lNPa+fef/qzY9MZFnAY429pqaM0g9k6Mj2eqhvi9XC+FhR1QmNAJPY Ylrbod/ih8b60oRllZX1TE/3y/geL+XP7VsRG03D7R70aThTHpTdv9KN2iGngseY2W26A94PPmkO/ rwOK/9bpx7l3jithYvrsQ+WdRsIjFjyURSaq2KbjDf/XlxusYvqg3vmPfly4QRO4uR0V7c9twqP3A 5FeOOfLRypXXj9bBm7HMgFjOfX6galU5fxYZPP/kzV49cCh1zGz1kTgqL2YzJJyg6brPkCXDa8rq1 6RT+quFA==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 04/13] tests: Add 'store_samples' decorator to 'test_people' Date: Tue, 30 Oct 2018 11:31:44 +0000 Message-Id: <20181030113153.7855-5-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_person.py | 37 +++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/patchwork/tests/api/test_person.py b/patchwork/tests/api/test_person.py index 3a89e73e..aad37a7a 100644 --- a/patchwork/tests/api/test_person.py +++ b/patchwork/tests/api/test_person.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_maintainer from patchwork.tests.utils import create_person from patchwork.tests.utils import create_user @@ -42,31 +43,49 @@ class TestPersonAPI(APITestCase): self.assertEqual(person_obj.user.id, person_json['user']['id']) - def test_list(self): - """This API requires authenticated users.""" - person = create_person() + def test_list_empty(self): + """List people when none are present.""" + # authentication is required + user = create_user(link_person=False) + + self.client.force_authenticate(user=user) + resp = self.client.get(self.api_url()) + self.assertEqual(status.HTTP_200_OK, resp.status_code) + self.assertEqual(0, len(resp.data)) + + @utils.store_samples('people-list-error-forbidden') + def test_list_anonymous(self): + """List people as anonymous user.""" + create_person() # anonymous user resp = self.client.get(self.api_url()) self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code) - # authenticated user + @utils.store_samples('people-list') + def test_list_authenticated(self): + """List people as an authenticated user.""" + person = create_person() user = create_user(link_person=False) - self.client.force_authenticate(user=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)) self.assertSerialized(person, resp.data[0]) - def test_detail(self): + @utils.store_samples('people-detail-error-forbidden') + def test_detail_anonymous(self): + """Show person as anonymous user.""" person = create_person() # anonymous user resp = self.client.get(self.api_url(person.id)) self.assertEqual(status.HTTP_403_FORBIDDEN, resp.status_code) - # authenticated, unlinked user + def test_detail_unlinked(self): + """Show unlinked person as authenticted user.""" + person = create_person() user = create_user(link_person=False) self.client.force_authenticate(user=user) @@ -74,7 +93,9 @@ class TestPersonAPI(APITestCase): self.assertEqual(status.HTTP_200_OK, resp.status_code) self.assertSerialized(person, resp.data, has_user=False) - # authenticated, linked user + @utils.store_samples('people-detail') + def test_detail_linked(self): + """Show linked person as authenticated user.""" user = create_user(link_person=True) person = user.person_set.all().first() self.client.force_authenticate(user=user)