Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions patchwork/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import os
import warnings

TEST_MAIL_DIR = os.path.join(os.path.dirname(__file__), 'mail')
TEST_PATCH_DIR = os.path.join(os.path.dirname(__file__), 'patches')
TEST_FUZZ_DIR = os.path.join(os.path.dirname(__file__), 'fuzztests')
TEST_MAIL_DIR = os.path.join(os.path.dirname(__file__), 'data', 'mail')
TEST_PATCH_DIR = os.path.join(os.path.dirname(__file__), 'data', 'patches')
TEST_FUZZ_DIR = os.path.join(os.path.dirname(__file__), 'data', 'fuzz')
TEST_SERIES_DIR = os.path.join(os.path.dirname(__file__), 'data', 'series')

# configure warnings

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rest_framework import status

from patchwork.models import Bundle
from patchwork.tests.api import utils
from patchwork.tests.unit.api import utils
from patchwork.tests.utils import create_bundle
from patchwork.tests.utils import create_maintainer
from patchwork.tests.utils import create_patch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rest_framework import status

from patchwork.models import Check
from patchwork.tests.api import utils
from patchwork.tests.unit.api import utils
from patchwork.tests.utils import create_check
from patchwork.tests.utils import create_patch
from patchwork.tests.utils import create_maintainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from patchwork.models import PatchComment
from patchwork.models import CoverComment
from patchwork.tests.api import utils
from patchwork.tests.unit.api import utils
from patchwork.tests.utils import create_cover
from patchwork.tests.utils import create_cover_comment
from patchwork.tests.utils import create_patch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.urls import reverse
from rest_framework import status

from patchwork.tests.api import utils
from patchwork.tests.unit.api import utils
from patchwork.tests.utils import create_cover
from patchwork.tests.utils import create_covers
from patchwork.tests.utils import create_maintainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rest_framework import status

from patchwork.models import Event
from patchwork.tests.api import utils
from patchwork.tests.unit.api import utils
from patchwork.tests.utils import create_check
from patchwork.tests.utils import create_cover
from patchwork.tests.utils import create_cover_comment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from rest_framework import status

from patchwork.models import Patch
from patchwork.tests.api import utils
from patchwork.tests.unit.api import utils
from patchwork.tests.utils import create_maintainer
from patchwork.tests.utils import create_patch
from patchwork.tests.utils import create_patches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.urls import reverse
from rest_framework import status

from patchwork.tests.api import utils
from patchwork.tests.unit.api import utils
from patchwork.tests.utils import create_maintainer
from patchwork.tests.utils import create_person
from patchwork.tests.utils import create_user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from rest_framework import status

from patchwork.models import Project
from patchwork.tests.api import utils
from patchwork.tests.unit.api import utils
from patchwork.tests.utils import create_maintainer
from patchwork.tests.utils import create_project
from patchwork.tests.utils import create_user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from patchwork.models import Patch
from patchwork.models import PatchRelation
from patchwork.tests.api import utils
from patchwork.tests.unit.api import utils
from patchwork.tests.utils import create_maintainer
from patchwork.tests.utils import create_patch
from patchwork.tests.utils import create_patches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.urls import reverse
from rest_framework import status

from patchwork.tests.api import utils
from patchwork.tests.unit.api import utils
from patchwork.tests.utils import create_cover
from patchwork.tests.utils import create_maintainer
from patchwork.tests.utils import create_patch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.urls import reverse
from rest_framework import status

from patchwork.tests.api import utils
from patchwork.tests.unit.api import utils
from patchwork.tests.utils import create_maintainer
from patchwork.tests.utils import create_user

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from rest_framework.test import APIClient as BaseAPIClient
from rest_framework.test import APIRequestFactory

from patchwork.tests.api import validator
from patchwork.tests.unit.api import validator
from patchwork.tests.utils import create_user


Expand All @@ -22,6 +22,7 @@
os.pardir,
os.pardir,
os.pardir,
os.pardir,
'docs',
'api',
'samples',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
os.pardir,
os.pardir,
os.pardir,
os.pardir,
'docs',
'api',
'schemas',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@

