From nobody Tue May 13 13:12:03 2025 Delivered-To: importer2@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557925163; cv=none; d=zoho.com; s=zohoarc; b=eXBnU47EPZCCogVJG6S4p3or2pz7FgDY709VuyhAgqONMYrBr+2qxQ07XM/t08N+IKT40GMZiFZ1Ymop4iVKuRM6I7PwSylq3x8mNCbO4tcOhnPP/1GhMnfpwgC3JiEIozgoYXWdsW86q89BiJ3Uwl/J/DgrybyRTIV0K2+GlKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557925163; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=tpM11fljNDol64KH3FRGR2JgopQe5JWI95YKzX2WuRw=; b=C4VCX1VNEWtZkMmdjmbx+zDXtJgDRKdFWQOmNUZ/D+p1oXq0OGExXy+WuqauiNqYE64OFMvSOebxfHpNzacP2RtrwFtzjRDZ6F3PB28JqpeQdshgUSa9GTRXJ9cxtLjd9VAMg5qnsWlWxHc9R/sSvqu1yu76WRtR+i18mxiEGlg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557925163709330.71689713992896; Wed, 15 May 2019 05:59:23 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 85F072CD7E9; Wed, 15 May 2019 12:59:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AC785D72E; Wed, 15 May 2019 12:59:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 72FFB18089D1; Wed, 15 May 2019 12:59:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4FCxLWx012723 for ; Wed, 15 May 2019 08:59:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 442C660CDA; Wed, 15 May 2019 12:59:21 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-34.ams2.redhat.com [10.36.112.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id E86B77D4F0 for ; Wed, 15 May 2019 12:59:02 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:58:06 +0200 Message-Id: <20190515125808.27716-10-pbonzini@redhat.com> In-Reply-To: <20190515125808.27716-1-pbonzini@redhat.com> References: <20190515125808.27716-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 09/11] testing: convert test_testing to use REST API X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 15 May 2019 12:59:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" --- tests/patchewtest.py | 20 +++++++++----- tests/test_testing.py | 62 +++++++++++++++++++++---------------------- 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/tests/patchewtest.py b/tests/patchewtest.py index e58e5b9..d511954 100644 --- a/tests/patchewtest.py +++ b/tests/patchewtest.py @@ -138,13 +138,19 @@ class PatchewTestCase(dj_test.LiveServerTestCase): p.save() return p =20 - def api_login(self): - r =3D self.client.login(username=3Dself.user, password=3Dself.pass= word) - self.assertTrue(r) - - def api_call(self, method, **params): - resp =3D self.client.post('/api/%s/' % method, {"params": json.dum= ps(params)}) - return json.loads(resp.content.decode('utf-8')) if resp.content el= se None + def api_login(self, username=3DNone, password=3DNone): + username =3D username or self.user + password =3D password or self.password + user =3D User.objects.get(username=3Dusername) + resp =3D self.api_client.post(self.REST_BASE + 'users/login/', + { 'username': username, 'password': password }) + self.assertEquals(resp.status_code, 200) + self.api_client.force_authenticate(user, resp.data['key']) + + def api_logout(self): + resp =3D self.api_client.post(self.REST_BASE + 'users/logout/') + self.assertEquals(resp.status_code, 200) + self.api_client.force_authenticate(None, None) =20 def apply_and_retrieve(self, mbox, project_id, msgid): # TODO: change this to a REST import when it is added diff --git a/tests/test_testing.py b/tests/test_testing.py index 3fa912e..df155c7 100755 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -70,29 +70,27 @@ class TestingTestCase(PatchewTestCase, metaclass=3Dabc.= ABCMeta): kwargs['status'] =3D Result.SUCCESS self.modify_test_result(obj, **kwargs) =20 - def do_testing_report(self, **report): + def do_testing_report(self, passed=3DTrue, log=3DNone, is_timeout=3DFa= lse): self.api_login() - r =3D self.api_call( - "testing-get", - project=3D"QEMU", - tester=3D"dummy tester", - capabilities=3D[], - ) - report['project'] =3D r["project"] - report['identity'] =3D r["identity"] - report['test'] =3D r["test"]["name"] - report['tester'] =3D 'dummy_tester' - report['head'] =3D r["head"] - report['base'] =3D r["base"] - if 'passed' not in report: - report['passed'] =3D True - if 'log' not in report: - report['log'] =3D None - if 'is_timeout' not in report: - report['is_timeout'] =3D False - - self.api_call("testing-report", **report) - return r['identity'] + resp =3D self.api_client.post(self.PROJECT_BASE + "get-test/", { + 'tester': "dummy tester", + 'capabilities': [], + }) + self.assertEqual(resp.status_code, 200) + r =3D resp.data + data =3D { + "status": "success" if passed else 'failure', + 'data': { + "head": r["head"], + "is_timeout": is_timeout, + "tester": "dummy_tester" + } + } + if log is not None: + data['log'] =3D log + + self.api_client.put(r['result_uri'], data, format=3D'json') + return r["identity"] =20 @abc.abstractmethod def do_testing_done(self, log=3DNone, **report): @@ -104,10 +102,12 @@ class TestingTestCase(PatchewTestCase, metaclass=3Dab= c.ABCMeta): =20 def test_basic(self): self.api_login() - td =3D self.api_call("testing-get", - project=3D"QEMU", - tester=3D"dummy tester", - capabilities=3D[]) + resp =3D self.api_client.post(self.PROJECT_BASE + "get-test/", { + 'tester': "dummy tester", + 'capabilities': [], + }) + self.assertEqual(resp.status_code, 200) + td =3D resp.data self.assertIn("head", td) resp =3D self.get_test_result('a') self.assertEquals(resp.data['status'], 'running') @@ -115,11 +115,11 @@ class TestingTestCase(PatchewTestCase, metaclass=3Dab= c.ABCMeta): def test_done(self): self.do_testing_done() self.api_login() - td =3D self.api_call("testing-get", - project=3D"QEMU", - tester=3D"dummy tester", - capabilities=3D[]) - self.assertFalse(td) + resp =3D self.api_client.post(self.PROJECT_BASE + "get-test/", { + 'tester': "dummy tester", + 'capabilities': [], + }) + self.assertEqual(resp.status_code, 204) =20 def test_rest_basic(self): resp =3D self.get_test_result('a') --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel