← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/snap-export-findByOwner into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/snap-export-findByOwner into lp:launchpad.

Commit message:
Export ISnapSet.findByOwner on the webservice.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/snap-export-findByOwner/+merge/343278

It's kind of rubbish to have to use things like `lp.snaps.findByURLPrefix(url_prefix='https://github.com/', owner='/~build.snapcraft.io')` to iterate over BSI's snaps.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/snap-export-findByOwner into lp:launchpad.
=== modified file 'lib/lp/snappy/interfaces/snap.py'
--- lib/lp/snappy/interfaces/snap.py	2018-04-04 14:14:30 +0000
+++ lib/lp/snappy/interfaces/snap.py	2018-04-15 16:50:59 +0000
@@ -660,6 +660,11 @@
     def getByName(owner, name):
         """Return the appropriate `ISnap` for the given objects."""
 
+    @operation_parameters(
+        owner=Reference(IPerson, title=_("Owner"), required=True))
+    @operation_returns_collection_of(ISnap)
+    @export_read_operation()
+    @operation_for_version("devel")
     def findByOwner(owner):
         """Return all snap packages with the given `owner`."""
 

=== modified file 'lib/lp/snappy/tests/test_snap.py'
--- lib/lp/snappy/tests/test_snap.py	2018-04-04 14:14:30 +0000
+++ lib/lp/snappy/tests/test_snap.py	2018-04-15 16:50:59 +0000
@@ -1547,6 +1547,67 @@
             "No such snap package with this owner: 'nonexistent'.",
             response.body)
 
+    def test_findByOwner(self):
+        # lp.snaps.findByOwner returns all visible Snaps with the given owner.
+        persons = [self.factory.makePerson(), self.factory.makePerson()]
+        snaps = []
+        for person in persons:
+            for private in (False, True):
+                snaps.append(self.factory.makeSnap(
+                    registrant=person, owner=person, private=private))
+        with admin_logged_in():
+            person_urls = [api_url(person) for person in persons]
+            ws_snaps = [
+                self.webservice.getAbsoluteUrl(api_url(snap))
+                for snap in snaps]
+        commercial_admin = (
+            getUtility(ILaunchpadCelebrities).commercial_admin.teamowner)
+        logout()
+        # Anonymous requests can only see public snaps.
+        anon_webservice = LaunchpadWebServiceCaller("test", "")
+        response = anon_webservice.named_get(
+            "/+snaps", "findByOwner", owner=person_urls[0],
+            api_version="devel")
+        self.assertEqual(200, response.status)
+        self.assertContentEqual(
+            [ws_snaps[0]],
+            [entry["self_link"] for entry in response.jsonBody()["entries"]])
+        # persons[0] can see their own private snap as well, but not those
+        # for other people.
+        webservice = webservice_for_person(
+            persons[0], permission=OAuthPermission.READ_PRIVATE)
+        response = webservice.named_get(
+            "/+snaps", "findByOwner", owner=person_urls[0],
+            api_version="devel")
+        self.assertEqual(200, response.status)
+        self.assertContentEqual(
+            ws_snaps[:2],
+            [entry["self_link"] for entry in response.jsonBody()["entries"]])
+        response = webservice.named_get(
+            "/+snaps", "findByOwner", owner=person_urls[1],
+            api_version="devel")
+        self.assertEqual(200, response.status)
+        self.assertContentEqual(
+            [ws_snaps[2]],
+            [entry["self_link"] for entry in response.jsonBody()["entries"]])
+        # Admins can see all snaps.
+        commercial_admin_webservice = webservice_for_person(
+            commercial_admin, permission=OAuthPermission.READ_PRIVATE)
+        response = commercial_admin_webservice.named_get(
+            "/+snaps", "findByOwner", owner=person_urls[0],
+            api_version="devel")
+        self.assertEqual(200, response.status)
+        self.assertContentEqual(
+            ws_snaps[:2],
+            [entry["self_link"] for entry in response.jsonBody()["entries"]])
+        response = commercial_admin_webservice.named_get(
+            "/+snaps", "findByOwner", owner=person_urls[1],
+            api_version="devel")
+        self.assertEqual(200, response.status)
+        self.assertContentEqual(
+            ws_snaps[2:],
+            [entry["self_link"] for entry in response.jsonBody()["entries"]])
+
     def test_findByURL(self):
         # lp.snaps.findByURL returns visible Snaps with the given URL.
         persons = [self.factory.makePerson(), self.factory.makePerson()]


Follow ups