Merge ~cjwatson/launchpadlib:fakelaunchpad-plain-methods into launchpadlib:main

Proposed by Colin Watson
Status: Merged
Merged at revision: ce8cee3126264ed7cdc7e43a2c32850eddadbb77
Proposed branch: ~cjwatson/launchpadlib:fakelaunchpad-plain-methods
Merge into: launchpadlib:main
Diff against target: 73 lines (+23/-1)
4 files modified
NEWS.rst (+2/-0)
src/launchpadlib/testing/launchpad.py (+4/-1)
src/launchpadlib/testing/testing-wadl.xml (+6/-0)
src/launchpadlib/testing/tests/test_launchpad.py (+11/-0)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+435267@code.launchpad.net

Commit message

Fix handling of methods with no response representation

Description of the change

Some methods have no response representation defined in their WADL; these return plain data rather than an entry or a collection. Don't attempt to wrap the result of such fake methods in a `FakeResource`.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/NEWS.rst b/NEWS.rst
index 29fc779..09feeb8 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -9,6 +9,8 @@ NEWS for launchpadlib
9 ``launchpadlib.testing.launchpad.FakeLaunchpad``.9 ``launchpadlib.testing.launchpad.FakeLaunchpad``.
10- Allow setting ``FakeLaunchpad`` sample data with attributes that are links10- Allow setting ``FakeLaunchpad`` sample data with attributes that are links
11 to other entries or collections.11 to other entries or collections.
12- Fix handling of methods with no response representation in
13 ``FakeLaunchpad``.
1214
131.10.18 (2022-10-28)151.10.18 (2022-10-28)
14====================16====================
diff --git a/src/launchpadlib/testing/launchpad.py b/src/launchpadlib/testing/launchpad.py
index 3b68798..aa2ee6d 100644
--- a/src/launchpadlib/testing/launchpad.py
+++ b/src/launchpadlib/testing/launchpad.py
@@ -493,12 +493,15 @@ class FakeResource(object):
493 @param result: The result of calling the method.493 @param result: The result of calling the method.
494 @raises IntegrityError: Raised if C{result} is an invalid return value494 @raises IntegrityError: Raised if C{result} is an invalid return value
495 for the method.495 for the method.
496 @return: A L{FakeResource} for C{result}.496 @return: A L{FakeResource} for C{result}, or just C{result} if no
497 response representation is defined for the method.
497 """498 """
498 resource_name = resource_type.tag.get("id")499 resource_name = resource_type.tag.get("id")
499 if resource_name == name:500 if resource_name == name:
500 name = "get"501 name = "get"
501 xml_id = self._find_representation_id(resource_type, name)502 xml_id = self._find_representation_id(resource_type, name)
503 if xml_id is None:
504 return result
502 xml_id = strip_suffix(xml_id, "-full")505 xml_id = strip_suffix(xml_id, "-full")
503 if xml_id not in self._application.resource_types:506 if xml_id not in self._application.resource_types:
504 xml_id += "-resource"507 xml_id += "-resource"
diff --git a/src/launchpadlib/testing/testing-wadl.xml b/src/launchpadlib/testing/testing-wadl.xml
index 650711d..720ac51 100644
--- a/src/launchpadlib/testing/testing-wadl.xml
+++ b/src/launchpadlib/testing/testing-wadl.xml
@@ -161,6 +161,12 @@
161 </wadl:method>161 </wadl:method>
162162
163 <wadl:method name="DELETE" id="branch-delete"/>163 <wadl:method name="DELETE" id="branch-delete"/>
164
165 <wadl:method id="branch-canBeDeleted" name="GET">
166 <wadl:request>
167 <wadl:param style="query" name="ws.op" required="true" fixed="canBeDeleted"/>
168 </wadl:request>
169 </wadl:method>
164 </wadl:resource_type>170 </wadl:resource_type>
165171
166 <wadl:representation mediaType="application/json"172 <wadl:representation mediaType="application/json"
diff --git a/src/launchpadlib/testing/tests/test_launchpad.py b/src/launchpadlib/testing/tests/test_launchpad.py
index cad2f10..c988d2b 100644
--- a/src/launchpadlib/testing/tests/test_launchpad.py
+++ b/src/launchpadlib/testing/tests/test_launchpad.py
@@ -261,6 +261,17 @@ class FakeLaunchpadTest(ResourcedTestCase):
261 self.launchpad.branches = dict(getByUniqueName=lambda name: None)261 self.launchpad.branches = dict(getByUniqueName=lambda name: None)
262 self.assertIsNone(self.launchpad.branches.getByUniqueName("foo"))262 self.assertIsNone(self.launchpad.branches.getByUniqueName("foo"))
263263
264 def test_callable_object_no_response_representation(self):
265 """
266 If the WADL definition of a method does not include a response
267 representation, then fake versions of that method just pass through
268 the return value.
269 """
270 branch = dict(canBeDeleted=lambda: True)
271 self.launchpad.branches = dict(getByUniqueName=lambda name: branch)
272 branch = self.launchpad.branches.getByUniqueName("foo")
273 self.assertTrue(branch.canBeDeleted())
274
264 def test_entry_property(self):275 def test_entry_property(self):
265 """276 """
266 Attributes that represent links to other objects are set using a277 Attributes that represent links to other objects are set using a

Subscribers

People subscribed via source and target branches