from patchwork import models
from patchwork import parser
from patchwork.tests import TEST_SERIES_DIR
from patchwork.tests import utils
from patchwork.views.utils import patch_to_mbox


TEST_SERIES_DIR = os.path.join(os.path.dirname(__file__), 'series')


class _BaseTestCase(TestCase):
def setUp(self):
utils.create_state()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,56 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later

import base64
from xmlrpc import client as xmlrpc_client

from django.test import LiveServerTestCase
from django.test import TestCase
from django.test import override_settings
from django.urls import reverse

from patchwork.tests import utils


class ServerProxy(xmlrpc_client.ServerProxy):
def close(self):
self.__close()
class _TestClientTransport(xmlrpc_client.Transport):
"""XML-RPC transport backed by Django's test client.

Allows XML-RPC tests to run without a live server by dispatching
requests directly through the WSGI stack.
"""

def __init__(self, client, username=None, password=None):
super().__init__()
self._client = client
self._extra_headers = {}
if username is not None:
credentials = base64.b64encode(
f'{username}:{password}'.encode()
).decode()
self._extra_headers['HTTP_AUTHORIZATION'] = f'Basic {credentials}'

def request(self, host, handler, request_body, verbose=False):
# host is ignored: requests are dispatched in-process via the test client
response = self._client.post(
handler,
data=request_body,
content_type='text/xml',
**self._extra_headers,
)
p, u = self.getparser()
p.feed(response.content)
p.close()
return u.close()


@override_settings(ENABLE_XMLRPC=True)
class XMLRPCTest(LiveServerTestCase):
class XMLRPCTest(TestCase):
def setUp(self):
self.url = self.live_server_url + reverse('xmlrpc')
self.rpc = ServerProxy(self.url)

def tearDown(self):
self.rpc.close()
self.url = reverse('xmlrpc')
server_name = self.client._base_environ()['SERVER_NAME']
self.rpc = xmlrpc_client.ServerProxy(
f'http://{server_name}{self.url}',
transport=_TestClientTransport(self.client),
)


class XMLRPCGenericTest(XMLRPCTest):
Expand All @@ -46,21 +74,20 @@ def test_absent_auth(self):


@override_settings(ENABLE_XMLRPC=True)
class XMLRPCAuthenticatedTest(LiveServerTestCase):
class XMLRPCAuthenticatedTest(TestCase):
def setUp(self):
self.url = self.live_server_url + reverse('xmlrpc')
# url is of the form http://localhost:PORT/PATH
# strip the http and replace it with the username/passwd of a user.
self.url = reverse('xmlrpc')
self.project = utils.create_project()
self.user = utils.create_maintainer(self.project)
self.url = ('http://%s:%s@' + self.url[7:]) % (
self.user.username,
self.user.username,
server_name = self.client._base_environ()['SERVER_NAME']
self.rpc = xmlrpc_client.ServerProxy(
f'http://{server_name}{self.url}',
transport=_TestClientTransport(
self.client,
username=self.user.username,
password=self.user.username,
),
)
self.rpc = ServerProxy(self.url)

def tearDown(self):
self.rpc.close()

def test_patch_set(self):
patch = utils.create_patch(project=self.project)
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ passenv =
DATABASE_NAME
DJANGO_TEST_PROCESSES
commands =
python {toxinidir}/manage.py test --noinput --parallel -v 2 --timing -- {posargs:patchwork}
python {toxinidir}/manage.py test --noinput --parallel -v 2 --timing -- {posargs:patchwork.tests.unit}

[testenv:pep8]
deps =
Expand Down Expand Up @@ -64,8 +64,8 @@ setenv =
DJANGO_SETTINGS_MODULE = patchwork.settings.dev
commands =
coverage erase
coverage run --omit=*tox*,patchwork/tests/*.py,manage.py,patchwork/migrations/*.py \
--branch {toxinidir}/manage.py test --noinput patchwork
coverage run --omit=*tox*,patchwork/tests/unit/*.py,manage.py,patchwork/migrations/*.py \
--branch {toxinidir}/manage.py test --noinput patchwork.tests.unit
coverage report -m

[gh-actions]
Expand Down
Loading