# default={{ project.linkname }}
[{{ project.linkname }}]
-url = {{ scheme }}://{{ site.domain }}{% url 'xmlrpc' %}
-{% if user.is_authenticated %}
-username = {{ user.username }}
-password = <add your patchwork password here>
-{% endif %}
+backend = {{ api_backend }}
+url = {{ api_scheme }}://{{ site.domain }}{{ api_path }}
+{% if user.is_authenticated %}username = {{ user.username }}
+password = <add your patchwork password here>{% endif %}
#
# SPDX-License-Identifier: GPL-2.0-or-later
-import unittest
-
-from django.conf import settings
from django.test import TestCase
from django.urls import reverse
self.assertRedirects(response, redirect_url, 301)
def test_redirects(self):
- for view in ['help', 'help-about']:
+ for view in ['help', 'help-about', 'help-pwclient']:
self._test_redirect(view)
- @unittest.skipUnless(
- settings.ENABLE_XMLRPC,
- 'requires xmlrpc interface (use the ENABLE_XMLRPC setting)',
- )
- def test_redirects_xmlrpc(self):
- self._test_redirect('help-pwclient')
-
def test_xmlrpc(self):
with self.settings(ENABLE_XMLRPC=False):
response = self.client.get(reverse('about'))
--- /dev/null
+# Patchwork - automated patch tracking system
+# Copyright (C) 2023 Stephen Finucane <stephen@that.guru>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+import configparser
+
+from django.test import TestCase
+from django.test import override_settings
+from django.urls import reverse
+
+from patchwork.tests.utils import create_project
+from patchwork.tests.utils import create_user
+
+
+class PwclientrcTest(TestCase):
+ def setUp(self):
+ super().setUp()
+ self.project = create_project()
+
+ def _get_pwclientrc(self):
+ response = self.client.get(
+ reverse('pwclientrc', kwargs={'project_id': self.project.linkname})
+ )
+
+ pwclientrc = configparser.ConfigParser()
+ pwclientrc.read_string(response.content.decode())
+
+ return pwclientrc
+
+ @override_settings(ENABLE_REST_API=False)
+ def test_xmlrpc(self):
+ pwclientrc = self._get_pwclientrc()
+
+ self.assertTrue(pwclientrc.has_section(self.project.linkname))
+ self.assertTrue(
+ pwclientrc.has_option(self.project.linkname, 'backend')
+ )
+ self.assertEqual(
+ 'xmlrpc', pwclientrc.get(self.project.linkname, 'backend')
+ )
+
+ @override_settings(ENABLE_REST_API=True)
+ def test_rest(self):
+ pwclientrc = self._get_pwclientrc()
+
+ self.assertTrue(pwclientrc.has_section(self.project.linkname))
+ self.assertTrue(
+ pwclientrc.has_option(self.project.linkname, 'backend')
+ )
+ self.assertEqual(
+ 'rest', pwclientrc.get(self.project.linkname, 'backend')
+ )
+ self.assertFalse(pwclientrc.has_option(self.project, 'username'))
+ self.assertFalse(pwclientrc.has_option(self.project, 'password'))
+
+ @override_settings(ENABLE_REST_API=True)
+ def test_rest_auth(self):
+ user = create_user()
+ user.set_password('12345')
+ user.save()
+ self.client.login(
+ username=user.username,
+ password='12345',
+ )
+
+ pwclientrc = self._get_pwclientrc()
+
+ self.assertTrue(pwclientrc.has_section(self.project.linkname))
+ self.assertTrue(
+ pwclientrc.has_option(self.project.linkname, 'backend')
+ )
+ self.assertEqual(
+ 'rest', pwclientrc.get(self.project.linkname, 'backend')
+ )
+ self.assertTrue(
+ pwclientrc.has_option(self.project.linkname, 'username')
+ )
+ self.assertEqual(
+ user.username,
+ pwclientrc.get(self.project.linkname, 'username'),
+ )
+ self.assertTrue(
+ pwclientrc.has_option(self.project.linkname, 'password')
+ )
+ self.assertEqual(
+ '<add your patchwork password here>',
+ pwclientrc.get(self.project.linkname, 'password'),
+ )
path('mail/optin/', mail_views.optin, name='mail-optin'),
# about
path('about/', about_views.about, name='about'),
+ # pwclientrc
+ path(
+ 'project/<project_id>/pwclientrc/',
+ pwclient_views.pwclientrc,
+ name='pwclientrc',
+ ),
# legacy redirects
path('help/', about_views.redirect, name='help'),
path('help/about/', about_views.redirect, name='help-about'),
+ path('help/pwclient/', about_views.redirect, name='help-pwclient'),
]
if 'debug_toolbar' in settings.INSTALLED_APPS:
if settings.ENABLE_XMLRPC:
urlpatterns += [
path('xmlrpc/', xmlrpc_views.xmlrpc, name='xmlrpc'),
- path(
- 'project/<project_id>/pwclientrc/',
- pwclient_views.pwclientrc,
- name='pwclientrc',
- ),
- # legacy redirect
- path('help/pwclient/', about_views.redirect, name='help-pwclient'),
]
if settings.ENABLE_REST_API:
from django.conf import settings
from django.shortcuts import get_object_or_404
from django.shortcuts import render
+from django.urls import reverse_lazy
from patchwork.models import Project
def pwclientrc(request, project_id):
project = get_object_or_404(Project, linkname=project_id)
+ if settings.FORCE_HTTPS_LINKS or request.is_secure():
+ api_scheme = 'https'
+ else:
+ api_scheme = 'http'
+
+ if settings.ENABLE_REST_API:
+ api_backend = 'rest'
+ api_path = reverse_lazy('api-index')
+ else:
+ api_backend = 'xmlrpc'
+ api_path = reverse_lazy('xmlrpc')
+
context = {
'project': project,
+ 'api_backend': api_backend,
+ 'api_path': api_path,
+ 'api_scheme': api_scheme,
}
- if settings.FORCE_HTTPS_LINKS or request.is_secure():
- context['scheme'] = 'https'
- else:
- context['scheme'] = 'http'
response = render(
- request, 'patchwork/pwclientrc', context, content_type='text/plain'
+ request,
+ 'patchwork/pwclientrc',
+ context,
+ content_type='text/plain',
)
response['Content-Disposition'] = 'attachment; filename=.pwclientrc'
--- /dev/null
+---
+features:
+ - |
+ The sample ``pwclientrc`` files found at ``/project/<project>/pwclientrc``
+ will now use the ``rest`` backend by default if the REST API is enabled.
+ In addition, it is now possible to download a sample ``pwclientrc`` file
+ even if the XML-RPC API backend is disabled.