From nobody Thu Apr 18 20:38:59 2024 Delivered-To: importer@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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1543442192750603.3288335050374; Wed, 28 Nov 2018 13:56:32 -0800 (PST) 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 73328306B58A; Wed, 28 Nov 2018 21:56:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 632E95EDE4; Wed, 28 Nov 2018 21:56:31 +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 56C523F7CB; Wed, 28 Nov 2018 21:56:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wASLuU3E003649 for ; Wed, 28 Nov 2018 16:56:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4D0C4103BAB9; Wed, 28 Nov 2018 21:56:30 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-23.gru2.redhat.com [10.97.116.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id B078B105705B; Wed, 28 Nov 2018 21:56:27 +0000 (UTC) From: Caio Carrara To: patchew-devel@redhat.com Date: Wed, 28 Nov 2018 19:56:16 -0200 Message-Id: <20181128215617.9284-2-ccarrara@redhat.com> In-Reply-To: <20181128215617.9284-1-ccarrara@redhat.com> References: <20181128215617.9284-1-ccarrara@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 1/2] Apply PEP8 to www apps and urls modules 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.41]); Wed, 28 Nov 2018 21:56:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The adjustments in this change were basically indentation and line breaks. Signed-off-by: Caio Carrara --- www/apps.py | 2 -- www/urls.py | 40 ++++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/www/apps.py b/www/apps.py index 82a38c9..ddae842 100644 --- a/www/apps.py +++ b/www/apps.py @@ -8,8 +8,6 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 - - from django.apps import AppConfig =20 =20 diff --git a/www/urls.py b/www/urls.py index 21b945c..b64c1c8 100644 --- a/www/urls.py +++ b/www/urls.py @@ -17,23 +17,23 @@ urlpatterns =3D [] dispatch_module_hook("www_url_hook", urlpatterns=3Durlpatterns) =20 urlpatterns +=3D [ - url( - '^login/$', - auth_views.login, - {'template_name': 'login.html'}, - name=3D"login" - ), - url( - '^logout/$', - auth_views.logout, - name=3D"logout" - ), - url(r"^search$", views.view_search, name=3D"search"), - url(r"^search-help$", views.view_search_help, name=3D"search_help"= ), - url(r"^(?P[^/]*)/$", views.view_series_list, name=3D"seri= es_list"), - url(r"^(?P[^/]*)/info$", views.view_project_detail, name= =3D"project_detail"), - url(r"^(?P[^/]*)/(?P[^/]*)/$", views.view_ser= ies_detail, name=3D"series_detail"), - url(r"^(?P[^/]*)/(?P[^/]*)/(?P[^/]= *)/$", views.view_series_message, name=3D"series_message"), - url(r"^(?P[^/]*)/(?P[^/]*)/mbox$", views.view= _mbox, name=3D"mbox"), - url(r"^$", views.view_project_list, name=3D"project_list"), - ] + url( + '^login/$', + auth_views.login, + {'template_name': 'login.html'}, + name=3D"login" + ), + url( + '^logout/$', + auth_views.logout, + name=3D"logout" + ), + url(r"^search$", views.view_search, name=3D"search"), + url(r"^search-help$", views.view_search_help, name=3D"search_help"), + url(r"^(?P[^/]*)/$", views.view_series_list, name=3D"series_l= ist"), + url(r"^(?P[^/]*)/info$", views.view_project_detail, name=3D"p= roject_detail"), + url(r"^(?P[^/]*)/(?P[^/]*)/$", views.view_series_= detail, name=3D"series_detail"), + url(r"^(?P[^/]*)/(?P[^/]*)/(?P[^/]*)/$= ", views.view_series_message, name=3D"series_message"), + url(r"^(?P[^/]*)/(?P[^/]*)/mbox$", views.view_mbo= x, name=3D"mbox"), + url(r"^$", views.view_project_list, name=3D"project_list"), +] --=20 2.19.2 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel From nobody Thu Apr 18 20:38:59 2024 Delivered-To: importer@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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1543442196058250.02876419234394; Wed, 28 Nov 2018 13:56:36 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AD16309B6D4; Wed, 28 Nov 2018 21:56:34 +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 81E4D9F7B; Wed, 28 Nov 2018 21:56:34 +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 6AF7F181B9E4; Wed, 28 Nov 2018 21:56:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wASLuWXG003661 for ; Wed, 28 Nov 2018 16:56:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id B4A64103BAB2; Wed, 28 Nov 2018 21:56:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-23.gru2.redhat.com [10.97.116.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id C97D31001943; Wed, 28 Nov 2018 21:56:30 +0000 (UTC) From: Caio Carrara To: patchew-devel@redhat.com Date: Wed, 28 Nov 2018 19:56:17 -0200 Message-Id: <20181128215617.9284-3-ccarrara@redhat.com> In-Reply-To: <20181128215617.9284-1-ccarrara@redhat.com> References: <20181128215617.9284-1-ccarrara@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH 2/2] Apply PEP8 to tests modules 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-Type: text/plain; charset="utf-8" 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 28 Nov 2018 21:56:34 +0000 (UTC) The most of the changes in this commit are related with indentation and whitespaces. However it was also necessary to fix how the import from patchewtest members was implemented. Before this change each test module was appending to sys.path the tests directory so it was possible to import the base class PatchewTestCase. However we can accomplish the same without change the sys.path attribute. It's just a matter of turn tests directory into a Python package (adding __init__.py file into it) and use the import statement with relative imports as following: `from .patchewtest import PatchewTestcase` The changes were validated running the tests with the following command: `./manage.py test tests`. Signed-off-by: Caio Carrara --- tests/__init__.py | 0 tests/data/0016-nested-multipart.mbox.gz | Bin 2122 -> 2118 bytes tests/patchewtest.py | 34 ++++---- tests/test_ansi2html.py | 1 + tests/test_custom_tags.py | 8 +- tests/test_diff.py | 7 +- tests/test_git.py | 11 ++- tests/test_import.py | 11 +-- tests/test_mbox.py | 14 ++-- tests/test_message.py | 5 +- tests/test_model.py | 5 +- tests/test_project.py | 4 +- tests/test_rest.py | 94 ++++++++++++++--------- tests/test_tags.py | 8 +- tests/test_testing.py | 58 ++++++++------ 15 files changed, 153 insertions(+), 107 deletions(-) create mode 100644 tests/__init__.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/data/0016-nested-multipart.mbox.gz b/tests/data/0016-nes= ted-multipart.mbox.gz index 40ee55c1d96d9fa3bd205199cd00f8bb0af43740..d7ad6c053737dab992afd12df10= 6db01eb47030c 100644 GIT binary patch delta 599 zcmV-d0;v7U5XKM)ABzYGc?JJlu?YPIe-2{ZYM+$>=3DN^k~4-Ejh4P_moaqQ*`l2T+c z4_XXOxo1-wJw9rf2deY3ha3GM(-hQ~b}$Sur@? zEXYr`7sUTkxmYX&$^x(YSp>gs>Kqpg&Gli+JZ!gG&QV~Rw%zM@(-ZT$J!9hh;x5sS z(s3|lLn%ILg`qq<6I*R>HvDzYe+{KO>Mq<`Z@knq^-Lk7&}^$gE%Bn7xKo1Agu;~+e>?bduWiCc7Nj8+#HzB3@xsTnI$HqhM@ zRk`WsWMR0&r06b!6FdA23e?G3+cQ@1P zk$d7zuNPT3O6234XgEKeSPR8iz+5DL?wqCEn$DIUIqI#b?RnGN^Y|9N9NpBiyDL?5 zFJ0%b(}^xy;bGKR%xB$;c`X#rt+hW4JN@}|9B_suIc;^(b=3DNh+OhUOMM_E&~mpHB7AMait(mRep`Q<#CxX%R2Dt6{-HdZG`<7rnFF8*C<5=3DOQ&& lY=3DDDZTOq{tFH$e#Eg8006AWClUYv delta 603 zcmV-h0;K)M5Xuk;ABzYGRu!CCu?YPIfA0H%BywDB%%k~4+jFt?Cpo!9h%u`kZk;k=3DHk9I{Rv5~&GqKh7e`dp9=3DiE@bqwd13^~Os*Q_mDK3eC0})DkbMiECw{ z-qrhVq-*Q+_@_BpjStlp9*&Q?=3Dj)XEv&k7ZJ`TcD+iuNAlek5P#%OhM;X4B|otm*C zWdq$kQI(s1P8NncOp5LzIPt^VWlEQ9Xjsc0r=3D3QpH@740+)*>Xb*98}f3Kbl*X`q) zeRngx9=3DRvp^m>tnqeMQwiH7sjiM3FS1x!cc=3DgwKmt?6v(k)z&<+MYMPJ&$kU%h63O zySq{~_tJF^JDupV6&^;7#eCMinAbw_+*sDHH8`2oEGtdyBZcOq$m1te9=3D3*y}@R3 pbuLna#dg^8y@LbpKyEnkhEC>r=3DPfdQrEW?w?!VCGVV}1X000fwH{}2T diff --git a/tests/patchewtest.py b/tests/patchewtest.py index fc6de3e..ade039d 100644 --- a/tests/patchewtest.py +++ b/tests/patchewtest.py @@ -18,30 +18,32 @@ import json import atexit import gzip =20 +import django +import django.test as dj_test +from django.contrib.auth.models import User, Group +import rest_framework.test + +from api.models import Message, Result, Project + + BASE_DIR =3D os.path.join(os.path.dirname(__file__), "..") +PATCHEW_CLI =3D os.path.join(BASE_DIR, "patchew-cli") +RUN_DIR =3D tempfile.mkdtemp() =20 sys.path.append(BASE_DIR) =20 os.environ["PATCHEW_TEST"] =3D "1" +os.environ["PATCHEW_TEST_DATA_DIR"] =3D os.path.join(RUN_DIR, "patchew-dat= a") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "patchew.settings") -import django =20 django.setup() =20 -import django.test -from django.contrib.auth.models import User, Group -import rest_framework.test -from api.models import * =20 -PATCHEW_CLI =3D os.path.join(BASE_DIR, "patchew-cli") -RUN_DIR =3D tempfile.mkdtemp() -os.environ["PATCHEW_TEST_DATA_DIR"] =3D os.path.join(RUN_DIR, "patchew-dat= a") - -class PatchewTestCase(django.test.LiveServerTestCase): +class PatchewTestCase(dj_test.LiveServerTestCase): user =3D "admin" email =3D "admin@test" password =3D "adminpass" - client =3D django.test.Client() + client =3D dj_test.Client() api_client =3D rest_framework.test.APIClient() =20 REST_BASE =3D 'http://testserver/api/v1/' @@ -79,8 +81,11 @@ class PatchewTestCase(django.test.LiveServerTestCase): def check_cli(self, args, rc=3D0, stdout=3DNone, stderr=3DNone): assert(isinstance(args, list)) r, a, b =3D self.cli(args) - self.assertEqual(r, rc, - "Exit code {} !=3D expected {}, stdout:\n{}\nstderr:\n{}\n".fo= rmat(r, rc, a, b)) + self.assertEqual( + r, + rc, + "Exit code {} !=3D expected {}, stdout:\n{}\nstderr:\n{}\n".fo= rmat(r, rc, a, b) + ) if stdout is not None: self.assertEqual(stdout, a) if stderr is not None: @@ -162,12 +167,14 @@ class PatchewTestCase(django.test.LiveServerTestCase): cwd=3Drepo) return repo =20 + def parse_args(): parser =3D argparse.ArgumentParser() parser.add_argument("--debug", "-d", action=3D"store_true", help=3D"Enable debug output, and keep temp dir aft= er done") return parser.parse_known_args() =20 + def main(): import unittest args, argv =3D parse_args() @@ -183,4 +190,3 @@ def main(): finally: if not args.debug: shutil.rmtree(RUN_DIR) - diff --git a/tests/test_ansi2html.py b/tests/test_ansi2html.py index e146c3e..16c1d1e 100644 --- a/tests/test_ansi2html.py +++ b/tests/test_ansi2html.py @@ -8,6 +8,7 @@ import unittest =20 from patchew.logviewer import ansi2html, ansi2text, ANSI2TextConverter =20 + class ANSI2HTMLTest(unittest.TestCase): def assertAnsi(self, test, expected, **kwargs): self.assertEqual(''.join(ansi2html(test, **kwargs)), diff --git a/tests/test_custom_tags.py b/tests/test_custom_tags.py index c401d0e..49c67e2 100755 --- a/tests/test_custom_tags.py +++ b/tests/test_custom_tags.py @@ -12,6 +12,7 @@ from django.template import Context, Template from patchew.tags import tail_lines, grep_A, grep_B, grep_C, grep, lines_b= etween import unittest =20 + class CustomTagsTest(unittest.TestCase): def assertTemplate(self, template, expected, **kwargs): context =3D Context(kwargs) @@ -22,13 +23,13 @@ class CustomTagsTest(unittest.TestCase): self.assertTemplate('{{s|grep:"[0-9]"}}', '0\n9', s=3D'0\na\n9') self.assertTemplate('{{s|grep_A:"b"}}', 'b\nc\nd\ne\n---\nb', - s=3D'a\nb\nc\nd\ne\nf\nx\ny\nz\nb') + s=3D'a\nb\nc\nd\ne\nf\nx\ny\nz\nb') self.assertTemplate('{{s|grep_B:"b"}}', 'a\nb\n---\nx\ny\nz\nb', - s=3D'a\nb\nc\nd\ne\nf\nx\ny\nz\nb') + s=3D'a\nb\nc\nd\ne\nf\nx\ny\nz\nb') self.assertTemplate('{{s|grep_C:"b"}}', 'a\nb\nc\nd\ne\n---\nx\ny\nz\nb', - s=3D'a\nb\nc\nd\ne\nf\nx\ny\nz\nb') + s=3D'a\nb\nc\nd\ne\nf\nx\ny\nz\nb') self.assertTemplate('{{s|tail_lines:3}}', 'b\nc\nd', s=3D'a\nb\nc\= nd') =20 def test_template_tags(self): @@ -132,5 +133,6 @@ class CustomTagsTest(unittest.TestCase): self.assertEqual(lines_between('a\nb\ncb\nd', 'b', 'c', False), 'b= \ncb\nd') self.assertEqual(lines_between('a\nb\n\n\na\nb', '.', '^$'), 'a\nb= \n\na\nb') =20 + if __name__ =3D=3D '__main__': unittest.main() diff --git a/tests/test_diff.py b/tests/test_diff.py index 5aaf543..8e37e4f 100755 --- a/tests/test_diff.py +++ b/tests/test_diff.py @@ -8,10 +8,8 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 -import sys -import os -sys.path.append(os.path.dirname(__file__)) -from tests.patchewtest import PatchewTestCase, main +from .patchewtest import PatchewTestCase, main + =20 class DiffTest(PatchewTestCase): =20 @@ -63,5 +61,6 @@ class DiffTest(PatchewTestCase): self.assertEqual(resp3.data['other_versions'][1]['version'], 2) self.assertEqual(resp3.data['other_versions'][1]['resource_uri'], = resp2.data['resource_uri']) =20 + if __name__ =3D=3D '__main__': main() diff --git a/tests/test_git.py b/tests/test_git.py index 31e9823..09545df 100755 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -8,14 +8,13 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 -import sys -import os -sys.path.append(os.path.dirname(__file__)) -from tests.patchewtest import PatchewTestCase, main import shutil -import subprocess + from api.models import Message, Result =20 +from .patchewtest import PatchewTestCase, main + + class GitTest(PatchewTestCase): =20 def setUp(self): @@ -99,7 +98,6 @@ class GitTest(PatchewTestCase): def test_rest_git_base(self): self.cli_import("0013-foo-patch.mbox.gz") self.do_apply() - s =3D Message.objects.series_heads()[0] self.cli_import("0014-bar-patch.mbox.gz") MESSAGE_ID =3D '20160628014747.20971-2-famz@redhat.com' resp =3D self.api_client.get('%sseries/%s/' % (self.PROJECT_BASE, = MESSAGE_ID)) @@ -141,5 +139,6 @@ class GitTest(PatchewTestCase): self.assertEqual(log.status_code, 200) self.assertEqual(log.content.decode(), resp.data['log']) =20 + if __name__ =3D=3D '__main__': main() diff --git a/tests/test_import.py b/tests/test_import.py index 64d8c66..b5fe327 100755 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -8,15 +8,14 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 -import sys -import os -sys.path.append(os.path.dirname(__file__)) -from tests.patchewtest import PatchewTestCase, main import json + from api.models import Message, Project =20 -class ImportTest(PatchewTestCase): +from .patchewtest import PatchewTestCase, main + =20 +class ImportTest(PatchewTestCase): def setUp(self): self.create_superuser() self.cli_login() @@ -97,6 +96,7 @@ class ImportTest(PatchewTestCase): ['[libvirt] [PATCH v2] vcpupin: add clear featur= e', subj]) self.check_cli(["search", "project:Libvirt-python"], stdout=3Dsubj) =20 + class UnprivilegedImportTest(ImportTest): def setUp(self): self.create_superuser() @@ -133,5 +133,6 @@ class UnprivilegedImportTest(ImportTest): p.save() self.check_cli(["project", "update"]) =20 + if __name__ =3D=3D '__main__': main() diff --git a/tests/test_mbox.py b/tests/test_mbox.py index f003844..d04fa6b 100755 --- a/tests/test_mbox.py +++ b/tests/test_mbox.py @@ -8,11 +8,10 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 -import os -import sys import mbox -sys.path.append(os.path.dirname(__file__)) -from tests.patchewtest import PatchewTestCase, main + +from .patchewtest import PatchewTestCase, main + =20 class MboxTest(PatchewTestCase): =20 @@ -24,11 +23,11 @@ On 07/25/2017 10:57 AM, Jeff Cody wrote: > redhat/build_configure.sh | 3 +++ > redhat/qemu-kvm.spec.template | 7 +++++++ > 2 files changed, 10 insertions(+) ->=20 +> =20 ACK =20 ---=20 +-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org @@ -66,10 +65,11 @@ Virtualization: qemu.org | libvirt.org {'name': 'Alberto Garcia', 'address= ': 'berto@igalia.com'}, {'address': 'qemu-block@nongnu.org'= }, {'name': 'Max Reitz', 'address': 'm= reitz@redhat.com'}], - 'mbox':content + 'mbox': content } msg =3D mbox.MboxMessage(content).get_json() self.assertEqual(msg, expected) =20 + if __name__ =3D=3D '__main__': main() diff --git a/tests/test_message.py b/tests/test_message.py index 9448aee..419e384 100755 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -10,7 +10,9 @@ =20 import time import datetime -from tests.patchewtest import PatchewTestCase, main + +from .patchewtest import PatchewTestCase, main + =20 class ProjectTest(PatchewTestCase): =20 @@ -54,5 +56,6 @@ class ProjectTest(PatchewTestCase): asctime =3D message.get_asctime() self.assertEqual(asctime, "Sat Oct 22 9:06:04 2016") =20 + if __name__ =3D=3D '__main__': main() diff --git a/tests/test_model.py b/tests/test_model.py index 1464df2..704c658 100755 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -8,9 +8,11 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 -from tests.patchewtest import PatchewTestCase, main from api.models import Message =20 +from .patchewtest import PatchewTestCase, main + + class ImportTest(PatchewTestCase): =20 def setUp(self): @@ -136,5 +138,6 @@ mode change 100644 =3D> 100755 tests/qemu-iotests/205 self.maxDiff =3D 100000 self.assertMultiLineEqual(expected.strip(), msg.get_diff_stat()) =20 + if __name__ =3D=3D '__main__': main() diff --git a/tests/test_project.py b/tests/test_project.py index fbc1f0e..9274716 100755 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -8,7 +8,8 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 -from tests.patchewtest import PatchewTestCase, main +from .patchewtest import PatchewTestCase, main + =20 class ProjectTest(PatchewTestCase): =20 @@ -77,5 +78,6 @@ class ProjectTest(PatchewTestCase): self.assertFalse(p.maintained_by(u1)) self.assertFalse(p.maintained_by(u2)) =20 + if __name__ =3D=3D '__main__': main() diff --git a/tests/test_rest.py b/tests/test_rest.py index 8c86d9d..4ed9c07 100755 --- a/tests/test_rest.py +++ b/tests/test_rest.py @@ -8,24 +8,22 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 -import sys -import os +from collections import OrderedDict import json -import unittest =20 from django.contrib.auth.models import User =20 -sys.path.append(os.path.dirname(__file__)) -from tests.patchewtest import PatchewTestCase, main from api.models import Message from api.rest import AddressSerializer -from collections import OrderedDict + +from .patchewtest import PatchewTestCase, main =20 try: import coreapi except ImportError: coreapi =3D None =20 + class RestTest(PatchewTestCase): def setUp(self): self.create_superuser() @@ -97,15 +95,23 @@ class RestTest(PatchewTestCase): def test_update_project_head(self): resp =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', self.p.id, '20160628014747.20971-1-= famz@redhat.com') - self.api_client.login(username=3Dself.user, password=3Dself.passwo= rd) =20 - resp_before =3D self.api_client.get(self.PROJECT_BASE + "series/"+= "20160628014747.20971-1-famz@redhat.com/") + self.api_client.login(username=3Dself.user, password=3Dself.passwo= rd) + resp_before =3D self.api_client.get( + self.PROJECT_BASE + "series/" + "20160628014747.20971-1-famz@r= edhat.com/" + ) data =3D { - "message_ids": ["20160628014747.20971-1-famz@redhat.com"], - "old_head": "None", - "new_head": "000000" - } - resp =3D self.api_client.post(self.PROJECT_BASE + "update_project_= head/", data=3Djson.dumps(data), content_type=3D'application/json') - resp_after =3D self.api_client.get(self.PROJECT_BASE + "series/"+ = "20160628014747.20971-1-famz@redhat.com/") + "message_ids": ["20160628014747.20971-1-famz@redhat.com"], + "old_head": "None", + "new_head": "000000", + } + resp =3D self.api_client.post( + self.PROJECT_BASE + "update_project_head/", + data=3Djson.dumps(data), + content_type=3D'application/json' + ) + resp_after =3D self.api_client.get( + self.PROJECT_BASE + "series/" + "20160628014747.20971-1-famz@r= edhat.com/" + ) self.assertEquals(resp_before.data['is_merged'], False) self.assertEquals(resp.status_code, 200) self.assertEquals(resp.data['count'], 1) @@ -226,10 +232,10 @@ class RestTest(PatchewTestCase): self.assertEqual(resp.data['patches'][0]['stripped_subject'], 'cry= pto: add support for querying parameters for block encryption') =20 def test_series_list(self): - resp1 =3D self.apply_and_retrieve('0004-multiple-patch-reviewed.mb= ox.gz', - self.p.id, '1469192015-16487-1-git= -send-email-berrange@redhat.com') - resp2 =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', - self.p.id, '20160628014747.20971-1= -famz@redhat.com') + self.apply_and_retrieve('0004-multiple-patch-reviewed.mbox.gz', + self.p.id, '1469192015-16487-1-git-send-em= ail-berrange@redhat.com') + self.apply_and_retrieve('0001-simple-patch.mbox.gz', + self.p.id, '20160628014747.20971-1-famz@re= dhat.com') =20 resp =3D self.api_client.get(self.REST_BASE + 'series/') self.assertEqual(resp.data['count'], 2) @@ -242,7 +248,7 @@ class RestTest(PatchewTestCase): =20 def test_series_results_list(self): resp1 =3D self.apply_and_retrieve('0001-simple-patch.mbox.gz', - self.p.id, '20160628014747.20971-1-= famz@redhat.com') + self.p.id, '20160628014747.20971-1= -famz@redhat.com') resp =3D self.api_client.get(resp1.data['results']) self.assertEqual(resp.data['count'], len(resp.data['results'])) =20 @@ -277,20 +283,25 @@ class RestTest(PatchewTestCase): =20 def test_series_delete(self): test_message_id =3D '1469192015-16487-1-git-send-email-berrange@re= dhat.com' - series =3D self.apply_and_retrieve('0004-multiple-patch-reviewed.m= box.gz',self.p.id, - test_message_id) + series =3D self.apply_and_retrieve( + '0004-multiple-patch-reviewed.mbox.gz', self.p.id, test_messag= e_id + ) message =3D series.data['message'] - resp_before =3D self.api_client.get(self.REST_BASE + 'projects/' += str(self.p.id) - + '/series/' + test_message_id += '/') + resp_before =3D self.api_client.get( + self.REST_BASE + 'projects/' + str(self.p.id) + '/series/' + t= est_message_id + '/' + ) resp_reply_before =3D self.api_client.get(message + 'replies/') - resp_without_login =3D self.api_client.delete(self.REST_BASE + 'pr= ojects/' + str(self.p.id) - + '/series/' + test_message_id + '/') + resp_without_login =3D self.api_client.delete( + self.REST_BASE + 'projects/' + str(self.p.id) + '/series/' + t= est_message_id + '/' + ) self.api_client.login(username=3Dself.user, password=3Dself.passwo= rd) - resp =3D self.api_client.delete(self.REST_BASE + 'projects/' + str= (self.p.id) - + '/series/' + test_message_id + '/') + resp =3D self.api_client.delete( + self.REST_BASE + 'projects/' + str(self.p.id) + '/series/' + t= est_message_id + '/' + ) self.api_client.logout() - resp_after =3D self.api_client.get(self.REST_BASE + 'projects/' + = str(self.p.id) - + '/series/' + test_message_id + = '/') + resp_after =3D self.api_client.get( + self.REST_BASE + 'projects/' + str(self.p.id) + '/series/' + t= est_message_id + '/' + ) resp_reply_after =3D self.api_client.get(message + 'replies/') =20 self.assertEqual(resp_before.status_code, 200) @@ -391,7 +402,7 @@ class RestTest(PatchewTestCase): dp =3D self.get_data_path("0023-multiple-project-patch.mbox.gz") with open(dp, "r") as f: data =3D f.read() - test =3D self.create_user(username=3D"test", password=3D"userpass"= , groups=3D['importers']) + self.create_user(username=3D"test", password=3D"userpass", groups= =3D['importers']) self.api_client.login(username=3D"test", password=3D"userpass") resp =3D self.api_client.post(self.REST_BASE + "messages/", data, = content_type=3D'message/rfc822') self.assertEqual(resp.status_code, 201) @@ -419,19 +430,25 @@ class RestTest(PatchewTestCase): self.assertEqual(resp.data, Message.objects.all()[0].get_mbox()) =20 def test_address_serializer(self): - data1 =3D {"name":"Shubham", "address":"shubhamjain7495@gmail.com"} - serializer1 =3D AddressSerializer(data =3D data1) + data1 =3D {"name": "Shubham", "address": "shubhamjain7495@gmail.co= m"} + serializer1 =3D AddressSerializer(data=3Ddata1) valid1 =3D serializer1.is_valid() valid_data1 =3D serializer1.validated_data - data2 =3D {"name":123, "address":"shubhamjain7495@gmail.com"} - serializer2 =3D AddressSerializer(data =3D data2) + data2 =3D {"name": 123, "address": "shubhamjain7495@gmail.com"} + serializer2 =3D AddressSerializer(data=3Ddata2) valid2 =3D serializer2.is_valid() valid_data2 =3D serializer2.validated_data =20 - self.assertEqual(valid1,True) - self.assertEqual(valid_data1,OrderedDict([('name', 'Shubham'), ('a= ddress', 'shubhamjain7495@gmail.com')])) - self.assertEqual(valid2,True) - self.assertEqual(valid_data2,OrderedDict([('name', '123'), ('addre= ss', 'shubhamjain7495@gmail.com')])) + self.assertEqual(valid1, True) + self.assertEqual( + valid_data1, + OrderedDict([('name', 'Shubham'), ('address', 'shubhamjain7495= @gmail.com')]) + ) + self.assertEqual(valid2, True) + self.assertEqual( + valid_data2, + OrderedDict([('name', '123'), ('address', 'shubhamjain7495@gma= il.com')]) + ) =20 def test_message_replies(self): series =3D self.apply_and_retrieve('0004-multiple-patch-reviewed.m= box.gz', @@ -453,5 +470,6 @@ class RestTest(PatchewTestCase): resp =3D self.api_client.get(self.REST_BASE + 'schema/') self.assertEqual(resp.status_code, 200) =20 + if __name__ =3D=3D '__main__': main() diff --git a/tests/test_tags.py b/tests/test_tags.py index 075c497..1be2a7f 100755 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -8,15 +8,14 @@ # This work is licensed under the MIT License. Please see the LICENSE fil= e or # http://opensource.org/licenses/MIT. =20 -import sys -import os -sys.path.append(os.path.dirname(__file__)) -from tests.patchewtest import PatchewTestCase, main import email import email.parser import email.policy from mbox import decode_payload =20 +from .patchewtest import PatchewTestCase, main + + class ImportTest(PatchewTestCase): =20 def setUp(self): @@ -63,5 +62,6 @@ class ImportTest(PatchewTestCase): self.assertIn('SynICState *synic =3D get_synic(cs);', payload) self.assertIn('Reviewed-by: Philippe Mathieu-Daud=C3=A9 ', payload) =20 + if __name__ =3D=3D '__main__': main() diff --git a/tests/test_testing.py b/tests/test_testing.py index 6f2808c..a5c22e1 100755 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -9,13 +9,13 @@ # http://opensource.org/licenses/MIT. =20 import abc -import sys -import os import subprocess -sys.path.append(os.path.dirname(__file__)) -from tests.patchewtest import PatchewTestCase, main + from api.models import Message, Result =20 +from .patchewtest import PatchewTestCase, main + + def create_test(project, name, requirements=3D"", script=3D"#!/bin/bash\nt= rue"): prefix =3D "testing.tests." + name + "." project.set_property(prefix + "timeout", 3600) @@ -23,6 +23,7 @@ def create_test(project, name, requirements=3D"", script= =3D"#!/bin/bash\ntrue"): project.set_property(prefix + "script", script) project.set_property(prefix + "requirements", requirements) =20 + class TestingTestCase(PatchewTestCase, metaclass=3Dabc.ABCMeta): =20 def setUp(self): @@ -36,7 +37,7 @@ class TestingTestCase(PatchewTestCase, metaclass=3Dabc.AB= CMeta): def modify_test_result(self, obj, **kwargs): try: r =3D obj.results.get(name=3D'testing.a') - except: + except Exception: r =3D obj.create_result(name=3D'testing.a') if 'status' not in kwargs: kwargs['status'] =3D Result.PENDING @@ -52,28 +53,30 @@ class TestingTestCase(PatchewTestCase, metaclass=3Dabc.= ABCMeta): r.save() =20 def _do_testing_done(self, obj, **kwargs): - if not 'status' in kwargs: + if 'status' not in kwargs: kwargs['status'] =3D Result.SUCCESS self.modify_test_result(obj, **kwargs) obj.set_property("testing.done", True) =20 def do_testing_report(self, **report): self.api_login() - r =3D self.api_call("testing-get", - project=3D"QEMU", - tester=3D"dummy tester", - capabilities=3D[]) + 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 not 'passed' in report: + if 'passed' not in report: report['passed'] =3D True - if not 'log' in report: + if 'log' not in report: report['log'] =3D None - if not 'is_timeout' in report: + if 'is_timeout' not in report: report['is_timeout'] =3D False =20 self.api_call("testing-report", **report) @@ -150,6 +153,7 @@ class TestingTestCase(PatchewTestCase, metaclass=3Dabc.= ABCMeta): self.assertEquals(log.status_code, 200) self.assertEquals(log.content, b'sorry no good') =20 + class MessageTestingTest(TestingTestCase): =20 def setUp(self): @@ -170,15 +174,19 @@ class MessageTestingTest(TestingTestCase): return r =20 def get_test_result(self, test_name): - return self.api_client.get('%sseries/%s/results/testing.%s/' % ( - self.PROJECT_BASE, self.msg.message= _id, test_name)) + return self.api_client.get( + '%sseries/%s/results/testing.%s/' % ( + self.PROJECT_BASE, + self.msg.message_id, + test_name + )) =20 def test_testing_ready(self): self.assertEqual(self.msg.results.filter(name=3D'testing.a').first= ().status, Result.PENDING) =20 -class ProjectTestingTest(TestingTestCase): =20 +class ProjectTestingTest(TestingTestCase): def setUp(self): super(ProjectTestingTest, self).setUp() self.p.set_property("git.head", "5678") @@ -193,11 +201,12 @@ class ProjectTestingTest(TestingTestCase): return r =20 def get_test_result(self, test_name): - return self.api_client.get('%sresults/testing.%s/' % ( - self.PROJECT_BASE, test_name)) + return self.api_client.get( + '%sresults/testing.%s/' % (self.PROJECT_BASE, test_name) + ) =20 -class TesterTest(PatchewTestCase): =20 +class TesterTest(PatchewTestCase): def setUp(self): self.create_superuser() =20 @@ -227,8 +236,9 @@ class TesterTest(PatchewTestCase): self.update_head(self.p2) self.update_head(self.p3) self.update_head(self.p4) - base =3D subprocess.check_output(["git", "rev-parse", "HEAD~1"], - cwd=3Dself.repo).decode() + subprocess.check_output( + ["git", "rev-parse", "HEAD~1"], + cwd=3Dself.repo).decode() subprocess.check_output(["git", "tag", "test"], cwd=3Dself.repo) =20 def add_file_and_commit(self, f): @@ -314,8 +324,8 @@ class TesterTest(PatchewTestCase): self.assertIn("Nothing to test", out) self.cli_logout() =20 -class TestingResetTest(PatchewTestCase): =20 +class TestingResetTest(PatchewTestCase): def setUp(self): self.create_superuser() =20 @@ -364,8 +374,8 @@ class TestingResetTest(PatchewTestCase): "testing.c": Result.PENDING}) self.assertFalse(msg.get_property("testing.done")) =20 -class TestingDisableTest(PatchewTestCase): =20 +class TestingDisableTest(PatchewTestCase): def setUp(self): self.create_superuser() =20 @@ -383,8 +393,10 @@ class TestingDisableTest(PatchewTestCase): self.assertNotIn("Project: QEMU\n", out) self.cli_logout() =20 + # do not run tests on the abstract class del TestingTestCase =20 + if __name__ =3D=3D '__main__': main() --=20 2.19.2 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel