launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24952
[Merge] ~cjwatson/launchpad:authserver-unittest into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:authserver-unittest into launchpad:master.
Commit message:
Port authserver doctests to unittest
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/386729
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:authserver-unittest into launchpad:master.
diff --git a/lib/lp/services/authserver/doc/xmlrpc-authserver.txt b/lib/lp/services/authserver/doc/xmlrpc-authserver.txt
deleted file mode 100644
index 7918087..0000000
--- a/lib/lp/services/authserver/doc/xmlrpc-authserver.txt
+++ /dev/null
@@ -1,39 +0,0 @@
-Private XML-RPC Authentication Server
-=====================================
-
-The AuthServer interface is available on the authserver attribute
-of our private XMLRPC instance.
-
- >>> from lp.testing import verifyObject
- >>> from lp.xmlrpc.interfaces import IPrivateApplication
- >>> from lp.services.authserver.interfaces import (
- ... IAuthServerApplication,
- ... )
-
- >>> private_root = getUtility(IPrivateApplication)
- >>> verifyObject(IAuthServerApplication, private_root.authserver)
- True
-
-The AuthServerAPIView provides the IAuthServer XML-RPC API:
-
- >>> from zope.publisher.xmlrpc import TestRequest
- >>> from lp.services.authserver.interfaces import IAuthServer
- >>> from lp.services.authserver.xmlrpc import AuthServerAPIView
-
- >>> authserver_api = AuthServerAPIView(
- ... private_root.authserver, TestRequest())
- >>> verifyObject(IAuthServer, authserver_api)
- True
-
-That interface allows the codehosting SSH server to find information
-about users.
-
- >>> from six.moves import xmlrpc_client
- >>> from lp.testing.xmlrpc import XMLRPCTestTransport
- >>> authserver= xmlrpc_client.ServerProxy(
- ... 'http://xmlrpc-private.launchpad.test:8087/authserver',
- ... transport=XMLRPCTestTransport())
-
- >>> user_dict = authserver.getUserAndSSHKeys('name16')
- >>> user_dict['id']
- 16
diff --git a/lib/lp/services/authserver/tests/test_authserver.py b/lib/lp/services/authserver/tests/test_authserver.py
index b299441..5949a80 100644
--- a/lib/lp/services/authserver/tests/test_authserver.py
+++ b/lib/lp/services/authserver/tests/test_authserver.py
@@ -1,4 +1,4 @@
-# Copyright 2009-2019 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2020 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for the internal codehosting API."""
@@ -6,6 +6,7 @@
__metaclass__ = type
from pymacaroons import Macaroon
+from six.moves import xmlrpc_client
from storm.sqlobject import SQLObjectNotFound
from testtools.matchers import (
Equals,
@@ -17,6 +18,10 @@ from zope.component import getUtility
from zope.interface import implementer
from zope.publisher.xmlrpc import TestRequest
+from lp.services.authserver.interfaces import (
+ IAuthServer,
+ IAuthServerApplication,
+ )
from lp.services.authserver.xmlrpc import AuthServerAPIView
from lp.services.config import config
from lp.services.librarian.interfaces import (
@@ -32,16 +37,37 @@ from lp.services.macaroons.model import MacaroonIssuerBase
from lp.testing import (
person_logged_in,
TestCaseWithFactory,
+ verifyObject,
)
from lp.testing.fixture import ZopeUtilityFixture
from lp.testing.layers import (
DatabaseFunctionalLayer,
ZopelessDatabaseLayer,
)
+from lp.testing.xmlrpc import XMLRPCTestTransport
from lp.xmlrpc import faults
from lp.xmlrpc.interfaces import IPrivateApplication
+class TestAuthServerInterfaces(TestCaseWithFactory):
+
+ layer = DatabaseFunctionalLayer
+
+ def test_application_interface(self):
+ # The AuthServer interface is available on the authserver attribute
+ # of our private XML-RPC instance.
+ private_root = getUtility(IPrivateApplication)
+ self.assertTrue(
+ verifyObject(IAuthServerApplication, private_root.authserver))
+
+ def test_api_interface(self):
+ # The AuthServerAPIView provides the IAuthServer XML-RPC API.
+ private_root = getUtility(IPrivateApplication)
+ authserver_api = AuthServerAPIView(
+ private_root.authserver, TestRequest())
+ self.assertTrue(verifyObject(IAuthServer, authserver_api))
+
+
class GetUserAndSSHKeysTests(TestCaseWithFactory):
"""Tests for the implementation of `IAuthServer.getUserAndSSHKeys`.
"""
@@ -82,6 +108,18 @@ class GetUserAndSSHKeysTests(TestCaseWithFactory):
keys=[(key.keytype.title, key.keytext)]),
self.authserver.getUserAndSSHKeys(new_person.name))
+ def test_via_xmlrpc(self):
+ new_person = self.factory.makePerson()
+ with person_logged_in(new_person):
+ key = self.factory.makeSSHKey(person=new_person)
+ authserver = xmlrpc_client.ServerProxy(
+ 'http://xmlrpc-private.launchpad.test:8087/authserver',
+ transport=XMLRPCTestTransport())
+ self.assertEqual(
+ {'id': new_person.id, 'name': new_person.name,
+ 'keys': [[key.keytype.title, key.keytext]]},
+ authserver.getUserAndSSHKeys(new_person.name))
+
@implementer(IMacaroonIssuer)
class DummyMacaroonIssuer(MacaroonIssuerBase):
diff --git a/lib/lp/services/authserver/tests/test_doc.py b/lib/lp/services/authserver/tests/test_doc.py
deleted file mode 100644
index 5e032e6..0000000
--- a/lib/lp/services/authserver/tests/test_doc.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright 2009 Canonical Ltd. This software is licensed under the
-# GNU Affero General Public License version 3 (see the file LICENSE).
-
-"""
-Run the doctests and pagetests.
-"""
-
-import os
-
-from lp.services.testing import build_test_suite
-from lp.testing.layers import LaunchpadFunctionalLayer
-
-
-here = os.path.dirname(os.path.realpath(__file__))
-
-
-def test_suite():
- return build_test_suite(here, layer=LaunchpadFunctionalLayer)