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

Proposed by Colin Watson
Status: Merged
Merged at revision: 18617
Proposed branch: lp:~cjwatson/launchpad/snap-export-findByOwner
Merge into: lp:launchpad
Diff against target: 87 lines (+66/-0)
2 files modified
lib/lp/snappy/interfaces/snap.py (+5/-0)
lib/lp/snappy/tests/test_snap.py (+61/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/snap-export-findByOwner
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+343278@code.launchpad.net

Commit message

Export ISnapSet.findByOwner on the webservice.

Description of the change

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.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
660 def getByName(owner, name):660 def getByName(owner, name):
661 """Return the appropriate `ISnap` for the given objects."""661 """Return the appropriate `ISnap` for the given objects."""
662662
663 @operation_parameters(
664 owner=Reference(IPerson, title=_("Owner"), required=True))
665 @operation_returns_collection_of(ISnap)
666 @export_read_operation()
667 @operation_for_version("devel")
663 def findByOwner(owner):668 def findByOwner(owner):
664 """Return all snap packages with the given `owner`."""669 """Return all snap packages with the given `owner`."""
665670
666671
=== 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 @@
1547 "No such snap package with this owner: 'nonexistent'.",1547 "No such snap package with this owner: 'nonexistent'.",
1548 response.body)1548 response.body)
15491549
1550 def test_findByOwner(self):
1551 # lp.snaps.findByOwner returns all visible Snaps with the given owner.
1552 persons = [self.factory.makePerson(), self.factory.makePerson()]
1553 snaps = []
1554 for person in persons:
1555 for private in (False, True):
1556 snaps.append(self.factory.makeSnap(
1557 registrant=person, owner=person, private=private))
1558 with admin_logged_in():
1559 person_urls = [api_url(person) for person in persons]
1560 ws_snaps = [
1561 self.webservice.getAbsoluteUrl(api_url(snap))
1562 for snap in snaps]
1563 commercial_admin = (
1564 getUtility(ILaunchpadCelebrities).commercial_admin.teamowner)
1565 logout()
1566 # Anonymous requests can only see public snaps.
1567 anon_webservice = LaunchpadWebServiceCaller("test", "")
1568 response = anon_webservice.named_get(
1569 "/+snaps", "findByOwner", owner=person_urls[0],
1570 api_version="devel")
1571 self.assertEqual(200, response.status)
1572 self.assertContentEqual(
1573 [ws_snaps[0]],
1574 [entry["self_link"] for entry in response.jsonBody()["entries"]])
1575 # persons[0] can see their own private snap as well, but not those
1576 # for other people.
1577 webservice = webservice_for_person(
1578 persons[0], permission=OAuthPermission.READ_PRIVATE)
1579 response = webservice.named_get(
1580 "/+snaps", "findByOwner", owner=person_urls[0],
1581 api_version="devel")
1582 self.assertEqual(200, response.status)
1583 self.assertContentEqual(
1584 ws_snaps[:2],
1585 [entry["self_link"] for entry in response.jsonBody()["entries"]])
1586 response = webservice.named_get(
1587 "/+snaps", "findByOwner", owner=person_urls[1],
1588 api_version="devel")
1589 self.assertEqual(200, response.status)
1590 self.assertContentEqual(
1591 [ws_snaps[2]],
1592 [entry["self_link"] for entry in response.jsonBody()["entries"]])
1593 # Admins can see all snaps.
1594 commercial_admin_webservice = webservice_for_person(
1595 commercial_admin, permission=OAuthPermission.READ_PRIVATE)
1596 response = commercial_admin_webservice.named_get(
1597 "/+snaps", "findByOwner", owner=person_urls[0],
1598 api_version="devel")
1599 self.assertEqual(200, response.status)
1600 self.assertContentEqual(
1601 ws_snaps[:2],
1602 [entry["self_link"] for entry in response.jsonBody()["entries"]])
1603 response = commercial_admin_webservice.named_get(
1604 "/+snaps", "findByOwner", owner=person_urls[1],
1605 api_version="devel")
1606 self.assertEqual(200, response.status)
1607 self.assertContentEqual(
1608 ws_snaps[2:],
1609 [entry["self_link"] for entry in response.jsonBody()["entries"]])
1610
1550 def test_findByURL(self):1611 def test_findByURL(self):
1551 # lp.snaps.findByURL returns visible Snaps with the given URL.1612 # lp.snaps.findByURL returns visible Snaps with the given URL.
1552 persons = [self.factory.makePerson(), self.factory.makePerson()]1613 persons = [self.factory.makePerson(), self.factory.makePerson()]